Added a list example
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -28,22 +28,23 @@ func NewMouse () (element *Mouse) {
|
||||
|
||||
func (element *Mouse) Resize (width, height int) {
|
||||
element.core.AllocateCanvas(width, height)
|
||||
bounds := element.Bounds()
|
||||
artist.FillRectangle (
|
||||
element.core,
|
||||
theme.AccentPattern(),
|
||||
element.Bounds())
|
||||
bounds)
|
||||
artist.StrokeRectangle (
|
||||
element.core,
|
||||
artist.NewUniform(color.Black), 1,
|
||||
element.Bounds())
|
||||
artist.Line (
|
||||
element.core, artist.NewUniform(color.White), 3,
|
||||
image.Pt(1, 1),
|
||||
image.Pt(width - 2, height - 2))
|
||||
bounds)
|
||||
artist.Line (
|
||||
element.core, artist.NewUniform(color.White), 1,
|
||||
image.Pt(1, height - 2),
|
||||
image.Pt(width - 2, 1))
|
||||
image.Pt(1, 1),
|
||||
image.Pt(bounds.Dx() - 2, bounds.Dy() - 2))
|
||||
artist.Line (
|
||||
element.core, artist.NewUniform(color.White), 1,
|
||||
image.Pt(1, bounds.Dy() - 2),
|
||||
image.Pt(bounds.Dx() - 2, 1))
|
||||
}
|
||||
|
||||
func (element *Mouse) HandleMouseDown (x, y int, button tomo.Button) {
|
||||
|
||||
Reference in New Issue
Block a user