Update code for layouts, objects
This commit is contained in:
24
menuitem.go
24
menuitem.go
@@ -25,19 +25,18 @@ func NewMenuItem (text string) *MenuItem {
|
||||
label: NewLabel(text),
|
||||
icon: NewIcon("", tomo.IconSizeSmall),
|
||||
}
|
||||
box.SetRole(tomo.R("objects", "MenuItem", ""))
|
||||
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
||||
box.SetRole(tomo.R("objects", "MenuItem"))
|
||||
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||
box.SetLayout(layouts.Row { false, true })
|
||||
|
||||
box.Add(box.icon)
|
||||
box.Add(box.label)
|
||||
|
||||
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
|
||||
@@ -60,14 +59,19 @@ func (this *MenuItem) OnClick (callback func ()) event.Cookie {
|
||||
return this.on.click.Connect(callback)
|
||||
}
|
||||
|
||||
func (this *MenuItem) handleKeyUp (key input.Key, numberPad bool) {
|
||||
func (this *MenuItem) handleKeyUp (catch func(), key input.Key, numberPad bool) {
|
||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||
this.on.click.Broadcast()
|
||||
}
|
||||
|
||||
func (this *MenuItem) handleMouseUp (button input.Button) {
|
||||
func (this *MenuItem) handleButtonDown (catch func(), button input.Button) {
|
||||
catch()
|
||||
}
|
||||
|
||||
func (this *MenuItem) 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