List can now add multiple entries at once, and clear all of them

This commit is contained in:
Sasha Koshka 2023-03-20 01:57:06 -04:00
parent f37101eb9e
commit faf5ebb283
1 changed files with 22 additions and 6 deletions

View File

@ -244,13 +244,16 @@ func (element *List) CountEntries () (count int) {
return len(element.entries)
}
// Append adds an entry to the end of the list.
func (element *List) Append (entry ListEntry) {
// Append adds one or more entries to the end of the list.
func (element *List) Append (entries ...ListEntry) {
// append
entry = element.resizeEntryToFit(entry)
entry.SetTheme(element.theme.Theme)
entry.SetConfig(element.config)
element.entries = append(element.entries, entry)
for index, entry := range entries {
entry = element.resizeEntryToFit(entry)
entry.SetTheme(element.theme.Theme)
entry.SetConfig(element.config)
entries[index] = entry
}
element.entries = append(element.entries, entries...)
// recalculate, redraw, notify
element.updateMinimumSize()
@ -313,6 +316,19 @@ func (element *List) Remove (index int) {
element.scrollBoundsChange()
}
// Clear removes all entries from the list.
func (element *List) Clear () {
element.entries = nil
// recalculate, redraw, notify
element.updateMinimumSize()
if element.core.HasImage() {
element.draw()
element.core.DamageAll()
}
element.scrollBoundsChange()
}
// Replace replaces the entry at the specified index with another. If the index
// is out of bounds, it panics.
func (element *List) Replace (index int, entry ListEntry) {