From 5626342cbfb8be24fe7ec5f53cdf9f919c5e1fb1 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 15 Aug 2023 12:45:41 +0200 Subject: [PATCH] Increased MDSwitch hit zone --- .../uix/selectioncontrol/selectioncontrol.kv | 6 ++++-- .../uix/selectioncontrol/selectioncontrol.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/sbapp/kivymd/uix/selectioncontrol/selectioncontrol.kv b/sbapp/kivymd/uix/selectioncontrol/selectioncontrol.kv index 3d3b015..5d0a44c 100644 --- a/sbapp/kivymd/uix/selectioncontrol/selectioncontrol.kv +++ b/sbapp/kivymd/uix/selectioncontrol/selectioncontrol.kv @@ -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]) diff --git a/sbapp/kivymd/uix/selectioncontrol/selectioncontrol.py b/sbapp/kivymd/uix/selectioncontrol/selectioncontrol.py index 6bcefe6..be03df0 100755 --- a/sbapp/kivymd/uix/selectioncontrol/selectioncontrol.py +++ b/sbapp/kivymd/uix/selectioncontrol/selectioncontrol.py @@ -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