I forgor
This commit is contained in:
12
button.go
12
button.go
@@ -14,11 +14,14 @@ type Button struct {
|
||||
}
|
||||
|
||||
// NewButton creates a new button with the specified text.
|
||||
func NewButton (text string) Button {
|
||||
box := Button { TextBox: tomo.NewTextBox() }
|
||||
func NewButton (text string) *Button {
|
||||
box := &Button { TextBox: tomo.NewTextBox() }
|
||||
theme.Apply(box, theme.R("objects", "Button"))
|
||||
box.SetText(text)
|
||||
box.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
|
||||
box.OnMouseUp(box.handleMouseUp)
|
||||
box.OnKeyUp(box.handleKeyUp)
|
||||
box.SetFocusable(true)
|
||||
return box
|
||||
}
|
||||
|
||||
@@ -27,6 +30,11 @@ func (this *Button) OnClick (callback func ()) event.Cookie {
|
||||
return this.on.click.Connect(callback)
|
||||
}
|
||||
|
||||
func (this *Button) handleKeyUp (key input.Key, numberPad bool) {
|
||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||
this.on.click.Broadcast()
|
||||
}
|
||||
|
||||
func (this *Button) handleMouseUp (button input.Button) {
|
||||
if button != input.ButtonLeft { return }
|
||||
if this.MousePosition().In(this.Bounds()) {
|
||||
|
||||
Reference in New Issue
Block a user