Repository navigation
0.3 cleanup 1/4: Widget base class, Group cursor, utils, exports - #8
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
PygameUIKit.widgetwithWidget(base of every widget:rect,hovered,cursor,event_priority,handle_event(event) -> bool,update(dt),draw(...)) andGroup. Replacessuper_object.py.handle_eventreturnsTruewhen it consumed the event (button press/click, slider drag, click/typing in a focused text input, open-dropdown interactions).Group.handle_eventstops at the first consumer and returns whether one did.Groupsets the system cursor after eachMOUSEMOTION(hovered widget'scursor, else arrow; only callsset_cursorwhen it changes). Buttons/slider/dropdown use the hand cursor, text inputs the I-beam. Widgets no longer touch the cursor.TextInputhasevent_priority1 so clicking a button (which now consumes the click) still unfocuses it.utilis.py->utils.py,ligther_color->lighter_color,get_fontmoved there. No other helper was unused.Group.draw,ObjectWithText,EasyObject.update_pos,DEFAULT_FONT,handle_events, button/slideron_hover/on_unhoverhooks, the duplicate rootsrc/demo.pyandsrc/assets/.Group,Widgetand 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(sincecursoris 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), plusuv buildand 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 (monkeypatchedutils.set_system_cursor).