Introduce new layouts.Grid construct

This commit is contained in:
Sasha Koshka 2024-06-22 18:44:26 -04:00
parent ae1e62c1f2
commit e8a3a376ea
7 changed files with 17 additions and 12 deletions

View File

@ -47,8 +47,7 @@ func NewCalendar (tm time.Time) *Calendar {
calendar.grid = tomo.NewContainerBox()
calendar.grid.SetRole(tomo.R("objects", "CalendarGrid", ""))
calendar.grid.SetLayout(layouts.NewGrid (
[]bool { true, true, true, true, true, true, true },
[]bool { }))
true, true, true, true, true, true, true)())
calendar.Add(NewInnerContainer (
layouts.Row { false, true, false },
prevButton, calendar.monthLabel, nextButton))

View File

@ -66,7 +66,7 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
dialog.controlRow.SetAlign(tomo.AlignEnd, tomo.AlignEnd)
dialog.SetRoot(NewOuterContainer (
layouts.NewGrid([]bool { true }, []bool { true, false }),
layouts.Column { true, false },
NewInnerContainer(layouts.ContractHorizontal, icon, messageText),
dialog.controlRow))
return dialog, nil

View File

@ -24,7 +24,7 @@ func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
box.Add(box.checkbox)
box.Add(box.label)
box.SetLayout(layouts.NewGrid([]bool { false, true }, []bool { false }))
box.SetLayout(layouts.Row { false, true })
box.OnMouseUp(box.handleMouseUp)
box.label.OnMouseUp(box.handleMouseUp)

View File

@ -25,7 +25,7 @@ func NewLabelSwatch (value color.Color, text string) *LabelSwatch {
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
box.Add(box.swatch)
box.Add(box.label)
box.SetLayout(layouts.NewGrid([]bool { false, true }, []bool { false }))
box.SetLayout(layouts.Row { false, true })
box.OnMouseUp(box.handleMouseUp)
box.label.OnMouseUp(box.handleMouseUp)

View File

@ -18,12 +18,18 @@ type Grid struct {
// will contract. Boxes are laid out left to right, then top to bottom. Boxes
// that go beyond the lengh of rows will be laid out according to columns, but
// they will not expand vertically.
func NewGrid (columns, rows []bool) *Grid {
this := &Grid {
//
// If you aren't sure how to use this constructor, here is an example:
//
// X0 X1 X2 Y0 Y1 Y2
// NewGrid(true, false, true)(false, true, true)
func NewGrid (columns ...bool) func (rows ...bool) *Grid {
return func (rows ...bool) *Grid {
return &Grid {
xExpand: columns,
yExpand: rows,
}
return this
}
}
func (this *Grid) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {

View File

@ -27,7 +27,7 @@ func NewMenuItem (text string) *MenuItem {
}
box.SetRole(tomo.R("objects", "MenuItem", ""))
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
box.SetLayout(layouts.NewGrid([]bool { false, true }, []bool { true }))
box.SetLayout(layouts.Row { false, true })
box.Add(box.icon)
box.Add(box.label)

View File

@ -32,7 +32,7 @@ func NewNumberInput (value float64) *NumberInput {
box.Add(box.input)
box.Add(box.decrement)
box.Add(box.increment)
box.SetLayout(layouts.NewGrid([]bool { true, false, false }, []bool { true }))
box.SetLayout(layouts.Row { true, false, false })
box.increment.SetIcon(tomo.IconValueIncrement)
box.decrement.SetIcon(tomo.IconValueDecrement)