package objects import "fmt" 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 // 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. type Heading struct { box tomo.TextBox } // NewHeading creates a new section heading. The level can be from 0 to 2. func NewHeading (level int, text string) *Heading { if level < 0 { level = 0 } if level > 2 { level = 2 } this := &Heading { box: tomo.NewTextBox() } this.box.SetRole(tomo.R("objects", "Heading")) this.box.SetTag(fmt.Sprint(level), true) this.SetText(text) this.box.SetSelectable(true) this.box.SetFocusable(true) 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) } // 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. func NewMenuHeading (text string) *Heading { heading := NewHeading(0, text) heading.box.SetTag("menu", true) return heading }