The list element calls the scroll bounds change callback

This commit is contained in:
Sasha Koshka 2023-03-17 01:58:42 -04:00
parent 493c5210a7
commit d651570746
2 changed files with 17 additions and 22 deletions

View File

@ -65,9 +65,7 @@ func (element *List) handleResize () {
element.scroll = element.maxScrollHeight() element.scroll = element.maxScrollHeight()
} }
element.draw() element.draw()
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok { element.scrollBoundsChange()
parent.NotifyScrollBoundsChange(element)
}
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
@ -103,9 +101,7 @@ func (element *List) redo () {
element.draw() element.draw()
element.core.DamageAll() element.core.DamageAll()
} }
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok { element.scrollBoundsChange()
parent.NotifyScrollBoundsChange(element)
}
} }
// Collapse forces a minimum width and height upon the list. If a zero value is // Collapse forces a minimum width and height upon the list. If a zero value is
@ -209,9 +205,7 @@ func (element *List) ScrollTo (position image.Point) {
element.draw() element.draw()
element.core.DamageAll() element.core.DamageAll()
} }
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok { element.scrollBoundsChange()
parent.NotifyScrollBoundsChange(element)
}
} }
// ScrollAxes returns the supported axes for scrolling. // ScrollAxes returns the supported axes for scrolling.
@ -264,9 +258,7 @@ func (element *List) Append (entry ListEntry) {
element.draw() element.draw()
element.core.DamageAll() element.core.DamageAll()
} }
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok { element.scrollBoundsChange()
parent.NotifyScrollBoundsChange(element)
}
} }
// EntryAt returns the entry at the specified index. If the index is out of // EntryAt returns the entry at the specified index. If the index is out of
@ -297,9 +289,7 @@ func (element *List) Insert (index int, entry ListEntry) {
element.draw() element.draw()
element.core.DamageAll() element.core.DamageAll()
} }
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok { element.scrollBoundsChange()
parent.NotifyScrollBoundsChange(element)
}
} }
// Remove removes the entry at the specified index. If the index is out of // Remove removes the entry at the specified index. If the index is out of
@ -320,9 +310,7 @@ func (element *List) Remove (index int) {
element.draw() element.draw()
element.core.DamageAll() element.core.DamageAll()
} }
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok { element.scrollBoundsChange()
parent.NotifyScrollBoundsChange(element)
}
} }
// Replace replaces the entry at the specified index with another. If the index // Replace replaces the entry at the specified index with another. If the index
@ -342,9 +330,7 @@ func (element *List) Replace (index int, entry ListEntry) {
element.draw() element.draw()
element.core.DamageAll() element.core.DamageAll()
} }
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok { element.scrollBoundsChange()
parent.NotifyScrollBoundsChange(element)
}
} }
// Select selects a specific item in the list. If the index is out of bounds, // Select selects a specific item in the list. If the index is out of bounds,
@ -432,6 +418,15 @@ func (element *List) updateMinimumSize () {
element.core.SetMinimumSize(minimumWidth, minimumHeight) element.core.SetMinimumSize(minimumWidth, minimumHeight)
} }
func (element *List) scrollBoundsChange () {
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok {
parent.NotifyScrollBoundsChange(element)
}
if element.onScrollBoundsChange != nil {
element.onScrollBoundsChange()
}
}
func (element *List) draw () { func (element *List) draw () {
bounds := element.Bounds() bounds := element.Bounds()
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(theme.PatternSunken)

View File

@ -12,7 +12,7 @@ func main () {
} }
func run () { func run () {
window, _ := tomo.NewWindow(480, 360) window, _ := tomo.NewWindow(360, 240)
window.SetTitle("Scroll") window.SetTitle("Scroll")
container := containers.NewContainer(basicLayouts.Vertical { true, true }) container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container) window.Adopt(container)