List relies more on the bounds insetting from theme
This commit is contained in:
parent
92aeb48a1f
commit
44b9a1e717
@ -165,7 +165,7 @@ func (element *List) ScrollAxes () (horizontal, vertical bool) {
|
||||
|
||||
func (element *List) scrollViewportHeight () (height int) {
|
||||
_, inset := theme.ListPattern(theme.PatternState { })
|
||||
return element.Bounds().Dy() - theme.Padding() - inset[0] - inset[2]
|
||||
return element.Bounds().Dy() - inset[0] - inset[2]
|
||||
}
|
||||
|
||||
func (element *List) maxScrollHeight () (height int) {
|
||||
@ -288,11 +288,12 @@ func (element *List) Replace (index int, entry ListEntry) {
|
||||
}
|
||||
|
||||
func (element *List) selectUnderMouse (x, y int) (updated bool) {
|
||||
bounds := element.Bounds()
|
||||
_, inset := theme.ListPattern(theme.PatternState { })
|
||||
bounds := inset.Apply(element.Bounds())
|
||||
mousePoint := image.Pt(x, y)
|
||||
dot := image.Pt (
|
||||
bounds.Min.X + theme.Padding() / 2,
|
||||
bounds.Min.Y - element.scroll + theme.Padding() / 2)
|
||||
bounds.Min.X,
|
||||
bounds.Min.Y - element.scroll)
|
||||
|
||||
newlySelectedEntryIndex := -1
|
||||
for index, entry := range element.entries {
|
||||
@ -344,7 +345,6 @@ func (element *List) updateMinimumSize () {
|
||||
minimumHeight := element.forcedMinimumHeight
|
||||
|
||||
if minimumWidth == 0 {
|
||||
minimumWidth = theme.Padding()
|
||||
for _, entry := range element.entries {
|
||||
entryWidth := entry.Bounds().Dx()
|
||||
if entryWidth > minimumWidth {
|
||||
@ -354,10 +354,9 @@ func (element *List) updateMinimumSize () {
|
||||
}
|
||||
|
||||
if minimumHeight == 0 {
|
||||
minimumHeight = element.contentHeight + theme.Padding()
|
||||
minimumHeight = element.contentHeight
|
||||
}
|
||||
|
||||
|
||||
_, inset := theme.ListPattern(theme.PatternState { })
|
||||
minimumWidth += inset[1] + inset[3]
|
||||
minimumHeight += inset[0] + inset[2]
|
||||
@ -377,7 +376,7 @@ func (element *List) draw () {
|
||||
bounds = inset.Apply(bounds)
|
||||
dot := image.Point {
|
||||
bounds.Min.X,
|
||||
bounds.Min.Y - element.scroll + theme.Padding() / 2,
|
||||
bounds.Min.Y - element.scroll,
|
||||
}
|
||||
for index, entry := range element.entries {
|
||||
entryPosition := dot
|
||||
|
@ -33,22 +33,19 @@ func (entry *ListEntry) Collapse (width int) {
|
||||
}
|
||||
|
||||
func (entry *ListEntry) updateBounds () {
|
||||
padding := theme.Padding()
|
||||
|
||||
entry.bounds = image.Rectangle { }
|
||||
entry.bounds.Max.Y = entry.drawer.LineHeight().Round() + padding
|
||||
entry.bounds.Max.Y = entry.drawer.LineHeight().Round()
|
||||
if entry.forcedMinimumWidth > 0 {
|
||||
entry.bounds.Max.X = entry.forcedMinimumWidth
|
||||
} else {
|
||||
entry.bounds.Max.X =
|
||||
entry.drawer.LayoutBounds().Dx() + padding * 2
|
||||
entry.bounds.Max.X = entry.drawer.LayoutBounds().Dx()
|
||||
}
|
||||
|
||||
_, inset := theme.ItemPattern(theme.PatternState { })
|
||||
entry.bounds.Max.Y += inset[0] + inset[2]
|
||||
|
||||
entry.textPoint =
|
||||
image.Pt(inset[3] + padding, inset[0] + padding / 2).
|
||||
image.Pt(inset[3], inset[0]).
|
||||
Sub(entry.drawer.LayoutBounds().Min)
|
||||
}
|
||||
|
||||
|
@ -119,18 +119,18 @@ func InputPattern (state PatternState) (pattern artist.Pattern, inset Inset) {
|
||||
// ListPattern returns a background pattern for a list of things.
|
||||
func ListPattern (state PatternState) (pattern artist.Pattern, inset Inset) {
|
||||
if state.Selected {
|
||||
return selectedListPattern, Inset { }
|
||||
return selectedListPattern, Inset { 4, 0, 4, 0 }
|
||||
} else {
|
||||
return listPattern, Inset { }
|
||||
return listPattern, Inset { 4, 0, 4, 0 }
|
||||
}
|
||||
}
|
||||
|
||||
// ItemPattern returns a background pattern for a list item.
|
||||
func ItemPattern (state PatternState) (pattern artist.Pattern, inset Inset) {
|
||||
if state.On {
|
||||
return selectedListEntryPattern, Inset { 1, 1, 1, 1 }
|
||||
return selectedListEntryPattern, Inset { 4, 8, 4, 8 }
|
||||
} else {
|
||||
return listEntryPattern, Inset { 1, 1, 1, 1 }
|
||||
return listEntryPattern, Inset { 4, 8, 4, 8 }
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user