From 9acf942755b76f455da2b7e3ee5465aea42e5a30 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Tue, 9 Jan 2024 16:02:52 -0800 Subject: [PATCH] run selection initialization code on CreateRenderer --- widget/radio_group.go | 11 +++++++---- widget/radio_group_test.go | 1 - 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/widget/radio_group.go b/widget/radio_group.go index d71dea39b2..e89a7df48b 100644 --- a/widget/radio_group.go +++ b/widget/radio_group.go @@ -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 @@ -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 @@ -238,7 +241,7 @@ func (r *radioGroupRenderer) updateItems() { changed = true } - if changed { + if refresh && changed { item.Refresh() } } diff --git a/widget/radio_group_test.go b/widget/radio_group_test.go index dbea6f6e01..a51639b29a 100644 --- a/widget/radio_group_test.go +++ b/widget/radio_group_test.go @@ -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() }