Lists are now single-column
This commit is contained in:
parent
4fe778c095
commit
eaee284aaf
@ -18,7 +18,6 @@ type List struct {
|
|||||||
|
|
||||||
scroll image.Point
|
scroll image.Point
|
||||||
contentBounds image.Rectangle
|
contentBounds image.Rectangle
|
||||||
columnSizes []int
|
|
||||||
selected int
|
selected int
|
||||||
|
|
||||||
forcedMinimumWidth int
|
forcedMinimumWidth int
|
||||||
@ -29,10 +28,8 @@ type List struct {
|
|||||||
onScrollBoundsChange func ()
|
onScrollBoundsChange func ()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewList (columns int, children ...tomo.Element) (element *List) {
|
func NewList (children ...tomo.Element) (element *List) {
|
||||||
if columns < 1 { columns = 1 }
|
|
||||||
element = &List { selected: -1 }
|
element = &List { selected: -1 }
|
||||||
element.columnSizes = make([]int, columns)
|
|
||||||
element.theme.Case = tomo.C("tomo", "list")
|
element.theme.Case = tomo.C("tomo", "list")
|
||||||
element.entity = tomo.NewEntity(element).(listEntity)
|
element.entity = tomo.NewEntity(element).(listEntity)
|
||||||
element.container.entity = element.entity
|
element.container.entity = element.entity
|
||||||
@ -62,45 +59,23 @@ func (element *List) Layout () {
|
|||||||
bounds := padding.Apply(element.entity.Bounds())
|
bounds := padding.Apply(element.entity.Bounds())
|
||||||
element.contentBounds = image.Rectangle { }
|
element.contentBounds = image.Rectangle { }
|
||||||
|
|
||||||
dot := bounds.Min.Sub(element.scroll)
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
for index := 0; index < element.entity.CountChildren(); index ++ {
|
for index := 0; index < element.entity.CountChildren(); index ++ {
|
||||||
child := element.entity.Child(index)
|
child := element.entity.Child(index)
|
||||||
entry := element.scratch[child]
|
entry := element.scratch[child]
|
||||||
|
|
||||||
if columnIndex >= len(element.columnSizes) {
|
width := bounds.Dx()
|
||||||
nextLine()
|
|
||||||
}
|
|
||||||
width := element.columnSizes[columnIndex]
|
|
||||||
height := int(entry.minSize)
|
height := int(entry.minSize)
|
||||||
|
|
||||||
if len(element.columnSizes) == 1 && width < bounds.Dx() {
|
|
||||||
width = bounds.Dx()
|
|
||||||
}
|
|
||||||
|
|
||||||
if rowHeight < height {
|
|
||||||
rowHeight = height
|
|
||||||
}
|
|
||||||
|
|
||||||
childBounds := tomo.Bounds (
|
childBounds := tomo.Bounds (
|
||||||
dot.X, dot.Y,
|
dot.X, dot.Y,
|
||||||
width, height)
|
width, height)
|
||||||
element.entity.PlaceChild(index, childBounds)
|
element.entity.PlaceChild(index, childBounds)
|
||||||
element.contentBounds = element.contentBounds.Union(childBounds)
|
element.contentBounds = element.contentBounds.Union(childBounds)
|
||||||
|
|
||||||
dot.X += width + margin.X
|
dot.Y += height
|
||||||
|
dot.Y += margin.Y
|
||||||
columnIndex ++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
element.contentBounds =
|
element.contentBounds =
|
||||||
@ -218,23 +193,10 @@ func (element *List) updateMinimumSize () {
|
|||||||
margin := element.theme.Margin(tomo.PatternSunken)
|
margin := element.theme.Margin(tomo.PatternSunken)
|
||||||
padding := element.theme.Padding(tomo.PatternSunken)
|
padding := element.theme.Padding(tomo.PatternSunken)
|
||||||
|
|
||||||
for index := range element.columnSizes {
|
width := 0
|
||||||
element.columnSizes[index] = 0
|
height := 0
|
||||||
}
|
|
||||||
|
|
||||||
height := 0
|
|
||||||
rowHeight := 0
|
|
||||||
columnIndex := 0
|
|
||||||
nextLine := func () {
|
|
||||||
height += rowHeight
|
|
||||||
rowHeight = 0
|
|
||||||
columnIndex = 0
|
|
||||||
}
|
|
||||||
for index := 0; index < element.entity.CountChildren(); index ++ {
|
for index := 0; index < element.entity.CountChildren(); index ++ {
|
||||||
if columnIndex >= len(element.columnSizes) {
|
if index > 0 { height += margin.Y }
|
||||||
if index > 0 { height += margin.Y }
|
|
||||||
nextLine()
|
|
||||||
}
|
|
||||||
|
|
||||||
child := element.entity.Child(index)
|
child := element.entity.Child(index)
|
||||||
entry := element.scratch[child]
|
entry := element.scratch[child]
|
||||||
@ -244,30 +206,19 @@ func (element *List) updateMinimumSize () {
|
|||||||
entry.minSize = float64(entryHeight)
|
entry.minSize = float64(entryHeight)
|
||||||
element.scratch[child] = entry
|
element.scratch[child] = entry
|
||||||
|
|
||||||
if rowHeight < entryHeight {
|
height += entryHeight
|
||||||
rowHeight = entryHeight
|
if width < entryWidth { width = entryWidth }
|
||||||
}
|
|
||||||
if element.columnSizes[columnIndex] < entryWidth {
|
|
||||||
element.columnSizes[columnIndex] = entryWidth
|
|
||||||
}
|
|
||||||
|
|
||||||
columnIndex ++
|
|
||||||
}
|
}
|
||||||
nextLine()
|
|
||||||
|
|
||||||
width := 0; for index, size := range element.columnSizes {
|
|
||||||
width += size
|
|
||||||
if index > 0 { width += margin.X }
|
|
||||||
}
|
|
||||||
width += padding.Horizontal()
|
width += padding.Horizontal()
|
||||||
height += padding.Vertical()
|
height += padding.Vertical()
|
||||||
|
|
||||||
if element.forcedMinimumHeight > 0 {
|
|
||||||
height = element.forcedMinimumHeight
|
|
||||||
}
|
|
||||||
if element.forcedMinimumWidth > 0 {
|
if element.forcedMinimumWidth > 0 {
|
||||||
width = element.forcedMinimumWidth
|
width = element.forcedMinimumWidth
|
||||||
}
|
}
|
||||||
|
if element.forcedMinimumHeight > 0 {
|
||||||
|
height = element.forcedMinimumHeight
|
||||||
|
}
|
||||||
|
|
||||||
element.entity.SetMinimumSize(width, height)
|
element.entity.SetMinimumSize(width, height)
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,6 @@ func run () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list := elements.NewList (
|
list := elements.NewList (
|
||||||
1,
|
|
||||||
makePage("button", func () { turnPage(button) }),
|
makePage("button", func () { turnPage(button) }),
|
||||||
makePage("mouse", func () { turnPage(mouse) }),
|
makePage("mouse", func () { turnPage(mouse) }),
|
||||||
makePage("input", func () { turnPage(input) }),
|
makePage("input", func () { turnPage(input) }),
|
||||||
|
@ -19,7 +19,6 @@ func run () {
|
|||||||
|
|
||||||
disconnectedContainer := elements.NewHBox(elements.SpaceMargin)
|
disconnectedContainer := elements.NewHBox(elements.SpaceMargin)
|
||||||
list := elements.NewList (
|
list := elements.NewList (
|
||||||
2,
|
|
||||||
elements.NewCell(elements.NewCheckbox("Item 0", true)),
|
elements.NewCell(elements.NewCheckbox("Item 0", true)),
|
||||||
elements.NewCell(elements.NewCheckbox("Item 1", false)),
|
elements.NewCell(elements.NewCheckbox("Item 1", false)),
|
||||||
elements.NewCell(elements.NewCheckbox("Item 2", false)),
|
elements.NewCell(elements.NewCheckbox("Item 2", false)),
|
||||||
|
Reference in New Issue
Block a user