Added a list example

This commit is contained in:
Sasha Koshka
2023-01-24 16:41:12 -05:00
parent 68f1d052d2
commit 5edfbf8110
5 changed files with 83 additions and 12 deletions

View File

@@ -359,6 +359,9 @@ func (element *List) selectUnderMouse (x, y int) (updated bool) {
if element.onSelectedEntryChange != nil {
element.onSelectedEntryChange(element.selectedEntry)
}
if element.selectedEntry >= 0 {
element.entries[element.selectedEntry].RunSelect()
}
return true
}

View File

@@ -12,13 +12,13 @@ type ListEntry struct {
textPoint image.Point
text string
forcedMinimumWidth int
onClick func ()
onSelect func ()
}
func NewListEntry (text string, onClick func ()) (entry ListEntry) {
func NewListEntry (text string, onSelect func ()) (entry ListEntry) {
entry = ListEntry {
text: text,
onClick: onClick,
text: text,
onSelect: onSelect,
}
entry.drawer.SetText([]rune(text))
entry.drawer.SetFace(theme.FontFaceRegular())
@@ -62,6 +62,12 @@ func (entry *ListEntry) Draw (
offset.Add(entry.textPoint))
}
func (entry *ListEntry) RunSelect () {
if entry.onSelect != nil {
entry.onSelect()
}
}
func (entry *ListEntry) Bounds () (bounds image.Rectangle) {
return entry.bounds
}