Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just resize/move, not refresh content, for Split.SetOffset #5494

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions container/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
offsetUpdated bool
}

// NewHSplit creates a horizontally arranged container with the specified leading and trailing elements.
Expand Down Expand Up @@ -76,6 +81,7 @@ func (s *Split) SetOffset(offset float64) {
return
}
s.Offset = offset
s.offsetUpdated = true
s.Refresh()
}

Expand Down Expand Up @@ -147,6 +153,12 @@ func (r *splitContainerRenderer) Objects() []fyne.CanvasObject {
}

func (r *splitContainerRenderer) Refresh() {
if r.split.offsetUpdated {
r.Layout(r.split.Size())
r.split.offsetUpdated = false
return
}

r.objects[0] = r.split.Leading
// [1] is divider which doesn't change
r.objects[2] = r.split.Trailing
Expand Down
29 changes: 29 additions & 0 deletions container/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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()
}
Loading