layout fixes and upgrades, add list hdr sort icon
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package layouts
|
||||
|
||||
import "fyne.io/fyne/v2"
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
)
|
||||
|
||||
// ColumnsLayout lays out a number of items into columns.
|
||||
// There are two types of columns: fixed-width and variable width.
|
||||
@@ -58,11 +60,13 @@ func (c *ColumnsLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||
if !objects[i].Visible() {
|
||||
continue
|
||||
}
|
||||
|
||||
w := objects[i].MinSize().Width
|
||||
if i < len(c.ColumnWidths) && c.ColumnWidths[i] > w {
|
||||
w = c.ColumnWidths[i]
|
||||
} else if c.ColumnWidths[i] < 0 && expandObjW > w {
|
||||
w = expandObjW
|
||||
if i >= len(c.ColumnWidths) || c.ColumnWidths[i] < 0 {
|
||||
// expanding width column
|
||||
w = fyne.Max(expandObjW, w)
|
||||
} else {
|
||||
w = fyne.Max(c.ColumnWidths[i], w)
|
||||
}
|
||||
objects[i].Resize(fyne.NewSize(w, size.Height))
|
||||
objects[i].Move(fyne.NewPos(x, 0))
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user