Update code for layouts, objects
This commit is contained in:
24
button.go
24
button.go
@@ -28,17 +28,16 @@ func NewButton (text string) *Button {
|
||||
ContainerBox: tomo.NewContainerBox(),
|
||||
label: NewLabel(text),
|
||||
}
|
||||
box.SetRole(tomo.R("objects", "Button", ""))
|
||||
box.label.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
|
||||
box.SetRole(tomo.R("objects", "Button"))
|
||||
box.label.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle))
|
||||
box.SetLayout(buttonLayout)
|
||||
box.SetText(text)
|
||||
|
||||
box.CaptureDND(true)
|
||||
box.CaptureMouse(true)
|
||||
box.CaptureScroll(true)
|
||||
box.CaptureKeyboard(true)
|
||||
box.CatchDND(true)
|
||||
box.CatchMouse(true)
|
||||
|
||||
box.OnMouseUp(box.handleMouseUp)
|
||||
box.OnButtonDown(box.handleButtonDown)
|
||||
box.OnButtonUp(box.handleButtonUp)
|
||||
box.OnKeyUp(box.handleKeyUp)
|
||||
box.SetFocusable(true)
|
||||
return box
|
||||
@@ -89,14 +88,19 @@ func (this *Button) applyLayout () {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Button) handleKeyUp (key input.Key, numberPad bool) {
|
||||
func (this *Button) handleKeyUp (catch func (), key input.Key, numberPad bool) {
|
||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||
this.on.click.Broadcast()
|
||||
}
|
||||
|
||||
func (this *Button) handleMouseUp (button input.Button) {
|
||||
func (this *Button) handleButtonDown (catch func (), button input.Button) {
|
||||
catch()
|
||||
}
|
||||
|
||||
func (this *Button) handleButtonUp (catch func (), button input.Button) {
|
||||
catch()
|
||||
if button != input.ButtonLeft { return }
|
||||
if this.MousePosition().In(this.Bounds()) {
|
||||
if this.Window().MousePosition().In(this.Bounds()) {
|
||||
this.on.click.Broadcast()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user