From 927472c932fe5576174aa32fc75588f12d4651ed Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Mon, 3 Feb 2025 15:50:21 -0300 Subject: [PATCH 1/2] just resize/move, not refresh, for Split.SetOffset --- container/split.go | 12 ++++++++++++ container/split_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/container/split.go b/container/split.go index 7d1e3244e4..619e701174 100644 --- a/container/split.go +++ b/container/split.go @@ -20,6 +20,11 @@ type Split struct { Horizontal bool Leading fyne.CanvasObject Trailing fyne.CanvasObject + + // to communicate to the renderer that the next refresh + // is just an offset update (ie a resize and move only) + // cleared by renderer in Refresh() + nextRefreshIsOffsetUpdate bool } // NewHSplit creates a horizontally arranged container with the specified leading and trailing elements. @@ -76,6 +81,7 @@ func (s *Split) SetOffset(offset float64) { return } s.Offset = offset + s.nextRefreshIsOffsetUpdate = true s.Refresh() } @@ -147,6 +153,12 @@ func (r *splitContainerRenderer) Objects() []fyne.CanvasObject { } func (r *splitContainerRenderer) Refresh() { + if r.split.nextRefreshIsOffsetUpdate { + r.Layout(r.split.Size()) + r.split.nextRefreshIsOffsetUpdate = false + return + } + r.objects[0] = r.split.Leading // [1] is divider which doesn't change r.objects[2] = r.split.Trailing diff --git a/container/split_test.go b/container/split_test.go index 4a2d776dee..21577bd576 100644 --- a/container/split_test.go +++ b/container/split_test.go @@ -9,6 +9,7 @@ import ( "fyne.io/fyne/v2/driver/desktop" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" + "fyne.io/fyne/v2/widget" "github.com/stretchr/testify/assert" ) @@ -521,3 +522,31 @@ func TestSplitContainer_Hidden(t *testing.T) { assert.Equal(t, float32(0), sc.Trailing.Size().Height) }) } + +func TestSplitContainer_UpdateOffsetDoesNotRefreshContent(t *testing.T) { + objA := &refreshCountingWidget{} + objB := &refreshCountingWidget{} + split := NewHSplit(objA, objB) + split.SetOffset(0.4) + assert.Equal(t, 0, objA.refreshCount) + assert.Equal(t, 0, objB.refreshCount) + + split.Refresh() + assert.Equal(t, 1, objA.refreshCount) + assert.Equal(t, 1, objB.refreshCount) +} + +type refreshCountingWidget struct { + widget.BaseWidget + + refreshCount int +} + +func (r *refreshCountingWidget) CreateRenderer() fyne.WidgetRenderer { + return widget.NewSimpleRenderer(canvas.NewRectangle(color.Transparent)) +} + +func (r *refreshCountingWidget) Refresh() { + r.refreshCount += 1 + r.BaseWidget.Refresh() +} From fe785e68a4c2b404fa2dba3504ddaffb92b2ce57 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Mon, 3 Feb 2025 16:44:52 -0300 Subject: [PATCH 2/2] rename variable --- container/split.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/container/split.go b/container/split.go index 619e701174..bd064e3a48 100644 --- a/container/split.go +++ b/container/split.go @@ -24,7 +24,7 @@ type Split struct { // to communicate to the renderer that the next refresh // is just an offset update (ie a resize and move only) // cleared by renderer in Refresh() - nextRefreshIsOffsetUpdate bool + offsetUpdated bool } // NewHSplit creates a horizontally arranged container with the specified leading and trailing elements. @@ -81,7 +81,7 @@ func (s *Split) SetOffset(offset float64) { return } s.Offset = offset - s.nextRefreshIsOffsetUpdate = true + s.offsetUpdated = true s.Refresh() } @@ -153,9 +153,9 @@ func (r *splitContainerRenderer) Objects() []fyne.CanvasObject { } func (r *splitContainerRenderer) Refresh() { - if r.split.nextRefreshIsOffsetUpdate { + if r.split.offsetUpdated { r.Layout(r.split.Size()) - r.split.nextRefreshIsOffsetUpdate = false + r.split.offsetUpdated = false return }