atomize-element-interface #2

Merged
sashakoshka merged 20 commits from atomize-element-interface into main 2023-01-16 17:24:23 +00:00
3 changed files with 27 additions and 20 deletions
Showing only changes of commit 95b6607e4e - Show all commits

View File

@ -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()

View File

@ -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 {

View File

@ -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 {