refactor: Rename click property to on_click (closes #139)

Breaking change: callback property standardized to on_* pattern.
- `drawable.click` → `drawable.on_click`

Updated all C++ bindings (8 files) and Python test usages.
Note: src/scripts changes tracked separately (in .gitignore).

This establishes the naming pattern for future callbacks:
on_click, on_enter, on_exit, on_move, on_key, etc.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
John McCardle 2025-11-27 22:31:53 -05:00
parent e9b5a8301d
commit 52a655399e
12 changed files with 20 additions and 20 deletions

View File

@ -99,8 +99,8 @@ static int PyDrawable_set_opacity(PyDrawableObject* self, PyObject* value, void*
// GetSetDef array for properties // GetSetDef array for properties
static PyGetSetDef PyDrawable_getsetters[] = { static PyGetSetDef PyDrawable_getsetters[] = {
{"click", (getter)PyDrawable_get_click, (setter)PyDrawable_set_click, {"on_click", (getter)PyDrawable_get_click, (setter)PyDrawable_set_click,
MCRF_PROPERTY(click, MCRF_PROPERTY(on_click,
"Callable executed when object is clicked. " "Callable executed when object is clicked. "
"Function receives (x, y) coordinates of click." "Function receives (x, y) coordinates of click."
), NULL}, ), NULL},

View File

@ -404,7 +404,7 @@ PyGetSetDef UIArc::getsetters[] = {
"Arc color", NULL}, "Arc color", NULL},
{"thickness", (getter)UIArc::get_thickness, (setter)UIArc::set_thickness, {"thickness", (getter)UIArc::get_thickness, (setter)UIArc::set_thickness,
"Line thickness", NULL}, "Line thickness", NULL},
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, {"on_click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click,
"Callable executed when arc is clicked.", (void*)PyObjectsEnum::UIARC}, "Callable executed when arc is clicked.", (void*)PyObjectsEnum::UIARC},
{"z_index", (getter)UIDrawable::get_int, (setter)UIDrawable::set_int, {"z_index", (getter)UIDrawable::get_int, (setter)UIDrawable::set_int,
"Z-order for rendering (lower values rendered first).", (void*)PyObjectsEnum::UIARC}, "Z-order for rendering (lower values rendered first).", (void*)PyObjectsEnum::UIARC},

View File

@ -273,8 +273,8 @@ PyGetSetDef UICaption::getsetters[] = {
//{"children", (getter)PyUIFrame_get_children, NULL, "UICollection of objects on top of this one", NULL}, //{"children", (getter)PyUIFrame_get_children, NULL, "UICollection of objects on top of this one", NULL},
{"text", (getter)UICaption::get_text, (setter)UICaption::set_text, "The text displayed", NULL}, {"text", (getter)UICaption::get_text, (setter)UICaption::set_text, "The text displayed", NULL},
{"font_size", (getter)UICaption::get_float_member, (setter)UICaption::set_float_member, "Font size (integer) in points", (void*)5}, {"font_size", (getter)UICaption::get_float_member, (setter)UICaption::set_float_member, "Font size (integer) in points", (void*)5},
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, {"on_click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click,
MCRF_PROPERTY(click, MCRF_PROPERTY(on_click,
"Callable executed when object is clicked. " "Callable executed when object is clicked. "
"Function receives (x, y) coordinates of click." "Function receives (x, y) coordinates of click."
), (void*)PyObjectsEnum::UICAPTION}, ), (void*)PyObjectsEnum::UICAPTION},

View File

@ -360,7 +360,7 @@ PyGetSetDef UICircle::getsetters[] = {
"Outline color of the circle", NULL}, "Outline color of the circle", NULL},
{"outline", (getter)UICircle::get_outline, (setter)UICircle::set_outline, {"outline", (getter)UICircle::get_outline, (setter)UICircle::set_outline,
"Outline thickness (0 for no outline)", NULL}, "Outline thickness (0 for no outline)", NULL},
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, {"on_click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click,
"Callable executed when circle is clicked.", (void*)PyObjectsEnum::UICIRCLE}, "Callable executed when circle is clicked.", (void*)PyObjectsEnum::UICIRCLE},
{"z_index", (getter)UIDrawable::get_int, (setter)UIDrawable::set_int, {"z_index", (getter)UIDrawable::get_int, (setter)UIDrawable::set_int,
"Z-order for rendering (lower values rendered first).", (void*)PyObjectsEnum::UICIRCLE}, "Z-order for rendering (lower values rendered first).", (void*)PyObjectsEnum::UICIRCLE},

View File

@ -400,8 +400,8 @@ PyGetSetDef UIFrame::getsetters[] = {
{"fill_color", (getter)UIFrame::get_color_member, (setter)UIFrame::set_color_member, "Fill color of the rectangle", (void*)0}, {"fill_color", (getter)UIFrame::get_color_member, (setter)UIFrame::set_color_member, "Fill color of the rectangle", (void*)0},
{"outline_color", (getter)UIFrame::get_color_member, (setter)UIFrame::set_color_member, "Outline color of the rectangle", (void*)1}, {"outline_color", (getter)UIFrame::get_color_member, (setter)UIFrame::set_color_member, "Outline color of the rectangle", (void*)1},
{"children", (getter)UIFrame::get_children, NULL, "UICollection of objects on top of this one", NULL}, {"children", (getter)UIFrame::get_children, NULL, "UICollection of objects on top of this one", NULL},
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, {"on_click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click,
MCRF_PROPERTY(click, MCRF_PROPERTY(on_click,
"Callable executed when object is clicked. " "Callable executed when object is clicked. "
"Function receives (x, y) coordinates of click." "Function receives (x, y) coordinates of click."
), (void*)PyObjectsEnum::UIFRAME}, ), (void*)PyObjectsEnum::UIFRAME},

View File

@ -1478,8 +1478,8 @@ PyGetSetDef UIGrid::getsetters[] = {
{"center_y", (getter)UIGrid::get_float_member, (setter)UIGrid::set_float_member, "center of the view Y-coordinate", (void*)5}, {"center_y", (getter)UIGrid::get_float_member, (setter)UIGrid::set_float_member, "center of the view Y-coordinate", (void*)5},
{"zoom", (getter)UIGrid::get_float_member, (setter)UIGrid::set_float_member, "zoom factor for displaying the Grid", (void*)6}, {"zoom", (getter)UIGrid::get_float_member, (setter)UIGrid::set_float_member, "zoom factor for displaying the Grid", (void*)6},
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, {"on_click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click,
MCRF_PROPERTY(click, MCRF_PROPERTY(on_click,
"Callable executed when object is clicked. " "Callable executed when object is clicked. "
"Function receives (x, y) coordinates of click." "Function receives (x, y) coordinates of click."
), (void*)PyObjectsEnum::UIGRID}, ), (void*)PyObjectsEnum::UIGRID},

View File

@ -422,8 +422,8 @@ PyGetSetDef UILine::getsetters[] = {
MCRF_PROPERTY(color, "Line color as a Color object."), NULL}, MCRF_PROPERTY(color, "Line color as a Color object."), NULL},
{"thickness", (getter)UILine::get_thickness, (setter)UILine::set_thickness, {"thickness", (getter)UILine::get_thickness, (setter)UILine::set_thickness,
MCRF_PROPERTY(thickness, "Line thickness in pixels."), NULL}, MCRF_PROPERTY(thickness, "Line thickness in pixels."), NULL},
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, {"on_click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click,
MCRF_PROPERTY(click, "Callable executed when line is clicked."), MCRF_PROPERTY(on_click, "Callable executed when line is clicked."),
(void*)PyObjectsEnum::UILINE}, (void*)PyObjectsEnum::UILINE},
{"z_index", (getter)UIDrawable::get_int, (setter)UIDrawable::set_int, {"z_index", (getter)UIDrawable::get_int, (setter)UIDrawable::set_int,
MCRF_PROPERTY(z_index, "Z-order for rendering (lower values rendered first)."), MCRF_PROPERTY(z_index, "Z-order for rendering (lower values rendered first)."),

View File

@ -339,8 +339,8 @@ PyGetSetDef UISprite::getsetters[] = {
{"sprite_index", (getter)UISprite::get_int_member, (setter)UISprite::set_int_member, "Which sprite on the texture is shown", NULL}, {"sprite_index", (getter)UISprite::get_int_member, (setter)UISprite::set_int_member, "Which sprite on the texture is shown", NULL},
{"sprite_number", (getter)UISprite::get_int_member, (setter)UISprite::set_int_member, "Sprite index (DEPRECATED: use sprite_index instead)", NULL}, {"sprite_number", (getter)UISprite::get_int_member, (setter)UISprite::set_int_member, "Sprite index (DEPRECATED: use sprite_index instead)", NULL},
{"texture", (getter)UISprite::get_texture, (setter)UISprite::set_texture, "Texture object", NULL}, {"texture", (getter)UISprite::get_texture, (setter)UISprite::set_texture, "Texture object", NULL},
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, {"on_click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click,
MCRF_PROPERTY(click, MCRF_PROPERTY(on_click,
"Callable executed when object is clicked. " "Callable executed when object is clicked. "
"Function receives (x, y) coordinates of click." "Function receives (x, y) coordinates of click."
), (void*)PyObjectsEnum::UISPRITE}, ), (void*)PyObjectsEnum::UISPRITE},

View File

@ -437,7 +437,7 @@ class SweetButton:
# box w/ drop shadow # box w/ drop shadow
self.shadow_offset = shadow_offset self.shadow_offset = shadow_offset
self.base_frame = mcrfpy.Frame(pos=(x, y), size=(box_width+shadow_offset, box_height), fill_color=(0, 0, 0, 255)) self.base_frame = mcrfpy.Frame(pos=(x, y), size=(box_width+shadow_offset, box_height), fill_color=(0, 0, 0, 255))
self.base_frame.click = self.do_click self.base_frame.on_click = self.do_click
# drop shadow won't need configured, append directly # drop shadow won't need configured, append directly
if shadow: if shadow:

View File

@ -127,7 +127,7 @@ class TextInput:
self.parent_frame.children.append(self.frame) self.parent_frame.children.append(self.frame)
# Click handler on the input frame # Click handler on the input frame
self.frame.click = self._on_click self.frame.on_click = self._on_click
def _on_click(self, x, y, button, state): def _on_click(self, x, y, button, state):
"""Handle mouse clicks""" """Handle mouse clicks"""

View File

@ -68,7 +68,7 @@ frame.children.append(caption)
def frame_clicked(x, y, button): def frame_clicked(x, y, button):
print(f"Frame clicked at ({x}, {y}) with button {button}") print(f"Frame clicked at ({x}, {y}) with button {button}")
frame.click = frame_clicked frame.on_click = frame_clicked
print("Scene setup complete. Setting timer for automation tests...") print("Scene setup complete. Setting timer for automation tests...")

View File

@ -67,7 +67,7 @@ def test_issue_42_click_callback():
try: try:
frame1 = mcrfpy.Frame(10, 10, 200, 150) frame1 = mcrfpy.Frame(10, 10, 200, 150)
ui.append(frame1) ui.append(frame1)
frame1.click = correct_callback frame1.on_click = correct_callback
print("✓ Click callback with correct signature assigned successfully") print("✓ Click callback with correct signature assigned successfully")
except Exception as e: except Exception as e:
print(f"✗ Failed to assign correct callback: {type(e).__name__}: {e}") print(f"✗ Failed to assign correct callback: {type(e).__name__}: {e}")
@ -80,7 +80,7 @@ def test_issue_42_click_callback():
try: try:
frame2 = mcrfpy.Frame(220, 10, 200, 150) frame2 = mcrfpy.Frame(220, 10, 200, 150)
ui.append(frame2) ui.append(frame2)
frame2.click = wrong_callback_no_args frame2.on_click = wrong_callback_no_args
print("✓ Click callback with no args assigned (will fail at runtime per issue #42)") print("✓ Click callback with no args assigned (will fail at runtime per issue #42)")
except Exception as e: except Exception as e:
print(f"✗ Failed to assign callback: {type(e).__name__}: {e}") print(f"✗ Failed to assign callback: {type(e).__name__}: {e}")
@ -93,7 +93,7 @@ def test_issue_42_click_callback():
try: try:
frame3 = mcrfpy.Frame(10, 170, 200, 150) frame3 = mcrfpy.Frame(10, 170, 200, 150)
ui.append(frame3) ui.append(frame3)
frame3.click = wrong_callback_few_args frame3.on_click = wrong_callback_few_args
print("✓ Click callback with 2 args assigned (will fail at runtime per issue #42)") print("✓ Click callback with 2 args assigned (will fail at runtime per issue #42)")
except Exception as e: except Exception as e:
print(f"✗ Failed to assign callback: {type(e).__name__}: {e}") print(f"✗ Failed to assign callback: {type(e).__name__}: {e}")