layout fixes and upgrades, add list hdr sort icon

This commit is contained in:
Drew Weymouth
2023-05-23 11:10:43 -07:00
parent 1686c563fe
commit 0d02c1fe9d
4 changed files with 130 additions and 26 deletions
+42 -11
View File
@@ -2,6 +2,7 @@ package layouts
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
)
@@ -12,47 +13,77 @@ type HboxCustomPadding struct {
DisableThemePad bool
}
func (v *HboxCustomPadding) MinSize(objects []fyne.CanvasObject) fyne.Size {
func (*HboxCustomPadding) isSpacer(obj fyne.CanvasObject) bool {
if !obj.Visible() {
return false
}
if spacer, ok := obj.(layout.SpacerObject); ok {
return spacer.ExpandHorizontal()
}
return false
}
func (h *HboxCustomPadding) MinSize(objects []fyne.CanvasObject) fyne.Size {
minSize := fyne.NewSize(0, 0)
addPadding := false
padding := h.themePad() + h.ExtraPad
for _, child := range objects {
if !child.Visible() {
continue
}
if h.isSpacer(child) {
continue
}
minSize.Height = fyne.Max(child.MinSize().Height, minSize.Height)
minSize.Width += child.MinSize().Width
if addPadding {
minSize.Width += padding
}
addPadding = true
}
minSize.Width += (v.themePad() + v.ExtraPad) * float32(len(objects)-1)
return minSize
}
func (v *HboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size) {
func (h *HboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size) {
spacers := 0
total := float32(0)
for _, child := range objects {
if !child.Visible() {
continue
}
if h.isSpacer(child) {
spacers++
continue
}
total += child.MinSize().Width
}
x, y := float32(0), float32(0)
padding := v.themePad() + v.ExtraPad
extra := float32(0)
padding := h.themePad() + h.ExtraPad
extra := size.Width - total - (padding * float32(len(objects)-spacers-1))
extraCell := float32(0)
if spacers > 0 {
extraCell = extra / float32(spacers)
}
for _, child := range objects {
if !child.Visible() {
continue
}
if h.isSpacer(child) {
x += extraCell
}
width := child.MinSize().Width
child.Move(fyne.NewPos(x+extra, y))
x += width
child.Move(fyne.NewPos(x, y))
child.Resize(fyne.NewSize(width, size.Height))
extra += padding
x += padding + width
}
}
func (v *HboxCustomPadding) themePad() float32 {
if v.DisableThemePad {
func (h *HboxCustomPadding) themePad() float32 {
if h.DisableThemePad {
return 0
}
return theme.Padding()