Added a selectability core to reduce complexity of selectables
This commit is contained in:
parent
b2b2a80a06
commit
9422ff6198
@ -9,24 +9,28 @@ import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
|||||||
// Button is a clickable button.
|
// Button is a clickable button.
|
||||||
type Button struct {
|
type Button struct {
|
||||||
*core.Core
|
*core.Core
|
||||||
|
*core.SelectableCore
|
||||||
core core.CoreControl
|
core core.CoreControl
|
||||||
|
selectableControl core.SelectableCoreControl
|
||||||
pressed bool
|
|
||||||
enabled bool
|
|
||||||
selected bool
|
|
||||||
|
|
||||||
text string
|
|
||||||
drawer artist.TextDrawer
|
drawer artist.TextDrawer
|
||||||
|
|
||||||
|
pressed bool
|
||||||
|
text string
|
||||||
|
|
||||||
onClick func ()
|
onClick func ()
|
||||||
onSelectionRequest func () (granted bool)
|
|
||||||
onSelectionMotionRequest func (tomo.SelectionDirection) (granted bool)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewButton creates a new button with the specified label text.
|
// 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 { }
|
||||||
element.Core, element.core = core.NewCore(element)
|
element.Core, element.core = core.NewCore(element)
|
||||||
|
element.SelectableCore,
|
||||||
|
element.selectableControl = core.NewSelectableCore (func () {
|
||||||
|
if element.core.HasImage () {
|
||||||
|
element.draw()
|
||||||
|
element.core.DamageAll()
|
||||||
|
}
|
||||||
|
})
|
||||||
element.drawer.SetFace(theme.FontFaceRegular())
|
element.drawer.SetFace(theme.FontFaceRegular())
|
||||||
element.SetText(text)
|
element.SetText(text)
|
||||||
return
|
return
|
||||||