Compare commits
No commits in common. "694f9127c0882e6bfdae0ae8085334d282b42655" and "6f8d5cc426e1999e2050b27d203b427b7283c87f" have entirely different histories.
694f9127c0
...
6f8d5cc426
58
menuitem.go
58
menuitem.go
@ -5,14 +5,12 @@ 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 {
|
||||||
box tomo.ContainerBox
|
tomo.ContainerBox
|
||||||
|
|
||||||
label *Label
|
label *Label
|
||||||
icon *Icon
|
icon *Icon
|
||||||
labelActive bool
|
labelActive bool
|
||||||
|
|
||||||
on struct {
|
on struct {
|
||||||
@ -27,39 +25,27 @@ 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 {
|
||||||
menuItem := &MenuItem {
|
box := &MenuItem {
|
||||||
box: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
label: NewLabel(text),
|
label: NewLabel(text),
|
||||||
icon: NewIcon(icon, tomo.IconSizeSmall),
|
icon: NewIcon(icon, tomo.IconSizeSmall),
|
||||||
}
|
}
|
||||||
menuItem.box.SetRole(tomo.R("objects", "MenuItem"))
|
box.SetRole(tomo.R("objects", "MenuItem"))
|
||||||
menuItem.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
||||||
menuItem.box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||||
|
|
||||||
menuItem.box.Add(menuItem.icon)
|
box.Add(box.icon)
|
||||||
menuItem.box.Add(menuItem.label)
|
box.Add(box.label)
|
||||||
|
|
||||||
menuItem.box.SetInputMask(true)
|
box.SetInputMask(true)
|
||||||
menuItem.box.OnMouseEnter(menuItem.handleMouseEnter)
|
box.OnMouseEnter(box.handleMouseEnter)
|
||||||
menuItem.box.OnMouseLeave(menuItem.handleMouseLeave)
|
box.OnMouseLeave(box.handleMouseLeave)
|
||||||
menuItem.box.OnButtonDown(menuItem.handleButtonDown)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
menuItem.box.OnButtonUp(menuItem.handleButtonUp)
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
menuItem.box.OnKeyDown(menuItem.handleKeyDown)
|
box.OnKeyDown(box.handleKeyDown)
|
||||||
menuItem.box.OnKeyUp(menuItem.handleKeyUp)
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
menuItem.box.SetFocusable(true)
|
box.SetFocusable(true)
|
||||||
return menuItem
|
return box
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
||||||
@ -104,7 +90,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.box.Window().MousePosition().In(this.box.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.on.click.Broadcast()
|
this.on.click.Broadcast()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
29
mimeicon.go
29
mimeicon.go
@ -4,29 +4,22 @@ import "git.tebibyte.media/tomo/tomo"
|
|||||||
import "git.tebibyte.media/tomo/tomo/data"
|
import "git.tebibyte.media/tomo/tomo/data"
|
||||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||||
|
|
||||||
var _ tomo.Object = new(MimeIcon)
|
|
||||||
|
|
||||||
// MimeIcon displays an icon of a MIME type.
|
// MimeIcon displays an icon of a MIME type.
|
||||||
type MimeIcon struct {
|
type MimeIcon struct {
|
||||||
box tomo.Box
|
tomo.Box
|
||||||
mime data.Mime
|
mime data.Mime
|
||||||
size tomo.IconSize
|
size tomo.IconSize
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMimeIcon creates a new icon from a MIME type.
|
// NewMimeIcon creates a new icon from a MIME type.
|
||||||
func NewMimeIcon (mime data.Mime, size tomo.IconSize) *MimeIcon {
|
func NewMimeIcon (mime data.Mime, size tomo.IconSize) *MimeIcon {
|
||||||
mimeIcon := &MimeIcon {
|
this := &MimeIcon {
|
||||||
box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
mimeIcon.box.SetRole(tomo.R("objects", "MimeIcon"))
|
this.SetRole(tomo.R("objects", "MimeIcon"))
|
||||||
mimeIcon.SetIcon(mime, size)
|
this.SetIcon(mime, size)
|
||||||
mimeIcon.box.OnIconSetChange(mimeIcon.handleIconSetChange)
|
this.OnIconSetChange(this.handleIconSetChange)
|
||||||
return mimeIcon
|
return this
|
||||||
}
|
|
||||||
|
|
||||||
// GetBox returns the underlying box.
|
|
||||||
func (this *MimeIcon) GetBox () tomo.Box {
|
|
||||||
return this.box
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetIcon sets the MIME type and size of the icon.
|
// SetIcon sets the MIME type and size of the icon.
|
||||||
@ -42,12 +35,12 @@ func (this *MimeIcon) handleIconSetChange () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *MimeIcon) setTexture (texture canvas.Texture) {
|
func (this *MimeIcon) setTexture (texture canvas.Texture) {
|
||||||
this.box.SetAttr(tomo.ATexture(texture))
|
this.SetAttr(tomo.ATexture(texture))
|
||||||
this.box.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter))
|
this.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter))
|
||||||
if texture == nil {
|
if texture == nil {
|
||||||
this.box.SetAttr(tomo.AMinimumSize(0, 0))
|
this.SetAttr(tomo.AMinimumSize(0, 0))
|
||||||
} else {
|
} else {
|
||||||
bounds := texture.Bounds()
|
bounds := texture.Bounds()
|
||||||
this.box.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min)))
|
this.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user