objects/label.go

66 lines
1.7 KiB
Go
Raw Normal View History

2023-08-08 10:46:19 -06:00
package objects
import "git.tebibyte.media/tomo/tomo"
2024-08-24 17:52:47 -06:00
import "git.tebibyte.media/tomo/tomo/text"
import "git.tebibyte.media/tomo/tomo/event"
2023-08-08 10:46:19 -06:00
2024-08-24 17:57:48 -06:00
var _ tomo.Object = new(Label)
2023-08-08 10:46:19 -06:00
// Label is a simple text label.
2023-08-09 09:35:24 -06:00
type Label struct {
2024-08-24 17:52:47 -06:00
box tomo.TextBox
2023-08-09 09:35:24 -06:00
}
2023-08-08 10:46:19 -06:00
// NewLabel creates a new text label.
2023-08-09 09:35:24 -06:00
func NewLabel (text string) *Label {
2024-08-24 17:52:47 -06:00
this := &Label { box: tomo.NewTextBox() }
this.box.SetRole(tomo.R("objects", "Label"))
2023-08-09 09:35:24 -06:00
this.SetText(text)
2024-08-24 17:52:47 -06:00
this.box.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
this.box.SetSelectable(true)
this.box.SetFocusable(true)
2023-08-09 09:35:24 -06:00
return this
2023-08-08 10:46:19 -06:00
}
2024-08-24 17:52:47 -06:00
// 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)
}
2024-08-24 23:38:42 -06:00
// SetText sets the text content of the label.
2024-08-24 17:52:47 -06:00
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()
}
// 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)
}
// 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))
}
2024-08-29 15:06:38 -06:00
// SetOverflow sets the X and Y overflow of the label.
func (this *Label) SetOverflow (x, y bool) {
this.box.SetAttr(tomo.AOverflow(x, y))
}