Skip to content

Commit

Permalink
Also do the right thing for widgets extending internal base widget
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Apr 28, 2023
1 parent 2cc9d2e commit d30f691
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
20 changes: 18 additions & 2 deletions internal/widget/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ func (w *Base) Position() fyne.Position {
// Note this should not be used if the widget is being managed by a Layout within a Container.
func (w *Base) Move(pos fyne.Position) {
w.propertyLock.Lock()
defer w.propertyLock.Unlock()

w.position = pos
w.propertyLock.Unlock()

Repaint(w.super())
}

// MinSize for the widget - it should never be resized below this value.
Expand Down Expand Up @@ -158,3 +159,18 @@ func (w *Base) super() fyne.Widget {
w.propertyLock.RUnlock()
return impl
}

// Repaint instructs the containing canvas to redraw, even if nothing changed.
// This method is a duplicate of what is in `canvas/canvas.go` to avoid a dependency loop or public API.
func Repaint(obj fyne.CanvasObject) {
if fyne.CurrentApp() == nil || fyne.CurrentApp().Driver() == nil {
return
}

c := fyne.CurrentApp().Driver().CanvasForObject(obj)
if c != nil {
if paint, ok := c.(interface{ SetDirty() }); ok {
paint.SetDirty()
}
}
}
21 changes: 3 additions & 18 deletions widget/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func (w *BaseWidget) Position() fyne.Position {
// Note this should not be used if the widget is being managed by a Layout within a Container.
func (w *BaseWidget) Move(pos fyne.Position) {
w.propertyLock.Lock()
defer w.propertyLock.Unlock()

w.position = pos
repaint(w)
w.propertyLock.Unlock()

internalWidget.Repaint(w.super())
}

// MinSize for the widget - it should never be resized below this value.
Expand Down Expand Up @@ -207,18 +207,3 @@ func (w *DisableableWidget) Disabled() bool {
func NewSimpleRenderer(object fyne.CanvasObject) fyne.WidgetRenderer {
return internalWidget.NewSimpleRenderer(object)
}

// repaint instructs the containing canvas to redraw, even if nothing changed.
// This method is a duplicate of what is in `canvas/canvas.go` to avoid a dependency loop or public API.
func repaint(obj fyne.CanvasObject) {
if fyne.CurrentApp() == nil || fyne.CurrentApp().Driver() == nil {
return
}

c := fyne.CurrentApp().Driver().CanvasForObject(obj)
if c != nil {
if paint, ok := c.(interface{ SetDirty() }); ok {
paint.SetDirty()
}
}
}

0 comments on commit d30f691

Please sign in to comment.