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() {
|
if !objects[i].Visible() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
height = fyne.Max(height, objects[i].MinSize().Height)
|
s := objects[i].MinSize()
|
||||||
w := objects[i].MinSize().Width
|
height = fyne.Max(height, s.Height)
|
||||||
|
w := s.Width
|
||||||
if i < len(c.ColumnWidths) && c.ColumnWidths[i] > w {
|
if i < len(c.ColumnWidths) && c.ColumnWidths[i] > w {
|
||||||
w = c.ColumnWidths[i]
|
w = c.ColumnWidths[i]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ func (v *HboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size)
|
|||||||
|
|
||||||
x, y := float32(0), float32(0)
|
x, y := float32(0), float32(0)
|
||||||
|
|
||||||
|
padding := v.themePad() + v.ExtraPad
|
||||||
extra := float32(0)
|
extra := float32(0)
|
||||||
for _, child := range objects {
|
for _, child := range objects {
|
||||||
if !child.Visible() {
|
if !child.Visible() {
|
||||||
@@ -46,7 +47,7 @@ func (v *HboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size)
|
|||||||
child.Move(fyne.NewPos(x+extra, y))
|
child.Move(fyne.NewPos(x+extra, y))
|
||||||
x += width
|
x += width
|
||||||
child.Resize(fyne.NewSize(width, size.Height))
|
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) {
|
func (b *LeftMiddleRightLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||||
|
pad := theme.Padding()
|
||||||
midW := fyne.Max(b.middleWidth, objects[1].MinSize().Width)
|
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].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].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 {
|
if objects[2] != nil {
|
||||||
objects[2].Resize(fyne.NewSize(lrW, size.Height))
|
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 {
|
if len(objects) == 0 {
|
||||||
return
|
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 {
|
for _, child := range objects {
|
||||||
if !child.Visible() {
|
if !child.Visible() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
child.Move(fyne.NewPos(c.PadLeft, c.PadTop))
|
child.Move(pos)
|
||||||
child.Resize(fyne.NewSize(size.Width-c.PadLeft-c.PadRight, size.Height-c.PadTop-c.PadBottom))
|
child.Resize(objSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ func (v *VboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size)
|
|||||||
|
|
||||||
x, y := float32(0), float32(0)
|
x, y := float32(0), float32(0)
|
||||||
|
|
||||||
|
padding := theme.Padding() + v.ExtraPad
|
||||||
extra := float32(0)
|
extra := float32(0)
|
||||||
for _, child := range objects {
|
for _, child := range objects {
|
||||||
if !child.Visible() {
|
if !child.Visible() {
|
||||||
@@ -45,6 +46,6 @@ func (v *VboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size)
|
|||||||
child.Move(fyne.NewPos(x, y+extra))
|
child.Move(fyne.NewPos(x, y+extra))
|
||||||
y += height
|
y += height
|
||||||
child.Resize(fyne.NewSize(size.Width, height))
|
child.Resize(fyne.NewSize(size.Width, height))
|
||||||
extra += (theme.Padding() + v.ExtraPad)
|
extra += padding
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user