MenuItem no longer embeds tomo.ContainerBox
This commit is contained in:
parent
6f8d5cc426
commit
ae74c3dbf4
58
menuitem.go
58
menuitem.go
@ -5,12 +5,14 @@ import "git.tebibyte.media/tomo/tomo/input"
|
|||||||
import "git.tebibyte.media/tomo/tomo/event"
|
import "git.tebibyte.media/tomo/tomo/event"
|
||||||
import "git.tebibyte.media/tomo/objects/layouts"
|
import "git.tebibyte.media/tomo/objects/layouts"
|
||||||
|
|
||||||
|
var _ tomo.Object = new(MenuItem)
|
||||||
|
|
||||||
// MenuItem is a selectable memu item.
|
// MenuItem is a selectable memu item.
|
||||||
type MenuItem struct {
|
type MenuItem struct {
|
||||||
tomo.ContainerBox
|
box tomo.ContainerBox
|
||||||
|
|
||||||
label *Label
|
label *Label
|
||||||
icon *Icon
|
icon *Icon
|
||||||
labelActive bool
|
labelActive bool
|
||||||
|
|
||||||
on struct {
|
on struct {
|
||||||
@ -25,27 +27,39 @@ func NewMenuItem (text string) *MenuItem {
|
|||||||
|
|
||||||
// NewIconMenuItem creates a new menu item with the specified icon and text.
|
// NewIconMenuItem creates a new menu item with the specified icon and text.
|
||||||
func NewIconMenuItem (icon tomo.Icon, text string) *MenuItem {
|
func NewIconMenuItem (icon tomo.Icon, text string) *MenuItem {
|
||||||
box := &MenuItem {
|
menuItem := &MenuItem {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
box: tomo.NewContainerBox(),
|
||||||
label: NewLabel(text),
|
label: NewLabel(text),
|
||||||
icon: NewIcon(icon, tomo.IconSizeSmall),
|
icon: NewIcon(icon, tomo.IconSizeSmall),
|
||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "MenuItem"))
|
menuItem.box.SetRole(tomo.R("objects", "MenuItem"))
|
||||||
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
menuItem.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
||||||
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
menuItem.box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||||
|
|
||||||
box.Add(box.icon)
|
menuItem.box.Add(menuItem.icon)
|
||||||
box.Add(box.label)
|
menuItem.box.Add(menuItem.label)
|
||||||
|
|
||||||
box.SetInputMask(true)
|
menuItem.box.SetInputMask(true)
|
||||||
box.OnMouseEnter(box.handleMouseEnter)
|
menuItem.box.OnMouseEnter(menuItem.handleMouseEnter)
|
||||||
box.OnMouseLeave(box.handleMouseLeave)
|
menuItem.box.OnMouseLeave(menuItem.handleMouseLeave)
|
||||||
box.OnButtonDown(box.handleButtonDown)
|
menuItem.box.OnButtonDown(menuItem.handleButtonDown)
|
||||||
box.OnButtonUp(box.handleButtonUp)
|
menuItem.box.OnButtonUp(menuItem.handleButtonUp)
|
||||||
box.OnKeyDown(box.handleKeyDown)
|
menuItem.box.OnKeyDown(menuItem.handleKeyDown)
|
||||||
box.OnKeyUp(box.handleKeyUp)
|
menuItem.box.OnKeyUp(menuItem.handleKeyUp)
|
||||||
box.SetFocusable(true)
|
menuItem.box.SetFocusable(true)
|
||||||
return box
|
return menuItem
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetBox returns the underlying box.
|
||||||
|
func (this *MenuItem) GetBox () tomo.Box {
|
||||||
|
return this.box
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFocused sets whether or not this menu item has keyboard focus. If set to
|
||||||
|
// true, this method will steal focus away from whichever object currently has
|
||||||
|
// focus.
|
||||||
|
func (this *MenuItem) SetFocused (focused bool) {
|
||||||
|
this.box.SetFocused(focused)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetText sets the text of the items's label.
|
// SetText sets the text of the items's label.
|
||||||
@ -90,7 +104,7 @@ func (this *MenuItem) handleButtonDown (button input.Button) bool {
|
|||||||
|
|
||||||
func (this *MenuItem) handleButtonUp (button input.Button) bool {
|
func (this *MenuItem) handleButtonUp (button input.Button) bool {
|
||||||
if button != input.ButtonLeft { return false }
|
if button != input.ButtonLeft { return false }
|
||||||
if this.Window().MousePosition().In(this.Bounds()) {
|
if this.box.Window().MousePosition().In(this.box.Bounds()) {
|
||||||
this.on.click.Broadcast()
|
this.on.click.Broadcast()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user