objects/textview.go

28 lines
701 B
Go
Raw Permalink Normal View History

2023-09-15 14:11:59 -06:00
package objects
import "image"
import "git.tebibyte.media/tomo/tomo"
// TextView is an area for displaying a large amount of multi-line text.
type TextView struct {
tomo.TextBox
}
// NewTextView creates a new text view.
func NewTextView (text string) *TextView {
this := &TextView { TextBox: tomo.NewTextBox() }
2024-07-21 09:48:28 -06:00
this.SetRole(tomo.R("objects", "TextView"))
2023-09-15 14:11:59 -06:00
this.SetFocusable(true)
this.SetSelectable(true)
this.SetText(text)
2024-07-25 10:58:38 -06:00
this.SetAttr(tomo.AOverflow(false, true))
this.SetAttr(tomo.AWrap(true))
2023-09-15 14:11:59 -06:00
this.OnScroll(this.handleScroll)
return this
}
2024-07-25 10:58:38 -06:00
func (this *TextView) handleScroll (x, y float64) bool {
2023-09-15 14:11:59 -06:00
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
2024-07-25 10:58:38 -06:00
return true
2023-09-15 14:11:59 -06:00
}