Skip to content

0.3 feature: enabled and visible on every widget - #12

Merged
Times0 merged 4 commits into
masterfrom
feature/states
Oct 28, 2026
Merged

Times0 merged 4 commits into
masterfrom
feature/states

Conversation

@Times0

@Times0 Times0 commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #11

Summary

  • Every widget has enabled and visible properties (default True; attributes only, no constructor arguments, to keep signatures unchanged).
  • Each widget starts handle_event with if not self.interactive: return False and draw with if not self.visible: return, so direct calls are inert too. Group also skips widgets that aren't interactive, which covers user-defined widgets. (An earlier commit used __init_subclass__ wrapping; it was replaced with these plain guards for readability.)
  • Turning either off calls a small overridable _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.
  • Disabled look: colors pass through utils.disabled_color (mostly desaturated and faded toward white) and images through utils.disabled_image (greyscale, translucent), via Widget._paint(color). Label.surface now renders lazily from (text, effective color), so labels follow their state.
  • Cursor: Group sets the cursor after every event and every update(dt), not only after mouse motion. Disabling or hiding the widget under the pointer gives the arrow back right away.
  • Demo: a new States card has "Disable widgets" and "Hide widgets" buttons that toggle a set of showcase widgets across the cards and log 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.
  • README guide and CHANGELOG updated.

Breaking changes

None beyond 0.3.0. Group cursor updates now also happen after non-motion events and in update(dt). They still run only when the cursor changes.

How tested

  • New tests: disabled and hidden widgets ignore events and fire no callbacks, both through a Group and 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. Group skips inactive custom widgets. Also covered: the color and image helpers, and the demo toggles and log.
  • I checked that the tests catch regressions: removing the guards or the _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.
  • Checked screenshots of the disabled and hidden states by eye.

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__.
@Times0
Times0 changed the base branch from cleanup/demo to master October 28, 2026 10:24
@Times0
Times0 merged commit a748294 into master Oct 28, 2026
9 checks passed
@Times0
Times0 deleted the feature/states 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