You can choose whether or not you want text to wrap
This commit is contained in:
parent
a79f2eaf64
commit
3ddeeb5469
@ -137,6 +137,21 @@ func (drawer *TextDrawer) LayoutBounds () (bounds image.Rectangle) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Em returns the width of an emspace.
|
||||||
|
func (drawer *TextDrawer) Em () (width fixed.Int26_6) {
|
||||||
|
if drawer.face == nil { return }
|
||||||
|
width, _ = drawer.face.GlyphAdvance('M')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// LineHeight returns the height of one line.
|
||||||
|
func (drawer *TextDrawer) LineHeight () (height fixed.Int26_6) {
|
||||||
|
if drawer.face == nil { return }
|
||||||
|
metrics := drawer.face.Metrics()
|
||||||
|
height = metrics.Height
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (drawer *TextDrawer) recalculate () {
|
func (drawer *TextDrawer) recalculate () {
|
||||||
drawer.layoutClean = true
|
drawer.layoutClean = true
|
||||||
drawer.layout = nil
|
drawer.layout = nil
|
||||||
|
|||||||
@ -6,28 +6,29 @@ import "git.tebibyte.media/sashakoshka/tomo/theme"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||||
|
|
||||||
|
// Label is a simple text box.
|
||||||
type Label struct {
|
type Label struct {
|
||||||
*core.Core
|
*core.Core
|
||||||
core core.CoreControl
|
core core.CoreControl
|
||||||
|
|
||||||
|
wrap bool
|
||||||
text string
|
text string
|
||||||
drawer artist.TextDrawer
|
drawer artist.TextDrawer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLabel (text string) (element *Label) {
|
// NewLabel creates a new label. If wrap is set to true, the text inside will be
|
||||||
|
// wrapped.
|
||||||
|
func NewLabel (text string, wrap bool) (element *Label) {
|
||||||
element = &Label { }
|
element = &Label { }
|
||||||
element.Core, element.core = core.NewCore(element)
|
element.Core, element.core = core.NewCore(element)
|
||||||
face := theme.FontFaceRegular()
|
face := theme.FontFaceRegular()
|
||||||
element.drawer.SetFace(face)
|
element.drawer.SetFace(face)
|
||||||
|
element.SetWrap(wrap)
|
||||||
element.SetText(text)
|
element.SetText(text)
|
||||||
metrics := face.Metrics()
|
|
||||||
emspace, _ := face.GlyphAdvance('M')
|
|
||||||
intEmspace := emspace.Round()
|
|
||||||
if intEmspace < 1 { intEmspace = theme.Padding()}
|
|
||||||
element.core.SetMinimumSize(intEmspace, metrics.Height.Round())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle handles and event.
|
||||||
func (element *Label) Handle (event tomo.Event) {
|
func (element *Label) Handle (event tomo.Event) {
|
||||||
switch event.(type) {
|
switch event.(type) {
|
||||||
case tomo.EventResize:
|
case tomo.EventResize:
|
||||||