Padding and margin are now separate
This commit is contained in:
		
							parent
							
								
									6b19d66067
								
							
						
					
					
						commit
						0c5cc6ff74
					
				| @ -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 | ||||
|  | ||||
| @ -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() | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -41,4 +41,3 @@ var focusedOnListEntryPattern = artist.Padded { | ||||
| 	Fill:   uhex(0x6e8079FF), | ||||
| 	Sides:  []int { 0, 1, 0, 1 }, | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -112,14 +112,23 @@ func FontFaceBoldItalic () font.Face { | ||||
| 	return defaultfont.FaceBoldItalic | ||||
| } | ||||
| 
 | ||||
| // Padding returns how spaced out things should be on the screen. Generally, | ||||
| // text should be offset from its container on all sides by this amount. | ||||
| // Padding returns the amount of internal padding elements should have. An | ||||
| // 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 { | ||||
| 	return 7 | ||||
| } | ||||
| 
 | ||||
| // Margin returns how much space should be put in between elements. | ||||
| func Margin () int { | ||||
| 	return 8 | ||||
| } | ||||
| 
 | ||||
| // HandleWidth returns how large grab handles should typically be. This is | ||||
| // important for accessibility reasons. | ||||
| func HandleWidth () int { | ||||
| 	return Padding() * 2 | ||||
| 	return 16 | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user