Compare commits

...

5 Commits

8 changed files with 99 additions and 37 deletions

View File

@ -31,7 +31,7 @@ func NewButton (text string) *Button {
label: NewLabel(text), label: NewLabel(text),
} }
button.box.SetRole(tomo.R("objects", "Button")) button.box.SetRole(tomo.R("objects", "Button"))
button.label.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle)) button.label.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
button.box.SetAttr(tomo.ALayout(buttonLayout)) button.box.SetAttr(tomo.ALayout(buttonLayout))
button.SetText(text) button.SetText(text)

View File

@ -44,7 +44,7 @@ func NewCalendar (tm time.Time) *Calendar {
calendar.on.valueChange.Broadcast() calendar.on.valueChange.Broadcast()
}) })
calendar.monthLabel = NewLabel("") calendar.monthLabel = NewLabel("")
calendar.monthLabel.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle)) calendar.monthLabel.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
calendar.grid = tomo.NewContainerBox() calendar.grid = tomo.NewContainerBox()
calendar.grid.SetRole(tomo.R("objects", "CalendarGrid")) calendar.grid.SetRole(tomo.R("objects", "CalendarGrid"))

View File

@ -56,7 +56,7 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
dialog.SetIcon(iconId) dialog.SetIcon(iconId)
icon := NewIcon(iconId, tomo.IconSizeLarge) icon := NewIcon(iconId, tomo.IconSizeLarge)
messageText := NewLabel(message) messageText := NewLabel(message)
messageText.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle)) messageText.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
for _, option := range options { for _, option := range options {
if option, ok := option.(clickable); ok { if option, ok := option.(clickable); ok {

23
icon.go
View File

@ -3,9 +3,11 @@ package objects
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/tomo/canvas"
var _ tomo.Object = new(Icon)
// Icon displays a single icon. // Icon displays a single icon.
type Icon struct { type Icon struct {
tomo.Box box tomo.Box
icon tomo.Icon icon tomo.Icon
size tomo.IconSize size tomo.IconSize
} }
@ -21,14 +23,19 @@ func iconSizeString (size tomo.IconSize) string {
// NewIcon creates a new icon from an icon ID. // NewIcon creates a new icon from an icon ID.
func NewIcon (icon tomo.Icon, size tomo.IconSize) *Icon { func NewIcon (icon tomo.Icon, size tomo.IconSize) *Icon {
this := &Icon { this := &Icon {
Box: tomo.NewBox(), box: tomo.NewBox(),
} }
this.SetRole(tomo.R("objects", "Icon")) this.box.SetRole(tomo.R("objects", "Icon"))
this.SetIcon(icon, size) this.SetIcon(icon, size)
this.OnIconSetChange(this.handleIconSetChange) this.box.OnIconSetChange(this.handleIconSetChange)
return this return this
} }
// GetBox returns the underlying box.
func (this *Icon) GetBox () tomo.Box {
return this.box
}
// SetIcon sets the icon. // SetIcon sets the 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 }
@ -42,12 +49,12 @@ func (this *Icon) handleIconSetChange () {
} }
func (this *Icon) setTexture (texture canvas.Texture) { func (this *Icon) setTexture (texture canvas.Texture) {
this.SetAttr(tomo.ATexture(texture)) this.box.SetAttr(tomo.ATexture(texture))
this.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter)) this.box.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter))
if texture == nil { if texture == nil {
this.SetAttr(tomo.AMinimumSize(0, 0)) this.box.SetAttr(tomo.AMinimumSize(0, 0))
} else { } else {
bounds := texture.Bounds() bounds := texture.Bounds()
this.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min))) this.box.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min)))
} }
} }

View File

@ -1,19 +1,60 @@
package objects package objects
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/text"
import "git.tebibyte.media/tomo/tomo/event"
var _ tomo.Object = new(Label)
// Label is a simple text label. // Label is a simple text label.
type Label struct { type Label struct {
tomo.TextBox box tomo.TextBox
} }
// NewLabel creates a new text label. // NewLabel creates a new text label.
func NewLabel (text string) *Label { func NewLabel (text string) *Label {
this := &Label { TextBox: tomo.NewTextBox() } this := &Label { box: tomo.NewTextBox() }
this.SetRole(tomo.R("objects", "Label")) this.box.SetRole(tomo.R("objects", "Label"))
this.SetText(text) this.SetText(text)
this.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle)) this.box.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
this.SetSelectable(true) this.box.SetSelectable(true)
this.SetFocusable(true) this.box.SetFocusable(true)
return this return this
} }
// GetBox returns the underlying box.
func (this *Label) GetBox () tomo.Box {
return this.box
}
// SetFocused sets whether or not this label has keyboard focus. If set to true,
// this method will steal focus away from whichever object currently has focus.
func (this *Label) SetFocused (focused bool) {
this.box.SetFocused(focused)
}
// SetText sets the text content of the heading.
func (this *Label) SetText (text string) {
this.box.SetText(text)
}
// Select sets the text cursor or selection.
func (this *Label) Select (dot text.Dot) {
this.box.Select(dot)
}
// Dot returns the text cursor or selection.
func (this *Label) Dot () text.Dot {
return this.box.Dot()
}
// SetAlign sets the X and Y alignment of the label.
func (this *Label) SetAlign (x, y tomo.Align) {
this.box.SetAttr(tomo.AAlign(x, y))
}
// OnDotChange specifies a function to be called when the text cursor or
// selection changes.
func (this *Label) OnDotChange (callback func ()) event.Cookie {
return this.box.OnDotChange(callback)
}

View File

@ -5,9 +5,11 @@ 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(LabelCheckbox)
// LabelCheckbox is a checkbox with a label. // LabelCheckbox is a checkbox with a label.
type LabelCheckbox struct { type LabelCheckbox struct {
tomo.ContainerBox box tomo.ContainerBox
checkbox *Checkbox checkbox *Checkbox
label *Label label *Label
} }
@ -15,22 +17,34 @@ type LabelCheckbox struct {
// NewLabelCheckbox creates a new labeled checkbox with the specified value and // NewLabelCheckbox creates a new labeled checkbox with the specified value and
// label text. // label text.
func NewLabelCheckbox (value bool, text string) *LabelCheckbox { func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
box := &LabelCheckbox { labelCheckbox := &LabelCheckbox {
ContainerBox: tomo.NewContainerBox(), box: tomo.NewContainerBox(),
checkbox: NewCheckbox(value), checkbox: NewCheckbox(value),
label: NewLabel(text), label: NewLabel(text),
} }
box.SetRole(tomo.R("objects", "LabelCheckbox")) labelCheckbox.box.SetRole(tomo.R("objects", "LabelCheckbox"))
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle)) labelCheckbox.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
box.label.SetSelectable(false) labelCheckbox.label.GetBox().(tomo.TextBox).SetSelectable(false)
box.label.SetFocusable(false) labelCheckbox.label.GetBox().(tomo.TextBox).SetFocusable(false)
box.Add(box.checkbox) labelCheckbox.box.Add(labelCheckbox.checkbox)
box.Add(box.label) labelCheckbox.box.Add(labelCheckbox.label)
box.SetAttr(tomo.ALayout(layouts.Row { false, true })) labelCheckbox.box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
box.OnButtonDown(box.handleButtonDown) labelCheckbox.box.OnButtonDown(labelCheckbox.handleButtonDown)
box.OnButtonUp(box.handleButtonUp) labelCheckbox.box.OnButtonUp(labelCheckbox.handleButtonUp)
return box return labelCheckbox
}
// GetBox returns the underlying box.
func (this *LabelCheckbox) GetBox () tomo.Box {
return this.box
}
// SetFocused sets whether or not this checkbox has keyboard focus. If set to
// true, this method will steal focus away from whichever object currently has
// focus.
func (this *LabelCheckbox) SetFocused (focused bool) {
this.checkbox.SetFocused(focused)
} }
// Value returns the value of the checkbox. // Value returns the value of the checkbox.
@ -61,7 +75,7 @@ func (this *LabelCheckbox) handleButtonDown (button input.Button) bool {
func (this *LabelCheckbox) handleButtonUp (button input.Button) bool { func (this *LabelCheckbox) handleButtonUp (button input.Button) bool {
if !isClickingButton(button) { return false } if !isClickingButton(button) { return false }
if this.Window().MousePosition().In(this.Bounds()) { if this.box.Window().MousePosition().In(this.box.Bounds()) {
this.checkbox.SetFocused(true) this.checkbox.SetFocused(true)
this.checkbox.Toggle() this.checkbox.Toggle()
} }

View File

@ -23,9 +23,9 @@ func NewLabelSwatch (value color.Color, text string) *LabelSwatch {
} }
box.SetRole(tomo.R("objects", "LabelSwatch")) box.SetRole(tomo.R("objects", "LabelSwatch"))
box.swatch.label = text box.swatch.label = text
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle)) box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
box.label.SetSelectable(false) box.label.GetBox().(tomo.TextBox).SetSelectable(false)
box.label.SetFocusable(false) box.label.GetBox().(tomo.TextBox).SetFocusable(false)
box.Add(box.swatch) box.Add(box.swatch)
box.Add(box.label) box.Add(box.label)
box.SetAttr(tomo.ALayout(layouts.Row { false, true })) box.SetAttr(tomo.ALayout(layouts.Row { false, true }))

View File

@ -31,7 +31,7 @@ func NewIconMenuItem (icon tomo.Icon, text string) *MenuItem {
icon: NewIcon(icon, 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.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
box.SetAttr(tomo.ALayout(layouts.Row { false, true })) box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
box.Add(box.icon) box.Add(box.icon)