Padding and margin are now separate

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

View File

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

View File

@ -41,4 +41,3 @@ var focusedOnListEntryPattern = artist.Padded {
Fill: uhex(0x6e8079FF), Fill: uhex(0x6e8079FF),
Sides: []int { 0, 1, 0, 1 }, Sides: []int { 0, 1, 0, 1 },
} }

View File

@ -112,14 +112,23 @@ func FontFaceBoldItalic () font.Face {
return defaultfont.FaceBoldItalic return defaultfont.FaceBoldItalic
} }
// Padding returns how spaced out things should be on the screen. Generally, // Padding returns the amount of internal padding elements should have. An
// text should be offset from its container on all sides by this amount. // element's inner content (such as text) should be inset by this amount,
// in addition to the inset returned by the pattern of its background. When
// using the aforementioned inset values to calculate the element's minimum size
// or the position and alignment of its content, all parameters in the
// PatternState should be unset except for Case.
func Padding () int { func Padding () int {
return 7
}
// Margin returns how much space should be put in between elements.
func Margin () int {
return 8 return 8
} }
// HandleWidth returns how large grab handles should typically be. This is // HandleWidth returns how large grab handles should typically be. This is
// important for accessibility reasons. // important for accessibility reasons.
func HandleWidth () int { func HandleWidth () int {
return Padding() * 2 return 16
} }