From eaee284aafae23b87f05681b2da7b8432f2dc655 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 20 Apr 2023 14:06:00 -0400 Subject: [PATCH] Lists are now single-column --- elements/list.go | 75 +++++++---------------------------------- examples/list/main.go | 1 - examples/scroll/main.go | 1 - 3 files changed, 13 insertions(+), 64 deletions(-) diff --git a/elements/list.go b/elements/list.go index b7429f6..9f3079e 100644 --- a/elements/list.go +++ b/elements/list.go @@ -18,7 +18,6 @@ type List struct { scroll image.Point contentBounds image.Rectangle - columnSizes []int selected int forcedMinimumWidth int @@ -29,10 +28,8 @@ type List struct { onScrollBoundsChange func () } -func NewList (columns int, children ...tomo.Element) (element *List) { - if columns < 1 { columns = 1 } +func NewList (children ...tomo.Element) (element *List) { element = &List { selected: -1 } - element.columnSizes = make([]int, columns) element.theme.Case = tomo.C("tomo", "list") element.entity = tomo.NewEntity(element).(listEntity) element.container.entity = element.entity @@ -62,45 +59,23 @@ func (element *List) Layout () { bounds := padding.Apply(element.entity.Bounds()) element.contentBounds = image.Rectangle { } - dot := bounds.Min.Sub(element.scroll) - xStart := dot.X - rowHeight := 0 - columnIndex := 0 - nextLine := func () { - dot.X = xStart - dot.Y += margin.Y - dot.Y += rowHeight - rowHeight = 0 - columnIndex = 0 - } + dot := bounds.Min.Sub(element.scroll) for index := 0; index < element.entity.CountChildren(); index ++ { child := element.entity.Child(index) entry := element.scratch[child] - if columnIndex >= len(element.columnSizes) { - nextLine() - } - width := element.columnSizes[columnIndex] + width := bounds.Dx() height := int(entry.minSize) - if len(element.columnSizes) == 1 && width < bounds.Dx() { - width = bounds.Dx() - } - - if rowHeight < height { - rowHeight = height - } - childBounds := tomo.Bounds ( dot.X, dot.Y, width, height) element.entity.PlaceChild(index, childBounds) element.contentBounds = element.contentBounds.Union(childBounds) - - dot.X += width + margin.X - columnIndex ++ + dot.Y += height + dot.Y += margin.Y } element.contentBounds = @@ -218,23 +193,10 @@ func (element *List) updateMinimumSize () { margin := element.theme.Margin(tomo.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken) - for index := range element.columnSizes { - element.columnSizes[index] = 0 - } - - height := 0 - rowHeight := 0 - columnIndex := 0 - nextLine := func () { - height += rowHeight - rowHeight = 0 - columnIndex = 0 - } + width := 0 + height := 0 for index := 0; index < element.entity.CountChildren(); index ++ { - if columnIndex >= len(element.columnSizes) { - if index > 0 { height += margin.Y } - nextLine() - } + if index > 0 { height += margin.Y } child := element.entity.Child(index) entry := element.scratch[child] @@ -243,31 +205,20 @@ func (element *List) updateMinimumSize () { entry.minBreadth = float64(entryWidth) entry.minSize = float64(entryHeight) element.scratch[child] = entry - - if rowHeight < entryHeight { - rowHeight = entryHeight - } - if element.columnSizes[columnIndex] < entryWidth { - element.columnSizes[columnIndex] = entryWidth - } - columnIndex ++ + height += entryHeight + if width < entryWidth { width = entryWidth } } - nextLine() - width := 0; for index, size := range element.columnSizes { - width += size - if index > 0 { width += margin.X } - } width += padding.Horizontal() height += padding.Vertical() - if element.forcedMinimumHeight > 0 { - height = element.forcedMinimumHeight - } if element.forcedMinimumWidth > 0 { width = element.forcedMinimumWidth } + if element.forcedMinimumHeight > 0 { + height = element.forcedMinimumHeight + } element.entity.SetMinimumSize(width, height) } diff --git a/examples/list/main.go b/examples/list/main.go index 1e4fbc4..eb09fef 100644 --- a/examples/list/main.go +++ b/examples/list/main.go @@ -53,7 +53,6 @@ func run () { } list := elements.NewList ( - 1, makePage("button", func () { turnPage(button) }), makePage("mouse", func () { turnPage(mouse) }), makePage("input", func () { turnPage(input) }), diff --git a/examples/scroll/main.go b/examples/scroll/main.go index 73a2d31..f9a226f 100644 --- a/examples/scroll/main.go +++ b/examples/scroll/main.go @@ -19,7 +19,6 @@ func run () { disconnectedContainer := elements.NewHBox(elements.SpaceMargin) list := elements.NewList ( - 2, elements.NewCell(elements.NewCheckbox("Item 0", true)), elements.NewCell(elements.NewCheckbox("Item 1", false)), elements.NewCell(elements.NewCheckbox("Item 2", false)),