Dialong, Horizontal, and Vertical layouts now compile
However, they do not take into account expanding elements.
This commit is contained in:
parent
0a6858b376
commit
95b6607e4e
@ -4,6 +4,11 @@ import "image"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
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 {
|
type Dialog struct {
|
||||||
// If Gap is true, a gap will be placed between each element.
|
// If Gap is true, a gap will be placed between each element.
|
||||||
Gap bool
|
Gap bool
|
||||||
@ -39,10 +44,7 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) {
|
|||||||
mainBounds := entries[0].Bounds()
|
mainBounds := entries[0].Bounds()
|
||||||
if mainBounds.Dy() != mainHeight ||
|
if mainBounds.Dy() != mainHeight ||
|
||||||
mainBounds.Dx() != width {
|
mainBounds.Dx() != width {
|
||||||
entries[0].Handle (tomo.EventResize {
|
entries[0].Resize(width, mainHeight)
|
||||||
Width: width,
|
|
||||||
Height: mainHeight,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,10 +96,7 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) {
|
|||||||
entryBounds := entry.Bounds()
|
entryBounds := entry.Bounds()
|
||||||
if entryBounds.Dy() != controlRowHeight ||
|
if entryBounds.Dy() != controlRowHeight ||
|
||||||
entryBounds.Dx() != entryWidth {
|
entryBounds.Dx() != entryWidth {
|
||||||
entry.Handle (tomo.EventResize {
|
entry.Resize(entryWidth, controlRowHeight)
|
||||||
Width: entryWidth,
|
|
||||||
Height: 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
|
// MinimumSize returns the minimum width and height that will be needed to
|
||||||
// arrange the given list of entries.
|
// 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 {
|
if len(entries) > 0 {
|
||||||
mainChildHeight := 0
|
mainChildHeight := 0
|
||||||
width, mainChildHeight = entries[0].MinimumSize()
|
width, mainChildHeight = entries[0].MinimumSize()
|
||||||
|
@ -63,17 +63,19 @@ func (layout Horizontal) Arrange (entries []tomo.LayoutEntry, width, height int)
|
|||||||
x += entryWidth
|
x += entryWidth
|
||||||
entryBounds := entry.Bounds()
|
entryBounds := entry.Bounds()
|
||||||
if entryBounds.Dy() != height || entryBounds.Dx() != entryWidth {
|
if entryBounds.Dy() != height || entryBounds.Dx() != entryWidth {
|
||||||
entry.Handle (tomo.EventResize {
|
entry.Resize(entryWidth, height)
|
||||||
Width: entryWidth,
|
|
||||||
Height: height,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinimumSize returns the minimum width and height that will be needed to
|
// MinimumSize returns the minimum width and height that will be needed to
|
||||||
// arrange the given list of entries.
|
// 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 {
|
for index, entry := range entries {
|
||||||
entryWidth, entryHeight := entry.MinimumSize()
|
entryWidth, entryHeight := entry.MinimumSize()
|
||||||
if entryHeight > height {
|
if entryHeight > height {
|
||||||
|
@ -63,18 +63,19 @@ func (layout Vertical) Arrange (entries []tomo.LayoutEntry, width, height int) {
|
|||||||
y += entryHeight
|
y += entryHeight
|
||||||
entryBounds := entry.Bounds()
|
entryBounds := entry.Bounds()
|
||||||
if entryBounds.Dx() != width || entryBounds.Dy() != entryHeight {
|
if entryBounds.Dx() != width || entryBounds.Dy() != entryHeight {
|
||||||
// println(entryHeight)
|
entry.Resize(width, entryHeight)
|
||||||
entry.Handle (tomo.EventResize {
|
|
||||||
Width: width,
|
|
||||||
Height: entryHeight,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinimumSize returns the minimum width and height that will be needed to
|
// MinimumSize returns the minimum width and height that will be needed to
|
||||||
// arrange the given list of entries.
|
// 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 {
|
for index, entry := range entries {
|
||||||
entryWidth, entryHeight := entry.MinimumSize()
|
entryWidth, entryHeight := entry.MinimumSize()
|
||||||
if entryWidth > width {
|
if entryWidth > width {
|
||||||
|
Reference in New Issue
Block a user