Fix hover state being "stuck" when the mouse quickly moves out of the same cell.
Start implementing automatic Widget group updates when adding to a Frame.
Clean up NinePatch code in preparation for integrating into Widgets.
@@ -37,11 +37,12 @@ from pyglet.graphics import OrderedGroup
class Frame:
- def __init__(self, window, cell_size=128):
+ def __init__(self, window, cell_size=128, order=0):
window.push_handlers(self)
self._cell_size = cell_size
self._cells = {}
self._active_widgets = set()
+ self._order = order
def _hash(self, x, y):
"""Normalize position to cell"""
@@ -54,6 +55,7 @@ class Frame:
for j in range(min_vec[1], max_vec[1] + 1):
self._cells.setdefault((i, j), set()).add(widget)
# TODO: return ID and track Widgets for later deletion.
+ widget.update_groups(self._order)
def on_mouse_press(self, x, y, buttons, modifiers):
"""Pass the event to any widgets within range of the mouse"""
@@ -79,5 +81,8 @@ class Frame:
def on_mouse_motion(self, x, y, dx, dy):
"""Pass the event to any widgets within range of the mouse"""
+ for widget in self._active_widgets:
+ widget.dispatch_event('on_mouse_motion', x, y, dx, dy)
for widget in self._cells.get(self._hash(x, y), set()):
widget.dispatch_event('on_mouse_motion', x, y, dx, dy)
+ self._active_widgets.add(widget)
