Skip to content

0.3 cleanup 1/4: Widget base class, Group cursor, utils, exports - #8

Merged
Times0 merged 3 commits into
masterfrom
cleanup/core
Oct 28, 2026
Merged

Times0 merged 3 commits into
masterfrom
cleanup/core

Conversation

@Times0

@Times0 Times0 commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Summary

First of four stacked PRs for the 0.3.0 cleanup. This one is the foundation only; buttons/label, inputs and the demo are redesigned in the following PRs, so their constructors are only adapted minimally here.

  • New PygameUIKit.widget with Widget (base of every widget: rect, hovered, cursor, event_priority, handle_event(event) -> bool, update(dt), draw(...)) and Group. Replaces super_object.py.
  • Every handle_event returns True when it consumed the event (button press/click, slider drag, click/typing in a focused text input, open-dropdown interactions). Group.handle_event stops at the first consumer and returns whether one did.
  • Group sets the system cursor after each MOUSEMOTION (hovered widget's cursor, else arrow; only calls set_cursor when it changes). Buttons/slider/dropdown use the hand cursor, text inputs the I-beam. Widgets no longer touch the cursor.
  • A focused TextInput has event_priority 1 so clicking a button (which now consumes the click) still unfocuses it.
  • utilis.py -> utils.py, ligther_color -> lighter_color, get_font moved there. No other helper was unused.
  • Removed: Group.draw, ObjectWithText, EasyObject.update_pos, DEFAULT_FONT, handle_events, button/slider on_hover/on_unhover hooks, the duplicate root src/demo.py and src/assets/.
  • Top-level exports: Group, Widget and all existing widget classes under their current names.

Breaking changes

Listed in CHANGELOG.md under ## Unreleased (0.3.0) -> "Upgrading from 0.2". Notable: Group.objects -> Group.widgets, is_hover/hover -> hovered, TextInput.cursor (caret index) -> TextInput.caret (since cursor is now the system cursor), and overlapping widgets no longer all react to the same click.

How tested

uv run ruff check . && uv run ruff format --check . && uv run pytest && uv run pygameuikit-demo --frames 5 (45 tests pass), plus uv build and checked the sdist contents. New tests cover handle_event return values, Group stopping propagation (and surviving removal during dispatch), focus loss when clicking a button, and Group cursor selection (monkeypatched utils.set_system_cursor).

Replace super_object with widget.Widget/Group. handle_event returns True
when consumed and Group stops propagation there. Group sets the cursor of
the hovered widget after MOUSEMOTION. Rename utilis to utils, unify
hovered, rename TextInput.cursor to caret, drop dead helpers and
handle_events, and export widget classes at the top level.
@Times0
Times0 merged commit 2aff1b1 into master Oct 28, 2026
9 checks passed
@Times0
Times0 deleted the cleanup/core branch October 28, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant