Padding and margin are now separate

This commit is contained in:
2023-01-30 18:22:19 -05:00
parent 6b19d66067
commit 0c5cc6ff74
5 changed files with 54 additions and 46 deletions

View File

@@ -21,8 +21,8 @@ type Dialog struct {
// Arrange arranges a list of entries into a dialog.
func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) {
if layout.Pad {
width -= theme.Padding() * 2
height -= theme.Padding() * 2
width -= theme.Margin() * 2
height -= theme.Margin() * 2
}
controlRowWidth, controlRowHeight := 0, 0
@@ -34,12 +34,12 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) {
if len(entries) > 0 {
entries[0].Position = image.Point { }
if layout.Pad {
entries[0].Position.X += theme.Padding()
entries[0].Position.Y += theme.Padding()
entries[0].Position.X += theme.Margin()
entries[0].Position.Y += theme.Margin()
}
mainHeight := height - controlRowHeight
if layout.Gap {
mainHeight -= theme.Padding()
mainHeight -= theme.Margin()
}
mainBounds := entries[0].Bounds()
if mainBounds.Dy() != mainHeight ||
@@ -62,7 +62,7 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) {
freeSpace -= entryMinWidth
}
if index > 0 && layout.Gap {
freeSpace -= theme.Padding()
freeSpace -= theme.Margin()
}
}
expandingElementWidth := 0
@@ -76,14 +76,14 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) {
x = width - controlRowWidth
}
if layout.Pad {
x += theme.Padding()
y += theme.Padding()
x += theme.Margin()
y += theme.Margin()
}
height -= controlRowHeight
// set the size and position of each element in the control row
for index, entry := range entries[1:] {
if index > 0 && layout.Gap { x += theme.Padding() }
if index > 0 && layout.Gap { x += theme.Margin() }
entries[index + 1].Position = image.Pt(x, y)
entryWidth := 0
@@ -118,7 +118,7 @@ func (layout Dialog) MinimumSize (
}
if len(entries) > 1 {
if layout.Gap { height += theme.Padding() }
if layout.Gap { height += theme.Margin() }
additionalWidth,
additionalHeight := layout.minimumSizeOfControlRow(entries[1:])
height += additionalHeight
@@ -128,8 +128,8 @@ func (layout Dialog) MinimumSize (
}
if layout.Pad {
width += theme.Padding() * 2
height += theme.Padding() * 2
width += theme.Margin() * 2
height += theme.Margin() * 2
}
return
}
@@ -143,7 +143,7 @@ func (layout Dialog) FlexibleHeightFor (
height int,
) {
if layout.Pad {
width -= theme.Padding() * 2
width -= theme.Margin() * 2
}
if len(entries) > 0 {
@@ -157,13 +157,13 @@ func (layout Dialog) FlexibleHeightFor (
}
if len(entries) > 1 {
if layout.Gap { height += theme.Padding() }
if layout.Gap { height += theme.Margin() }
_, additionalHeight := layout.minimumSizeOfControlRow(entries[1:])
height += additionalHeight
}
if layout.Pad {
height += theme.Padding() * 2
height += theme.Margin() * 2
}
return
}
@@ -182,7 +182,7 @@ func (layout Dialog) minimumSizeOfControlRow (
}
width += entryWidth
if layout.Gap && index > 0 {
width += theme.Padding()
width += theme.Margin()
}
}
return

View File

@@ -19,21 +19,21 @@ type Horizontal struct {
// Arrange arranges a list of entries horizontally.
func (layout Horizontal) Arrange (entries []tomo.LayoutEntry, width, height int) {
if layout.Pad {
width -= theme.Padding() * 2
height -= theme.Padding() * 2
width -= theme.Margin() * 2
height -= theme.Margin() * 2
}
// get width of expanding elements
expandingElementWidth := layout.expandingElementWidth(entries, width)
x, y := 0, 0
if layout.Pad {
x += theme.Padding()
y += theme.Padding()
x += theme.Margin()
y += theme.Margin()
}
// set the size and position of each element
for index, entry := range entries {
if index > 0 && layout.Gap { x += theme.Padding() }
if index > 0 && layout.Gap { x += theme.Margin() }
entries[index].Position = image.Pt(x, y)
entryWidth := 0
@@ -64,13 +64,13 @@ func (layout Horizontal) MinimumSize (
}
width += entryWidth
if layout.Gap && index > 0 {
width += theme.Padding()
width += theme.Margin()
}
}
if layout.Pad {
width += theme.Padding() * 2
height += theme.Padding() * 2
width += theme.Margin() * 2
height += theme.Margin() * 2
}
return
}
@@ -84,15 +84,15 @@ func (layout Horizontal) FlexibleHeightFor (
height int,
) {
if layout.Pad {
width -= theme.Padding() * 2
width -= theme.Margin() * 2
}
// get width of expanding elements
expandingElementWidth := layout.expandingElementWidth(entries, width)
x, y := 0, 0
if layout.Pad {
x += theme.Padding()
y += theme.Padding()
x += theme.Margin()
y += theme.Margin()
}
// set the size and position of each element
@@ -107,11 +107,11 @@ func (layout Horizontal) FlexibleHeightFor (
if entryHeight > height { height = entryHeight }
x += entryWidth
if index > 0 && layout.Gap { x += theme.Padding() }
if index > 0 && layout.Gap { x += theme.Margin() }
}
if layout.Pad {
height += theme.Padding() * 2
height += theme.Margin() * 2
}
return
}
@@ -134,7 +134,7 @@ func (layout Horizontal) expandingElementWidth (
freeSpace -= entryMinWidth
}
if index > 0 && layout.Gap {
freeSpace -= theme.Padding()
freeSpace -= theme.Margin()
}
}

View File

@@ -19,8 +19,8 @@ type Vertical struct {
// Arrange arranges a list of entries vertically.
func (layout Vertical) Arrange (entries []tomo.LayoutEntry, width, height int) {
if layout.Pad {
width -= theme.Padding() * 2
height -= theme.Padding() * 2
width -= theme.Margin() * 2
height -= theme.Margin() * 2
}
freeSpace := height
expandingElements := 0
@@ -44,7 +44,7 @@ func (layout Vertical) Arrange (entries []tomo.LayoutEntry, width, height int) {
freeSpace -= entryMinHeight
}
if index > 0 && layout.Gap {
freeSpace -= theme.Padding()
freeSpace -= theme.Margin()
}
}
expandingElementHeight := 0
@@ -54,13 +54,13 @@ func (layout Vertical) Arrange (entries []tomo.LayoutEntry, width, height int) {
x, y := 0, 0
if layout.Pad {
x += theme.Padding()
y += theme.Padding()
x += theme.Margin()
y += theme.Margin()
}
// set the size and position of each element
for index, entry := range entries {
if index > 0 && layout.Gap { y += theme.Padding() }
if index > 0 && layout.Gap { y += theme.Margin() }
entries[index].Position = image.Pt(x, y)
entryHeight := 0
@@ -91,13 +91,13 @@ func (layout Vertical) MinimumSize (
}
height += entryHeight
if layout.Gap && index > 0 {
height += theme.Padding()
height += theme.Margin()
}
}
if layout.Pad {
width += theme.Padding() * 2
height += theme.Padding() * 2
width += theme.Margin() * 2
height += theme.Margin() * 2
}
return
}
@@ -111,8 +111,8 @@ func (layout Vertical) FlexibleHeightFor (
height int,
) {
if layout.Pad {
width -= theme.Padding() * 2
height += theme.Padding() * 2
width -= theme.Margin() * 2
height += theme.Margin() * 2
}
for index, entry := range entries {
@@ -125,7 +125,7 @@ func (layout Vertical) FlexibleHeightFor (
}
if layout.Gap && index > 0 {
height += theme.Padding()
height += theme.Margin()
}
}
return