Skip to content

Add Wrapping field to RadioGroup for long option strings (#5656)#6382

Open
mohsenm4 wants to merge 3 commits into
fyne-io:developfrom
mohsenm4:feature/5656-radiogroup-wrap
Open

Add Wrapping field to RadioGroup for long option strings (#5656)#6382
mohsenm4 wants to merge 3 commits into
fyne-io:developfrom
mohsenm4:feature/5656-radiogroup-wrap

Conversation

@mohsenm4

Copy link
Copy Markdown
Contributor

Summary

Adds a Wrapping fyne.TextWrap field on RadioGroup (since 2.9) so a long
option string can wrap to a new line instead of being clipped.

Fixes #5656

Example from the issue now wraps at the right edge of the group:

widget.NewRadioGroup([]string{"long string: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, nil)

Approach

  • The radioItem label is converted from canvas.Text to RichText so
    the existing wrap implementation can be reused. RichText.inset is
    set to InnerPadding so the geometry the renderer produces is the
    same as before.
  • RadioGroup.Wrapping is propagated to each radioItem.wrapping and
    forwarded to the label inside Refresh, so changes after creation
    apply immediately.
  • When wrapping is enabled, radioGroupRenderer.Layout uses the
    assigned size as the available width and reads each item's height
    back from MinSize so wrapped lines stay inside the group. With the
    default TextWrapOff, the previous layout path is kept unchanged,
    so existing apps are not affected.

Notes for review

  • The public API is plain fyne.TextWrap, matching widget.Label.
  • The XML markup fixtures are regenerated because the label is now a
    *widget.RichText node wrapping a <text> child. Positions and
    sizes did not change.
  • There is an existing PR (Add support for Wrapping for RadioGroup option strings #6369) targeting the same issue. This PR
    takes a smaller approach: it keeps the no-wrap layout path bit-for-
    bit identical and only adds a separate wrap-aware path, instead of
    rewriting the existing one.

Test plan

  • go test ./widget/ -run TestRadio (all radio tests pass)
  • New TestRadioGroup_Wrapping_PropagatesToItems verifies the
    field is forwarded to each item on create and on Refresh.
  • New TestRadioGroup_Wrapping_WrapsLongOption verifies that a
    long option is taller with TextWrapBreak than without.

mohsenm4 added 2 commits June 28, 2026 11:23
Switch the internal label of each radio item from canvas.Text to
RichText so future work can drive a TextWrap setting. RichText.inset
is set to InnerPadding so the label keeps the previous geometry.

Theme tests now read RichText MinSize because TextSize no longer
exists; markup fixtures are regenerated to reflect the new label
widget node (positions and sizes are unchanged).
Add a public Wrapping field on RadioGroup (Since: 2.9) that is
propagated to each radio item and forwarded to the underlying
RichText label.

When wrapping is enabled, Layout uses the assigned size to size
each item to the available width and reads its content height
back so wrapped lines stay inside the group. With the default
TextWrapOff the previous layout path is preserved unchanged.
@coveralls

coveralls commented Jun 28, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 59.931% (+0.04%) from 59.89% — mohsenm4:feature/5656-radiogroup-wrap into fyne-io:develop

* Drop the redundant inset assignment in CreateRenderer; update()
  already sets it and runs immediately after.
* Document why label.inset is set to InnerPadding (negate RichText's
  built-in padding so geometry stays compatible with the old
  canvas.Text-based renderer).
* Add a Scroll hint to RadioGroup.Wrapping's godoc for when the
  parent does not give the group enough room.
* Note in radioGroupRenderer.MinSize that per-item MinSize shrinks
  with Wrapping enabled, mirroring widget.Label.
* Add a horizontal-wrap test that asserts items keep equal width and
  height and are placed side by side.
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.

Add support for Wrapping for RadioGroup option strings

2 participants