From faf5ebb28314b85ac5f012f63d2ab4ab241f1eef Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 20 Mar 2023 01:57:06 -0400 Subject: [PATCH] List can now add multiple entries at once, and clear all of them --- elements/basic/list.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/elements/basic/list.go b/elements/basic/list.go index e8801bd..704f1f0 100644 --- a/elements/basic/list.go +++ b/elements/basic/list.go @@ -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) {