Update code for objects
This commit is contained in:
34
button.go
34
button.go
@@ -30,14 +30,13 @@ func NewButton (text string) *Button {
|
||||
}
|
||||
box.SetRole(tomo.R("objects", "Button"))
|
||||
box.label.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle))
|
||||
box.SetLayout(buttonLayout)
|
||||
box.SetAttr(tomo.ALayout(buttonLayout))
|
||||
box.SetText(text)
|
||||
|
||||
box.CatchDND(true)
|
||||
box.CatchMouse(true)
|
||||
|
||||
box.SetInputMask(true)
|
||||
box.OnButtonDown(box.handleButtonDown)
|
||||
box.OnButtonUp(box.handleButtonUp)
|
||||
box.OnKeyDown(box.handleKeyDown)
|
||||
box.OnKeyUp(box.handleKeyUp)
|
||||
box.SetFocusable(true)
|
||||
return box
|
||||
@@ -80,27 +79,34 @@ func (this *Button) OnClick (callback func ()) event.Cookie {
|
||||
|
||||
func (this *Button) applyLayout () {
|
||||
if this.labelActive && this.icon == nil {
|
||||
this.SetLayout(buttonLayout)
|
||||
this.SetAttr(tomo.ALayout(buttonLayout))
|
||||
} else if !this.labelActive && this.icon != nil {
|
||||
this.SetLayout(iconButtonLayout)
|
||||
this.SetAttr(tomo.ALayout(iconButtonLayout))
|
||||
} else {
|
||||
this.SetLayout(bothButtonLayout)
|
||||
this.SetAttr(tomo.ALayout(bothButtonLayout))
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Button) handleKeyUp (catch func (), key input.Key, numberPad bool) {
|
||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||
func (this *Button) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *Button) handleKeyUp (key input.Key, numberPad bool) bool {
|
||||
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||
this.on.click.Broadcast()
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *Button) handleButtonDown (catch func (), button input.Button) {
|
||||
catch()
|
||||
func (this *Button) handleButtonDown (button input.Button) bool {
|
||||
if button != input.ButtonLeft { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *Button) handleButtonUp (catch func (), button input.Button) {
|
||||
catch()
|
||||
if button != input.ButtonLeft { return }
|
||||
func (this *Button) handleButtonUp (button input.Button) bool {
|
||||
if button != input.ButtonLeft { return false }
|
||||
if this.Window().MousePosition().In(this.Bounds()) {
|
||||
this.on.click.Broadcast()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user