Skip to content

Commit

Permalink
Don't lay out parent object more than required
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Mar 4, 2020
1 parent 2a47561 commit bc298b8
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions internal/driver/glfw/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func (c *glCanvas) ensureMinSize() bool {
if c.Content() == nil {
return false
}
var lastParent fyne.CanvasObject

windowNeedsMinSizeUpdate := false
ensureMinSize := func(node *renderCacheNode) {
Expand Down Expand Up @@ -280,23 +281,34 @@ func (c *glCanvas) ensureMinSize() bool {
}
}

switch cont := objToLayout.(type) {
case *fyne.Container:
if cont.Layout != nil {
cont.Layout.Layout(cont.Objects, cont.Size())
}
case fyne.Widget:
cache.Renderer(cont).Layout(cont.Size())
if objToLayout != lastParent {
updateLayout(lastParent)
lastParent = objToLayout
}
}
}
c.walkTrees(nil, ensureMinSize)
if windowNeedsMinSizeUpdate && (c.size.Width < c.MinSize().Width || c.size.Height < c.MinSize().Height) {
c.Resize(c.Size().Union(c.MinSize()))
}

if lastParent != nil {
updateLayout(lastParent)
}
return windowNeedsMinSizeUpdate
}

func updateLayout(objToLayout fyne.CanvasObject) {
switch cont := objToLayout.(type) {
case *fyne.Container:
if cont.Layout != nil {
cont.Layout.Layout(cont.Objects, cont.Size())
}
case fyne.Widget:
cache.Renderer(cont).Layout(cont.Size())
}
}

func (c *glCanvas) paint(size fyne.Size) {
if c.Content() == nil {
return
Expand Down

0 comments on commit bc298b8

Please sign in to comment.