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

Only refresh scroll chrome when scroller is resized #5472

Merged
merged 4 commits into from
Jan 29, 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
39 changes: 31 additions & 8 deletions internal/widget/scroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (a *scrollBarArea) CreateRenderer() fyne.WidgetRenderer {

func (a *scrollBarArea) MouseIn(*desktop.MouseEvent) {
a.isMouseIn = true
a.scroll.Refresh()
a.scroll.refreshBars()
}

func (a *scrollBarArea) MouseMoved(*desktop.MouseEvent) {
Expand All @@ -234,7 +234,7 @@ func (a *scrollBarArea) MouseOut() {
return
}

a.scroll.Refresh()
a.scroll.refreshBars()
}

func (a *scrollBarArea) moveBar(offset float32, barSize fyne.Size) {
Expand Down Expand Up @@ -432,12 +432,13 @@ func (s *Scroll) CreateRenderer() fyne.WidgetRenderer {
// ScrollToBottom will scroll content to container bottom - to show latest info which end user just added
func (s *Scroll) ScrollToBottom() {
s.scrollBy(0, -1*(s.Content.MinSize().Height-s.Size().Height-s.Offset.Y))
s.Refresh()
s.refreshBars()
}

// ScrollToTop will scroll content to container top
func (s *Scroll) ScrollToTop() {
s.scrollBy(0, -s.Offset.Y)
s.refreshBars()
}

// DragEnd will stop scrolling on mobile has stopped
Expand Down Expand Up @@ -478,8 +479,11 @@ func (s *Scroll) SetMinSize(size fyne.Size) {

// Refresh causes this widget to be redrawn in it's current state
func (s *Scroll) Refresh() {
s.updateOffset(0, 0)
s.refreshWithoutOffsetUpdate()
s.refreshBars()

if s.Content != nil {
s.Content.Refresh()
}
}

// Resize is called when this scroller should change size. We refresh to ensure the scroll bars are updated.
Expand All @@ -489,7 +493,19 @@ func (s *Scroll) Resize(sz fyne.Size) {
}

s.Base.Resize(sz)
s.Refresh()
s.refreshBars()
}

// ScrollToOffset will update the location of the content of this scroll container.
//
// Since: 2.6
func (s *Scroll) ScrollToOffset(p fyne.Position) {
if s.Offset.Subtract(p).IsZero() {
return
}

s.Offset = p
s.refreshBars()
}

func (s *Scroll) refreshWithoutOffsetUpdate() {
Expand All @@ -503,6 +519,11 @@ func (s *Scroll) Scrolled(ev *fyne.ScrollEvent) {
}
}

func (s *Scroll) refreshBars() {
s.updateOffset(0, 0)
s.refreshWithoutOffsetUpdate()
}

func (s *Scroll) scrollBy(dx, dy float32) {
min := s.Content.MinSize()
size := s.Size()
Expand Down Expand Up @@ -530,10 +551,12 @@ func (s *Scroll) updateOffset(deltaX, deltaY float32) bool {
min := s.Content.MinSize()
s.Offset.X = computeOffset(s.Offset.X, -deltaX, size.Width, min.Width)
s.Offset.Y = computeOffset(s.Offset.Y, -deltaY, size.Height, min.Height)
if f := s.OnScrolled; f != nil && (s.Offset.X != oldX || s.Offset.Y != oldY) {

moved := s.Offset.X != oldX || s.Offset.Y != oldY
if f := s.OnScrolled; f != nil && moved {
f(s.Offset)
}
return true
return moved
}

func computeOffset(start, delta, outerWidth, innerWidth float32) float32 {
Expand Down
3 changes: 1 addition & 2 deletions widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1996,8 +1996,7 @@ func (r *entryContentRenderer) ensureCursorVisible() {
move.DY += cy2 - (offset.Y + size.Height)
}
if r.content.scroll.Content != nil {
r.content.scroll.Offset = r.content.scroll.Offset.Add(move)
r.content.scroll.Refresh()
r.content.scroll.ScrollToOffset(r.content.scroll.Offset.Add(move))
}
}

Expand Down
15 changes: 6 additions & 9 deletions widget/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package widget // import "fyne.io/fyne/v2/widget"
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/internal/async"
"fyne.io/fyne/v2/internal/cache"
internalWidget "fyne.io/fyne/v2/internal/widget"
"fyne.io/fyne/v2/theme"
Expand Down Expand Up @@ -112,16 +111,14 @@ func (w *BaseWidget) Hide() {

// Refresh causes this widget to be redrawn in its current state
func (w *BaseWidget) Refresh() {
async.EnsureMain(func() {
impl := w.super()
if impl == nil {
return
}
impl := w.super()
if impl == nil {
return
}

w.themeCache = nil
Jacalz marked this conversation as resolved.
Show resolved Hide resolved
w.themeCache = nil

cache.Renderer(impl).Refresh()
})
cache.Renderer(impl).Refresh()
}

// Theme returns a cached Theme instance for this widget (or its extending widget).
Expand Down
Loading