Commented button
This commit is contained in:
parent
b5469e103d
commit
4f8f80f142
@ -6,6 +6,7 @@ import "git.tebibyte.media/sashakoshka/tomo/theme"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||||
|
|
||||||
|
// Button is a clickable button.
|
||||||
type Button struct {
|
type Button struct {
|
||||||
*core.Core
|
*core.Core
|
||||||
core core.CoreControl
|
core core.CoreControl
|
||||||
@ -18,6 +19,7 @@ type Button struct {
|
|||||||
drawer artist.TextDrawer
|
drawer artist.TextDrawer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewButton creates a new button with the specified label text.
|
||||||
func NewButton (text string) (element *Button) {
|
func NewButton (text string) (element *Button) {
|
||||||
element = &Button { enabled: true }
|
element = &Button { enabled: true }
|
||||||
element.Core, element.core = core.NewCore(element)
|
element.Core, element.core = core.NewCore(element)
|
||||||
@ -27,6 +29,7 @@ func NewButton (text string) (element *Button) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle handles an event.
|
||||||
func (element *Button) Handle (event tomo.Event) {
|
func (element *Button) Handle (event tomo.Event) {
|
||||||
switch event.(type) {
|
switch event.(type) {
|
||||||
case tomo.EventResize:
|
case tomo.EventResize:
|
||||||
@ -106,14 +109,18 @@ func (element *Button) Handle (event tomo.Event) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnClick sets the function to be called when the button is clicked.
|
||||||
func (element *Button) OnClick (callback func ()) {
|
func (element *Button) OnClick (callback func ()) {
|
||||||
element.onClick = callback
|
element.onClick = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select requests that this button's parent container send it a selection
|
||||||
|
// event.
|
||||||
func (element *Button) Select () {
|
func (element *Button) Select () {
|
||||||
element.core.Select()
|
element.core.Select()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetEnabled sets whether this button can be clicked or not.
|
||||||
func (element *Button) SetEnabled (enabled bool) {
|
func (element *Button) SetEnabled (enabled bool) {
|
||||||
if element.enabled == enabled { return }
|
if element.enabled == enabled { return }
|
||||||
element.enabled = enabled
|
element.enabled = enabled
|
||||||
@ -124,6 +131,7 @@ func (element *Button) SetEnabled (enabled bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetText sets the button's label text.
|
||||||
func (element *Button) SetText (text string) {
|
func (element *Button) SetText (text string) {
|
||||||
if element.text == text { return }
|
if element.text == text { return }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user