Repository navigation
0.3 feature: Checkbox, RadioGroup and ProgressBar - #13
Merged
Merged
Conversation
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 #12
Summary
Checkbox(text="", *, value=False, on_change=None, color, text_color, font=None): a box with an antialiased check mark and an optional label to its right. It reuses_Clickablefrombutton.py, so press and release, focus loss, hover, the hand cursor and the enabled/visible guards behave exactly like buttons. Clicking the box or the label togglesvalueand callson_change(value). Settingvaluedoesn't call it.RadioGroup(options, *, index=0, on_change=None, direction="vertical", spacing=10, color, text_color, font=None): one widget that draws every option, stacked or in a row.value/indexwork likeDropdown: the setters validate and don't callon_change.highlightedis the hovered option.rectcovers all options, but only the option rows are clickable or hoverable, so the gaps between them aren't.ProgressBar(value=0.0, *, max_value=1.0, color, track_color, border_radius=None, show_text=False, font=None, text_color): display only (no events, no cursor).valueis clamped, andfractionandpercent_textare provided.draw(surface, x, y, width=200, height=12).border_radius=Nonegives pill ends. The fill is drawn as the full track shape clipped to the filled width, so a small value keeps a rounded left end and doesn't turn into a sliver.choice.py(Checkbox, RadioGroup) andprogress.py, exported at the top level. All three follow the enabled/visible pattern: guards,_reset()clears press and hover,_paint()greys them out.utils.draw_rounded_rect(surface, color, rect, radius, *, outline_color=None, outline_width=1)draws a filled rect with antialiased corners (quarteraacircles) and an optional outline. Button, Dropdown (box, menu, highlighted row), TextInput, Slider, the IconButton backdrop, the Dropdown shadow, the new widgets and the demo cards all use it in place ofpg.draw.rect(border_radius=...), whose corners came out jagged. TextInput now draws straight onto the target surface with a clip, with no per-frameSRCALPHAsurface. Cost: about 40 µs for an outlined button, and the demo frame went from about 1.2 to 2.6 ms with the dummy driver; it fills three bands rather than two overlapping rects, because SDL fill time grows with the row count.Breaking changes
None. Only additions.
Deviations
ProgressBar.update(dt)animation. Without a group or anupdatecall the bar would never reach its value, so it's not trivial. Skipped as the brief allowed.ProgressBaralso takestext_color(needed forshow_text, same asSlider).How tested
fraction(including after loweringmax_value),percent_text, fill and track pixels, ignores events, validation. Disabled or hidden Checkbox and RadioGroup ignore clicks (directly and through aGroup) and clear press and hover. The new widgets are added to the shared default-font, clickable and hidden/disabled drawing tests. Demo test: the checkboxes and radio drive the chart and are logged; the progress bars follow the loop and the slider.interactiveguard or the_resetoverride makes the new disabled tests fail.uv run ruff check . && uv run ruff format --check . && uv run pytest && uv run pygameuikit-demo --frames 5: 116 passed.