From 95b6607e4e093d598e6d74b6853a1ded2432cca7 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 16 Jan 2023 00:09:01 -0500 Subject: [PATCH] Dialong, Horizontal, and Vertical layouts now compile However, they do not take into account expanding elements. --- layouts/dialog.go | 22 +++++++++++++--------- layouts/horizontal.go | 12 +++++++----- layouts/vertical.go | 13 +++++++------ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/layouts/dialog.go b/layouts/dialog.go index e166cb1..f7915b9 100644 --- a/layouts/dialog.go +++ b/layouts/dialog.go @@ -4,6 +4,11 @@ import "image" import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo/theme" +// Dialog arranges elements in the form of a dialog box. The first element is +// positioned above as the main focus of the dialog, and is set to expand +// regardless of whether it is expanding or not. The remaining elements are +// arranged at the bottom in a row called the control row, which is aligned to +// the right, the last element being the rightmost one. type Dialog struct { // If Gap is true, a gap will be placed between each element. Gap bool @@ -39,10 +44,7 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) { mainBounds := entries[0].Bounds() if mainBounds.Dy() != mainHeight || mainBounds.Dx() != width { - entries[0].Handle (tomo.EventResize { - Width: width, - Height: mainHeight, - }) + entries[0].Resize(width, mainHeight) } } @@ -94,10 +96,7 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) { entryBounds := entry.Bounds() if entryBounds.Dy() != controlRowHeight || entryBounds.Dx() != entryWidth { - entry.Handle (tomo.EventResize { - Width: entryWidth, - Height: controlRowHeight, - }) + entry.Resize(entryWidth, controlRowHeight) } } } @@ -107,7 +106,12 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) { // MinimumSize returns the minimum width and height that will be needed to // arrange the given list of entries. -func (layout Dialog) MinimumSize (entries []tomo.LayoutEntry) (width, height int) { +func (layout Dialog) MinimumSize ( + entries []tomo.LayoutEntry, + squeeze int, +) ( + width, height int, +) { if len(entries) > 0 { mainChildHeight := 0 width, mainChildHeight = entries[0].MinimumSize() diff --git a/layouts/horizontal.go b/layouts/horizontal.go index 0f08a24..5ca5000 100644 --- a/layouts/horizontal.go +++ b/layouts/horizontal.go @@ -63,17 +63,19 @@ func (layout Horizontal) Arrange (entries []tomo.LayoutEntry, width, height int) x += entryWidth entryBounds := entry.Bounds() if entryBounds.Dy() != height || entryBounds.Dx() != entryWidth { - entry.Handle (tomo.EventResize { - Width: entryWidth, - Height: height, - }) + entry.Resize(entryWidth, height) } } } // MinimumSize returns the minimum width and height that will be needed to // arrange the given list of entries. -func (layout Horizontal) MinimumSize (entries []tomo.LayoutEntry) (width, height int) { +func (layout Horizontal) MinimumSize ( + entries []tomo.LayoutEntry, + squeeze int, +) ( + width, height int, +) { for index, entry := range entries { entryWidth, entryHeight := entry.MinimumSize() if entryHeight > height { diff --git a/layouts/vertical.go b/layouts/vertical.go index 971729c..c366419 100644 --- a/layouts/vertical.go +++ b/layouts/vertical.go @@ -63,18 +63,19 @@ func (layout Vertical) Arrange (entries []tomo.LayoutEntry, width, height int) { y += entryHeight entryBounds := entry.Bounds() if entryBounds.Dx() != width || entryBounds.Dy() != entryHeight { - // println(entryHeight) - entry.Handle (tomo.EventResize { - Width: width, - Height: entryHeight, - }) + entry.Resize(width, entryHeight) } } } // MinimumSize returns the minimum width and height that will be needed to // arrange the given list of entries. -func (layout Vertical) MinimumSize (entries []tomo.LayoutEntry) (width, height int) { +func (layout Vertical) MinimumSize ( + entries []tomo.LayoutEntry, + squeeze int, +) ( + width, height int, +) { for index, entry := range entries { entryWidth, entryHeight := entry.MinimumSize() if entryWidth > width {