Repository navigation
0.3 feature: enabled and visible on every widget - #12
Merged
Merged
Conversation
Widget gets enabled and visible properties. Widget.__init_subclass__ wraps each subclass's handle_event and draw once, so disabled or hidden widgets ignore events (through a Group or called directly) and hidden ones draw nothing; custom widgets get the same checks. Turning either off calls a small _reset() hook that clears hover, press, drag, focus and open menus; window focus loss now uses the same hook. Disabled widgets draw their colors through utils.disabled_color (mostly desaturated, faded toward white) and images through utils.disabled_image (greyscale, translucent). Label renders lazily so it follows its state. Group sets the cursor after every event and update, so disabling the widget under the pointer gives the arrow back immediately.
Two buttons disable or hide a set of showcase widgets across the cards and log the change. The window grows to 800 px so the States card fits above the event log; the bar chart spans both bottom rows, and the log shows its newest lines when they do not all fit. Refresh the screenshot.
Describe widget states in the README guide and the changelog, and note that Group now updates the cursor after every event and update.
Widgets now start handle_event with `if not self.interactive` and draw with `if not self.visible`, and Group skips widgets that aren't interactive. Plain guard lines are easier to follow than rewriting subclass methods in __init_subclass__.
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.
Stacked on #11
Summary
enabledandvisibleproperties (defaultTrue; attributes only, no constructor arguments, to keep signatures unchanged).handle_eventwithif not self.interactive: return Falseanddrawwithif not self.visible: return, so direct calls are inert too.Groupalso skips widgets that aren'tinteractive, which covers user-defined widgets. (An earlier commit used__init_subclass__wrapping; it was replaced with these plain guards for readability.)_reset()hook that clears hover, press, drag, text focus and open menus. Window focus loss now uses the same hook, which replaces four hand-written copies.utils.disabled_color(mostly desaturated and faded toward white) and images throughutils.disabled_image(greyscale, translucent), viaWidget._paint(color).Label.surfacenow renders lazily from (text, effective color), so labels follow their state.Groupsets the cursor after every event and everyupdate(dt), not only after mouse motion. Disabling or hiding the widget under the pointer gives the arrow back right away.widget.enabled = .../widget.visible = .... The window is now 1100×800: the chart spans both bottom rows and the States card sits above the event log, which now shows its newest lines when they don't all fit. Screenshot refreshed.Breaking changes
None beyond 0.3.0.
Groupcursor updates now also happen after non-motion events and inupdate(dt). They still run only when the cursor changes.How tested
Groupand directly. Disabling or hiding clears hover, press, drag, focus and open menus. Hidden widgets leave the surface byte-identical, and disabled widgets draw differently from enabled ones. The cursor resets when the hovered widget disables itself or is hidden.Groupskips inactive custom widgets. Also covered: the color and image helpers, and the demo toggles and log._reset()calls makes them fail.uv run ruff check . && uv run ruff format --check . && uv run pytest && uv run pygameuikit-demo --frames 5: 100 passed.