Simplify on_enter/on_exit callbacks to position-only signature
BREAKING CHANGE: Hover callbacks now take only (pos) instead of (pos, button, action) - Add PyHoverCallable class for on_enter/on_exit/on_move callbacks (position-only) - Add PyCellHoverCallable class for on_cell_enter/on_cell_exit callbacks - Change UIDrawable member types from PyClickCallable to PyHoverCallable - Update PyScene::do_mouse_hover() to call hover callbacks with only position - Add tryCallPythonMethod overload for position-only subclass method calls - Update UIGrid::fireCellEnter/fireCellExit to use position-only signature - Update all tests for new callback signatures New callback signatures: | Callback | Old | New | |----------------|--------------------------|------------| | on_enter | (pos, button, action) | (pos) | | on_exit | (pos, button, action) | (pos) | | on_move | (pos, button, action) | (pos) | | on_cell_enter | (cell_pos, button, action)| (cell_pos)| | on_cell_exit | (cell_pos, button, action)| (cell_pos)| | on_click | unchanged | unchanged | | on_cell_click | unchanged | unchanged | closes #230 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e14f3cb9fc
commit
2daebc84b5
12 changed files with 598 additions and 71 deletions
|
|
@ -61,13 +61,14 @@ try:
|
|||
assert isinstance(cell_pos, mcrfpy.Vector), f"cell_pos should be Vector, got {type(cell_pos)}"
|
||||
self.cell_events.append(('click', cell_pos.x, cell_pos.y, button, action))
|
||||
|
||||
def on_cell_enter(self, cell_pos, button, action):
|
||||
# #230 - Cell hover callbacks now only receive (cell_pos)
|
||||
def on_cell_enter(self, cell_pos):
|
||||
assert isinstance(cell_pos, mcrfpy.Vector), f"cell_pos should be Vector, got {type(cell_pos)}"
|
||||
self.cell_events.append(('enter', cell_pos.x, cell_pos.y, button, action))
|
||||
self.cell_events.append(('enter', cell_pos.x, cell_pos.y))
|
||||
|
||||
def on_cell_exit(self, cell_pos, button, action):
|
||||
def on_cell_exit(self, cell_pos):
|
||||
assert isinstance(cell_pos, mcrfpy.Vector), f"cell_pos should be Vector, got {type(cell_pos)}"
|
||||
self.cell_events.append(('exit', cell_pos.x, cell_pos.y, button, action))
|
||||
self.cell_events.append(('exit', cell_pos.x, cell_pos.y))
|
||||
|
||||
texture = mcrfpy.Texture("assets/kenney_tinydungeon.png", 16, 16)
|
||||
grid = GridWithCellCallbacks(grid_size=(5, 5), texture=texture, pos=(0, 0), size=(100, 100))
|
||||
|
|
@ -78,8 +79,9 @@ try:
|
|||
|
||||
# Manually call methods to verify signature works
|
||||
grid.on_cell_click(mcrfpy.Vector(1.0, 2.0), mcrfpy.MouseButton.LEFT, mcrfpy.InputState.PRESSED)
|
||||
grid.on_cell_enter(mcrfpy.Vector(3.0, 4.0), mcrfpy.MouseButton.RIGHT, mcrfpy.InputState.RELEASED)
|
||||
grid.on_cell_exit(mcrfpy.Vector(5.0, 6.0), mcrfpy.MouseButton.LEFT, mcrfpy.InputState.PRESSED)
|
||||
# #230 - Cell hover callbacks now only receive (cell_pos)
|
||||
grid.on_cell_enter(mcrfpy.Vector(3.0, 4.0))
|
||||
grid.on_cell_exit(mcrfpy.Vector(5.0, 6.0))
|
||||
|
||||
assert len(grid.cell_events) == 3, f"Should have 3 events, got {len(grid.cell_events)}"
|
||||
assert grid.cell_events[0][0] == 'click', "First event should be click"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue