raylib ui: only process mouse events when enabled (#35948)

pull/35843/merge
Shane Smiskol 1 day ago committed by GitHub
parent a79a5e5a16
commit fd32fcd20d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 61
      system/ui/widgets/__init__.py

@ -82,36 +82,37 @@ class Widget(abc.ABC):
ret = self._render(self._rect) ret = self._render(self._rect)
# Keep track of whether mouse down started within the widget's rectangle # Keep track of whether mouse down started within the widget's rectangle
for mouse_event in gui_app.mouse_events: if self.enabled:
if not self._multi_touch and mouse_event.slot != 0: for mouse_event in gui_app.mouse_events:
continue if not self._multi_touch and mouse_event.slot != 0:
continue
# Ignores touches/presses that start outside our rect
# Allows touch to leave the rect and come back in focus if mouse did not release # Ignores touches/presses that start outside our rect
if mouse_event.left_pressed and self._touch_valid(): # Allows touch to leave the rect and come back in focus if mouse did not release
if rl.check_collision_point_rec(mouse_event.pos, self._rect): if mouse_event.left_pressed and self._touch_valid():
self._is_pressed[mouse_event.slot] = True if rl.check_collision_point_rec(mouse_event.pos, self._rect):
self._tracking_is_pressed[mouse_event.slot] = True self._is_pressed[mouse_event.slot] = True
self._tracking_is_pressed[mouse_event.slot] = True
# Callback such as scroll panel signifies user is scrolling
elif not self._touch_valid(): # Callback such as scroll panel signifies user is scrolling
self._is_pressed[mouse_event.slot] = False elif not self._touch_valid():
self._tracking_is_pressed[mouse_event.slot] = False self._is_pressed[mouse_event.slot] = False
self._tracking_is_pressed[mouse_event.slot] = False
elif mouse_event.left_released:
if self._is_pressed[mouse_event.slot] and rl.check_collision_point_rec(mouse_event.pos, self._rect): elif mouse_event.left_released:
self._handle_mouse_release(mouse_event.pos) if self._is_pressed[mouse_event.slot] and rl.check_collision_point_rec(mouse_event.pos, self._rect):
self._is_pressed[mouse_event.slot] = False self._handle_mouse_release(mouse_event.pos)
self._tracking_is_pressed[mouse_event.slot] = False self._is_pressed[mouse_event.slot] = False
self._tracking_is_pressed[mouse_event.slot] = False
# Mouse/touch is still within our rect
elif rl.check_collision_point_rec(mouse_event.pos, self._rect): # Mouse/touch is still within our rect
if self._tracking_is_pressed[mouse_event.slot]: elif rl.check_collision_point_rec(mouse_event.pos, self._rect):
self._is_pressed[mouse_event.slot] = True if self._tracking_is_pressed[mouse_event.slot]:
self._is_pressed[mouse_event.slot] = True
# Mouse/touch left our rect but may come back into focus later
elif not rl.check_collision_point_rec(mouse_event.pos, self._rect): # Mouse/touch left our rect but may come back into focus later
self._is_pressed[mouse_event.slot] = False elif not rl.check_collision_point_rec(mouse_event.pos, self._rect):
self._is_pressed[mouse_event.slot] = False
return ret return ret

Loading…
Cancel
Save