misc: Port latest Fyne layout changes
Specific commits ported, to update the layouts and reduce differences with upstream Fyne code: * https://github.com/fyne-io/fyne/commit/a9a66f60d2167d7945bcf7718a781335541317c0 * https://github.com/fyne-io/fyne/commit/2cde868904092382ca5f645802ee9d444d8ae6e8 * https://github.com/fyne-io/fyne/commit/99fa7e3a7dc83dd273ad366cc7d336a1e1cee5f6 * https://github.com/fyne-io/fyne/commit/4ea8a5762f1744401ede9f7bd35b3b75890f925e
This commit is contained in:
@@ -2,6 +2,7 @@ package layouts
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
)
|
||||
|
||||
@@ -11,41 +12,76 @@ type VboxCustomPadding struct {
|
||||
ExtraPad float32
|
||||
}
|
||||
|
||||
func (*VboxCustomPadding) isSpacer(obj fyne.CanvasObject) bool {
|
||||
spacer, ok := obj.(layout.SpacerObject)
|
||||
return ok && spacer.ExpandVertical()
|
||||
}
|
||||
|
||||
func (v *VboxCustomPadding) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
||||
minSize := fyne.NewSize(0, 0)
|
||||
addPadding := false
|
||||
padding := theme.Padding() + v.ExtraPad
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
if !child.Visible() || v.isSpacer(child) {
|
||||
continue
|
||||
}
|
||||
|
||||
minSize.Width = fyne.Max(child.MinSize().Width, minSize.Width)
|
||||
minSize.Height += child.MinSize().Height
|
||||
childMin := child.MinSize()
|
||||
minSize.Width = fyne.Max(childMin.Width, minSize.Width)
|
||||
minSize.Height += childMin.Height
|
||||
if addPadding {
|
||||
minSize.Height += padding
|
||||
}
|
||||
addPadding = true
|
||||
}
|
||||
minSize.Height += (theme.Padding() + v.ExtraPad) * float32(len(objects)-1)
|
||||
return minSize
|
||||
}
|
||||
|
||||
func (v *VboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||
spacers := 0
|
||||
visibleObjects := 0
|
||||
// Size taken up by visible objects
|
||||
total := float32(0)
|
||||
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
continue
|
||||
}
|
||||
|
||||
if v.isSpacer(child) {
|
||||
spacers++
|
||||
continue
|
||||
}
|
||||
|
||||
visibleObjects++
|
||||
total += child.MinSize().Height
|
||||
}
|
||||
|
||||
x, y := float32(0), float32(0)
|
||||
|
||||
padding := theme.Padding() + v.ExtraPad
|
||||
extra := float32(0)
|
||||
|
||||
// Amount of space not taken up by visible objects and inter-object padding
|
||||
extra := size.Height - total - (padding * float32(visibleObjects-1))
|
||||
|
||||
// Spacers split extra space equally
|
||||
spacerSize := float32(0)
|
||||
if spacers > 0 {
|
||||
spacerSize = extra / float32(spacers)
|
||||
}
|
||||
|
||||
x, y := float32(0), float32(0)
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
continue
|
||||
}
|
||||
|
||||
if v.isSpacer(child) {
|
||||
y += spacerSize
|
||||
continue
|
||||
}
|
||||
child.Move(fyne.NewPos(x, y))
|
||||
|
||||
height := child.MinSize().Height
|
||||
child.Move(fyne.NewPos(x, y+extra))
|
||||
y += height
|
||||
y += padding + height
|
||||
child.Resize(fyne.NewSize(size.Width, height))
|
||||
extra += padding
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user