Heading no longer embeds tomo.TextBox

This commit is contained in:
Sasha Koshka 2024-08-24 19:42:25 -04:00
parent df2e8f1b07
commit 14f6e175f0

View File

@ -2,30 +2,73 @@ package objects
import "fmt" import "fmt"
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(Heading)
// Heading is a label that denotes the start of some section of content. It can // Heading is a label that denotes the start of some section of content. It can
// have a level from 0 to 2, with 0 being the most prominent and 2 being the // have a level from 0 to 2, with 0 being the most prominent and 2 being the
// most subtle. The level is described in the role variation. // most subtle. The level is described in the role variation.
type Heading struct { type Heading struct {
tomo.TextBox box tomo.TextBox
} }
// NewHeading creates a new section heading. The level can be from 0 to 2. // NewHeading creates a new section heading. The level can be from 0 to 2.
func NewHeading (level int, text string) *Heading { func NewHeading (level int, text string) *Heading {
if level < 0 { level = 0 } if level < 0 { level = 0 }
if level > 2 { level = 2 } if level > 2 { level = 2 }
this := &Heading { TextBox: tomo.NewTextBox() } this := &Heading { box: tomo.NewTextBox() }
this.SetRole(tomo.R("objects", "Heading")) this.box.SetRole(tomo.R("objects", "Heading"))
this.SetTag(fmt.Sprint(level), true) this.box.SetTag(fmt.Sprint(level), true)
this.SetText(text) this.SetText(text)
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 *Heading) GetBox () tomo.Box {
return this.box
}
// SetFocused sets whether or not this heading has keyboard focus. If set to
// true, this method will steal focus away from whichever object currently has
// focus.
func (this *Heading) SetFocused (focused bool) {
this.box.SetFocused(focused)
}
// SetText sets the text content of the heading.
func (this *Heading) SetText (text string) {
this.box.SetText(text)
}
// SetSelectable sets whether or not the text content can be highlighted/
// selected.
func (this *Heading) SetSelectable (selectable bool) {
this.box.SetSelectable(selectable)
}
// Select sets the text cursor or selection.
func (this *Heading) Select (dot text.Dot) {
this.box.Select(dot)
}
// Dot returns the text cursor or selection.
func (this *Heading) Dot () text.Dot {
return this.box.Dot()
}
// OnDotChange specifies a function to be called when the text cursor or
// selection changes.
func (this *Heading) OnDotChange (callback func ()) event.Cookie {
return this.box.OnDotChange(callback)
}
// NewMenuHeading creatss a new heading for use in menus. // NewMenuHeading creatss a new heading for use in menus.
func NewMenuHeading (text string) *Heading { func NewMenuHeading (text string) *Heading {
heading := NewHeading(0, text) heading := NewHeading(0, text)
heading.SetTag("menu", true) heading.box.SetTag("menu", true)
return heading return heading
} }