From e8a3a376ea5a05f2af4bbc2f8454b7fa2cf8b844 Mon Sep 17 00:00:00 2001 From: "sashakoshka@tebibyte.media" Date: Sat, 22 Jun 2024 18:44:26 -0400 Subject: [PATCH] Introduce new layouts.Grid construct --- calendar.go | 3 +-- dialog.go | 2 +- labelcheckbox.go | 2 +- labelswatch.go | 2 +- layouts/grid.go | 16 +++++++++++----- menuitem.go | 2 +- numberinput.go | 2 +- 7 files changed, 17 insertions(+), 12 deletions(-) diff --git a/calendar.go b/calendar.go index 06aff74..4f09dff 100644 --- a/calendar.go +++ b/calendar.go @@ -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)) diff --git a/dialog.go b/dialog.go index 448c038..ff4ee2e 100644 --- a/dialog.go +++ b/dialog.go @@ -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 diff --git a/labelcheckbox.go b/labelcheckbox.go index 85d4d8b..1c63c6c 100644 --- a/labelcheckbox.go +++ b/labelcheckbox.go @@ -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) diff --git a/labelswatch.go b/labelswatch.go index b7fdab2..e882a65 100644 --- a/labelswatch.go +++ b/labelswatch.go @@ -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) diff --git a/layouts/grid.go b/layouts/grid.go index 5c423ff..4420482 100644 --- a/layouts/grid.go +++ b/layouts/grid.go @@ -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 { - xExpand: columns, - yExpand: rows, +// +// 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 { diff --git a/menuitem.go b/menuitem.go index 913069d..c6cda2f 100644 --- a/menuitem.go +++ b/menuitem.go @@ -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) diff --git a/numberinput.go b/numberinput.go index 1ec3d89..61d6c4f 100644 --- a/numberinput.go +++ b/numberinput.go @@ -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)