Increased MDSwitch hit zone

This commit is contained in:
Mark Qvist 2023-08-15 12:45:41 +02:00
parent 14cd17c54e
commit 5626342cbf
2 changed files with 21 additions and 2 deletions

View File

@ -137,9 +137,11 @@
) \
) \
)
on_touch_down:
if self.collide_point(*args[1].pos) and not root.disabled: \
root.on_thumb_down()
on_touch_up:
if self.collide_point(*args[1].pos) and not root.disabled: \
setattr(root, "active", not root.active)
if self.collide_point(*args[1].pos) and not root.disabled: setattr(root, "active", not root.active)
elif root.collide_point(*args[1].pos) and not root.disabled: setattr(root, "active", not root.active)
else: root.tnn(args[1])

View File

@ -829,6 +829,23 @@ class MDSwitch(ThemableBehavior, FloatLayout):
Clock.schedule_once(lambda x: self._update_thumb_pos(animation=False))
Clock.schedule_once(lambda x: self.on_active(self, self.active))
# Hack to increase switch hit zone
def tnn(self, pa):
try:
ex = pa.pos[0]
ey = pa.pos[1]
xs = self.center[0]-self.width/2 - (self.width)
xe = self.center[0]+self.width/2 + (self.width)
ys = self.center[1]-self.height/2
ye = self.center[1]+self.height/2
# print(str(xs)+" < "+str(ex)+" < "+str(xe)+" "+str(ys)+" < "+str(ey)+" < "+str(ye))
if xs < ex < xe and ys < ey < ye:
self.active = not self.active
except Exception as e:
pass
def set_icon(self, instance_switch, icon_value: str) -> None:
"""
Called when the values of