Compare commits
4 Commits
v0.21.0
...
f1ac74dcbc
| Author | SHA1 | Date | |
|---|---|---|---|
| f1ac74dcbc | |||
| ce0bc5be3b | |||
| eb0bf58961 | |||
| 8068036219 |
@@ -23,3 +23,9 @@ func NewHeading (level int, text string) *Heading {
|
||||
return this
|
||||
}
|
||||
|
||||
// NewMenuHeading creatss a new heading for use in menus.
|
||||
func NewMenuHeading (text string) *Heading {
|
||||
heading := NewHeading(0, text)
|
||||
heading.SetTag("menu", true)
|
||||
return heading
|
||||
}
|
||||
|
||||
1
icon.go
1
icon.go
@@ -33,6 +33,7 @@ func NewIcon (icon tomo.Icon, size tomo.IconSize) *Icon {
|
||||
func (this *Icon) SetIcon (icon tomo.Icon, size tomo.IconSize) {
|
||||
if this.icon == icon { return }
|
||||
this.icon = icon
|
||||
this.size = size
|
||||
this.setTexture(icon.Texture(size))
|
||||
}
|
||||
|
||||
|
||||
36
menu.go
36
menu.go
@@ -18,22 +18,27 @@ type Menu struct {
|
||||
}
|
||||
|
||||
// NewMenu creates a new menu with the specified items. The menu will appear
|
||||
// directly under the anchor Object. If the anchor is nil, it will appear
|
||||
// directly under the mouse pointer instead.
|
||||
func NewMenu (anchor tomo.Object, items ...tomo.Object) (*Menu, error) {
|
||||
// directly under the mouse pointer.
|
||||
func NewMenu (parent tomo.Window, items ...tomo.Object) (*Menu, error) {
|
||||
bounds := (image.Rectangle { }).Add(parent.MousePosition())
|
||||
return newMenu(parent, bounds, items...)
|
||||
}
|
||||
|
||||
// NewAnchoredMenu creates a new menu with the specified items. The menu will
|
||||
// appear directly under the anchor.
|
||||
func NewAnchoredMenu (anchor tomo.Object, items ...tomo.Object) (*Menu, error) {
|
||||
parent := anchor.GetBox().Window()
|
||||
bounds := menuBoundsFromAnchor(anchor)
|
||||
return newMenu(parent, bounds, items...)
|
||||
}
|
||||
|
||||
func newMenu (parent tomo.Window, bounds image.Rectangle, items ...tomo.Object) (*Menu, error) {
|
||||
menu := &Menu { }
|
||||
if anchor == nil {
|
||||
// TODO: *actually* put it under the mouse
|
||||
window, err := tomo.NewWindow(menu.bounds)
|
||||
if err != nil { return nil, err }
|
||||
menu.Window = window
|
||||
} else {
|
||||
menu.bounds = menuBoundsFromAnchor(anchor)
|
||||
menu.parent = anchor.GetBox().Window()
|
||||
window, err := menu.parent.NewMenu(menu.bounds)
|
||||
if err != nil { return nil, err }
|
||||
menu.Window = window
|
||||
}
|
||||
menu.bounds = bounds
|
||||
menu.parent = parent
|
||||
window, err := menu.parent.NewMenu(menu.bounds)
|
||||
if err != nil { return nil, err }
|
||||
menu.Window = window
|
||||
|
||||
menu.rootContainer = tomo.NewContainerBox()
|
||||
menu.rootContainer.SetAttr(tomo.ALayout(layouts.ContractVertical))
|
||||
@@ -74,6 +79,7 @@ func (this *Menu) TearOff () {
|
||||
this.Window.Close()
|
||||
|
||||
this.rootContainer.Remove(this.tearLine)
|
||||
this.rootContainer.SetTag("torn", true)
|
||||
|
||||
this.Window = window
|
||||
this.Window.SetRoot(this.rootContainer)
|
||||
|
||||
10
menuitem.go
10
menuitem.go
@@ -20,10 +20,15 @@ type MenuItem struct {
|
||||
|
||||
// NewMenuItem creates a new menu item with the specified text.
|
||||
func NewMenuItem (text string) *MenuItem {
|
||||
return NewIconMenuItem(tomo.IconUnknown, text)
|
||||
}
|
||||
|
||||
// NewIconMenuItem creates a new menu item with the specified icon and text.
|
||||
func NewIconMenuItem (icon tomo.Icon, text string) *MenuItem {
|
||||
box := &MenuItem {
|
||||
ContainerBox: tomo.NewContainerBox(),
|
||||
label: NewLabel(text),
|
||||
icon: NewIcon("", tomo.IconSizeSmall),
|
||||
icon: NewIcon(icon, tomo.IconSizeSmall),
|
||||
}
|
||||
box.SetRole(tomo.R("objects", "MenuItem"))
|
||||
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||
@@ -49,8 +54,7 @@ func (this *MenuItem) SetText (text string) {
|
||||
// SetIcon sets an icon for this item. Setting the icon to IconUnknown will
|
||||
// remove it.
|
||||
func (this *MenuItem) SetIcon (id tomo.Icon) {
|
||||
if this.icon != nil { this.Remove(this.icon) }
|
||||
this.Insert(NewIcon(id, tomo.IconSizeSmall), this.label)
|
||||
this.icon.SetIcon(id, tomo.IconSizeSmall)
|
||||
}
|
||||
|
||||
// OnClick specifies a function to be called when the menu item is clicked.
|
||||
|
||||
@@ -126,10 +126,10 @@ type tab struct {
|
||||
func (this *tab) setActive (active bool) {
|
||||
if active {
|
||||
this.SetRole(tomo.R("objects", "Tab"))
|
||||
this.SetTag("active", false)
|
||||
this.SetTag("active", true)
|
||||
} else {
|
||||
this.SetRole(tomo.R("objects", "Tab"))
|
||||
this.SetTag("active", true)
|
||||
this.SetTag("active", false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user