Skip to content

Commit

Permalink
run selection initialization code on CreateRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jan 10, 2024
1 parent ca10bbe commit 9acf942
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 7 additions & 4 deletions widget/radio_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func (r *RadioGroup) CreateRenderer() fyne.WidgetRenderer {
})
}

return &radioGroupRenderer{widget.NewBaseRenderer(items), items, r}
render := &radioGroupRenderer{widget.NewBaseRenderer(items), items, r}
r.updateSelectedIndex()
render.updateItems(false)
return render
}

// MinSize returns the size that this widget should not shrink below
Expand Down Expand Up @@ -202,11 +205,11 @@ func (r *radioGroupRenderer) MinSize() fyne.Size {
}

func (r *radioGroupRenderer) Refresh() {
r.updateItems()
r.updateItems(true)
canvas.Refresh(r.radio.super())
}

func (r *radioGroupRenderer) updateItems() {
func (r *radioGroupRenderer) updateItems(refresh bool) {
if len(r.items) < len(r.radio.Options) {
for i := len(r.items); i < len(r.radio.Options); i++ {
idx := i
Expand Down Expand Up @@ -238,7 +241,7 @@ func (r *radioGroupRenderer) updateItems() {
changed = true
}

if changed {
if refresh && changed {
item.Refresh()
}
}
Expand Down
1 change: 0 additions & 1 deletion widget/radio_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func TestRadioGroup_Layout(t *testing.T) {
Options: tt.options,
Selected: tt.selected,
}
radio.Refresh() // set up selectedIndex
if tt.disabled {
radio.Disable()
}
Expand Down

0 comments on commit 9acf942

Please sign in to comment.