Skip to content

Fix UIFlatButton border gap, single-style error, and UITextArea styles - #2946

Merged
pvcraven merged 1 commit into
developmentfrom
fix/gui-bugs
Oct 8, 2026
Merged

pvcraven merged 1 commit into
developmentfrom
fix/gui-bugs

Conversation

@pvcraven

@pvcraven pvcraven commented Oct 8, 2026

Copy link
Copy Markdown
Member

Summary

Three GUI fixes found while triaging issues, plus a related UITextArea bug found while fixing one of them.

Gap between UIFlatButton's border and its edge (fixes #2868)

  • Cause: the border outline was drawn inset by a full border width. draw_lbwh_rectangle_outline centers the stroke on the rectangle's edge, so this left a gap of half the border width all around. UIDropdown uses UIFlatButton, so it had the gap too.
  • Fix: the outline is now inset by half the border width, so the stroke reaches the edge exactly.

Confusing error when passing a single style (fixes #2817)

  • Before: UIFlatButton(style=UIFlatButton.UIStyle()) raised TypeError: attribute name must be string, not 'int' from deep inside DictProperty.

  • After: styled widgets check for a single style and raise a TypeError that explains what to pass:

    UIFlatButton style must be a dict of styles for each state, such as {"normal": style, "hover": ..., "press": ..., "disabled": ...}, not a single UIFlatButtonStyle. To change only some states, start from the defaults: {**UIFlatButton.DEFAULT_STYLE, "normal": style}

  • Wrapping a single style as {"normal": style} automatically wouldn't work: the hover and press states would have no style and fail later. Every styled widget has a DEFAULT_STYLE, so the suggestion works for all of them.

UITextArea replaced styles set in the text (fixes #2441)

  • Before: with document_mode="ATTRIBUTED" or "HTML", the widget decoded the text and then set its font and color over the whole document, wiping out inline styles. It also used the length of the raw markup instead of the decoded text.
  • After: styles set in the text win, and the widget's font_name, font_size, text_color, bold and italic fill in the rest. In HTML mode they also replace pyglet's HTML defaults, such as Times New Roman 12 pt. Before, those applied wherever the HTML didn't set a style.

Also: UITextArea(bold=True, italic=True) had no effect

  • The widget set the bold and italic style keys, but pyglet 3 reads weight and style, so the text was drawn plain in every mode. It now sets weight and style, as arcade.Text already does.
  • The text widgets page of the gui/2_widgets example used {bold True} in its attributed text, so its labels weren't bold either. The markup now uses {weight "bold"}.

Tests

  • test_uiflatbutton_border.py: renders a button into a GUI surface and reads the pixels across its middle. The border must reach both edges. On development the first pixel is background color.
  • test_uistyle.py: a single style raises the new error, and the suggested {**DEFAULT_STYLE, "normal": style} works. The error test fails on development.
  • test_uitextarea_styles.py: bold and italic, plain text, attributed text keeping an inline color, and HTML keeping <b> and <font color> while the arguments apply to the rest. 3 of the 4 fail on development.
  • The 14 GUI examples that use these widgets run.

Full suite: 1764 passed. ruff, mypy and pyright all pass.

The changelog has entries under Unreleased → Fixes.

🤖 Generated with Claude Code

- UIFlatButton drew its border outline inset by a full border width,
  but outlines are centered on their rectangle, leaving a gap of half
  the border width at the edge (also on UIDropdown) (#2868).
- Passing a single style to a styled widget raised a confusing
  TypeError from DictProperty. It now says a dict of styles per state
  is needed, and how to start from DEFAULT_STYLE (#2817).
- UITextArea set its font and color over the whole document, replacing
  styles set in ATTRIBUTED and HTML text. Those now win, and the
  arguments fill in the rest, also replacing the HTML decoder's own
  defaults (#2441). bold and italic set keys pyglet 3 doesn't read, so
  they now set weight and style. The 2_widgets example's attributed
  text used the old bold key too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pvcraven
pvcraven merged commit 8cdacd0 into development Oct 8, 2026
7 checks passed
@pvcraven
pvcraven deleted the fix/gui-bugs branch October 8, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant