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
|
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) {
|
func (this *Icon) SetIcon (icon tomo.Icon, size tomo.IconSize) {
|
||||||
if this.icon == icon { return }
|
if this.icon == icon { return }
|
||||||
this.icon = icon
|
this.icon = icon
|
||||||
|
this.size = size
|
||||||
this.setTexture(icon.Texture(size))
|
this.setTexture(icon.Texture(size))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
menu.go
30
menu.go
@@ -18,22 +18,27 @@ type Menu struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewMenu creates a new menu with the specified items. The menu will appear
|
// 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.
|
||||||
// directly under the mouse pointer instead.
|
func NewMenu (parent tomo.Window, items ...tomo.Object) (*Menu, error) {
|
||||||
func NewMenu (anchor tomo.Object, 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 { }
|
menu := &Menu { }
|
||||||
if anchor == nil {
|
menu.bounds = bounds
|
||||||
// TODO: *actually* put it under the mouse
|
menu.parent = parent
|
||||||
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)
|
window, err := menu.parent.NewMenu(menu.bounds)
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
menu.Window = window
|
menu.Window = window
|
||||||
}
|
|
||||||
|
|
||||||
menu.rootContainer = tomo.NewContainerBox()
|
menu.rootContainer = tomo.NewContainerBox()
|
||||||
menu.rootContainer.SetAttr(tomo.ALayout(layouts.ContractVertical))
|
menu.rootContainer.SetAttr(tomo.ALayout(layouts.ContractVertical))
|
||||||
@@ -74,6 +79,7 @@ func (this *Menu) TearOff () {
|
|||||||
this.Window.Close()
|
this.Window.Close()
|
||||||
|
|
||||||
this.rootContainer.Remove(this.tearLine)
|
this.rootContainer.Remove(this.tearLine)
|
||||||
|
this.rootContainer.SetTag("torn", true)
|
||||||
|
|
||||||
this.Window = window
|
this.Window = window
|
||||||
this.Window.SetRoot(this.rootContainer)
|
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.
|
// NewMenuItem creates a new menu item with the specified text.
|
||||||
func NewMenuItem (text string) *MenuItem {
|
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 {
|
box := &MenuItem {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
label: NewLabel(text),
|
label: NewLabel(text),
|
||||||
icon: NewIcon("", tomo.IconSizeSmall),
|
icon: NewIcon(icon, tomo.IconSizeSmall),
|
||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "MenuItem"))
|
box.SetRole(tomo.R("objects", "MenuItem"))
|
||||||
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
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
|
// SetIcon sets an icon for this item. Setting the icon to IconUnknown will
|
||||||
// remove it.
|
// remove it.
|
||||||
func (this *MenuItem) SetIcon (id tomo.Icon) {
|
func (this *MenuItem) SetIcon (id tomo.Icon) {
|
||||||
if this.icon != nil { this.Remove(this.icon) }
|
this.icon.SetIcon(id, tomo.IconSizeSmall)
|
||||||
this.Insert(NewIcon(id, tomo.IconSizeSmall), this.label)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnClick specifies a function to be called when the menu item is clicked.
|
// 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) {
|
func (this *tab) setActive (active bool) {
|
||||||
if active {
|
if active {
|
||||||
this.SetRole(tomo.R("objects", "Tab"))
|
this.SetRole(tomo.R("objects", "Tab"))
|
||||||
this.SetTag("active", false)
|
this.SetTag("active", true)
|
||||||
} else {
|
} else {
|
||||||
this.SetRole(tomo.R("objects", "Tab"))
|
this.SetRole(tomo.R("objects", "Tab"))
|
||||||
this.SetTag("active", true)
|
this.SetTag("active", false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user