don't re-calculate values in loops for layouts
This commit is contained in:
@@ -25,8 +25,9 @@ func (c *ColumnsLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
||||
if !objects[i].Visible() {
|
||||
continue
|
||||
}
|
||||
height = fyne.Max(height, objects[i].MinSize().Height)
|
||||
w := objects[i].MinSize().Width
|
||||
s := objects[i].MinSize()
|
||||
height = fyne.Max(height, s.Height)
|
||||
w := s.Width
|
||||
if i < len(c.ColumnWidths) && c.ColumnWidths[i] > w {
|
||||
w = c.ColumnWidths[i]
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ func (v *HboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size)
|
||||
|
||||
x, y := float32(0), float32(0)
|
||||
|
||||
padding := v.themePad() + v.ExtraPad
|
||||
extra := float32(0)
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
@@ -46,7 +47,7 @@ func (v *HboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size)
|
||||
child.Move(fyne.NewPos(x+extra, y))
|
||||
x += width
|
||||
child.Resize(fyne.NewSize(width, size.Height))
|
||||
extra += (v.themePad() + v.ExtraPad)
|
||||
extra += padding
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,14 +30,15 @@ func (b *LeftMiddleRightLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
||||
}
|
||||
|
||||
func (b *LeftMiddleRightLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||
pad := theme.Padding()
|
||||
midW := fyne.Max(b.middleWidth, objects[1].MinSize().Width)
|
||||
lrW := (size.Width - midW - theme.Padding()*4) / 2
|
||||
lrW := (size.Width - midW - pad*4) / 2
|
||||
objects[0].Resize(fyne.NewSize(lrW, size.Height))
|
||||
objects[0].Move(fyne.NewPos(theme.Padding(), 0))
|
||||
objects[0].Move(fyne.NewPos(pad, 0))
|
||||
objects[1].Resize(fyne.NewSize(midW, size.Height))
|
||||
objects[1].Move(fyne.NewPos(lrW+theme.Padding()*2, 0))
|
||||
objects[1].Move(fyne.NewPos(lrW+pad*2, 0))
|
||||
if objects[2] != nil {
|
||||
objects[2].Resize(fyne.NewSize(lrW, size.Height))
|
||||
objects[2].Move(fyne.NewPos(lrW+midW+theme.Padding()*3, 0))
|
||||
objects[2].Move(fyne.NewPos(lrW+midW+pad*3, 0))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,13 @@ func (c *MaxPadLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||
if len(objects) == 0 {
|
||||
return
|
||||
}
|
||||
pos := fyne.NewPos(c.PadLeft, c.PadTop)
|
||||
objSize := fyne.NewSize(size.Width-c.PadLeft-c.PadRight, size.Height-c.PadTop-c.PadBottom)
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
continue
|
||||
}
|
||||
child.Move(fyne.NewPos(c.PadLeft, c.PadTop))
|
||||
child.Resize(fyne.NewSize(size.Width-c.PadLeft-c.PadRight, size.Height-c.PadTop-c.PadBottom))
|
||||
child.Move(pos)
|
||||
child.Resize(objSize)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ func (v *VboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size)
|
||||
|
||||
x, y := float32(0), float32(0)
|
||||
|
||||
padding := theme.Padding() + v.ExtraPad
|
||||
extra := float32(0)
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
@@ -45,6 +46,6 @@ func (v *VboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size)
|
||||
child.Move(fyne.NewPos(x, y+extra))
|
||||
y += height
|
||||
child.Resize(fyne.NewSize(size.Width, height))
|
||||
extra += (theme.Padding() + v.ExtraPad)
|
||||
extra += padding
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user