Text drawer now takes in runes instead of a string
This commit is contained in:
parent
85ddb8ace1
commit
b03cba57e1
@ -38,7 +38,6 @@ const (
|
||||
// text, and calculating text bounds. It avoids doing redundant work
|
||||
// automatically.
|
||||
type TextDrawer struct {
|
||||
text string
|
||||
runes []rune
|
||||
face font.Face
|
||||
width int
|
||||
@ -53,10 +52,9 @@ type TextDrawer struct {
|
||||
}
|
||||
|
||||
// SetText sets the text of the text drawer.
|
||||
func (drawer *TextDrawer) SetText (text string) {
|
||||
if drawer.text == text { return }
|
||||
drawer.text = text
|
||||
drawer.runes = []rune(text)
|
||||
func (drawer *TextDrawer) SetText (runes []rune) {
|
||||
// if drawer.runes == runes { return }
|
||||
drawer.runes = runes
|
||||
drawer.layoutClean = false
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ func (element *Button) SetText (text string) {
|
||||
if element.text == text { return }
|
||||
|
||||
element.text = text
|
||||
element.drawer.SetText(text)
|
||||
element.drawer.SetText([]rune(text))
|
||||
textBounds := element.drawer.LayoutBounds()
|
||||
element.core.SetMinimumSize (
|
||||
theme.Padding() * 2 + textBounds.Dx(),
|
||||
|
@ -157,7 +157,7 @@ func (element *Checkbox) SetText (text string) {
|
||||
if element.text == text { return }
|
||||
|
||||
element.text = text
|
||||
element.drawer.SetText(text)
|
||||
element.drawer.SetText([]rune(text))
|
||||
textBounds := element.drawer.LayoutBounds()
|
||||
element.core.SetMinimumSize (
|
||||
textBounds.Dy() + theme.Padding() + textBounds.Dx(),
|
||||
|
@ -54,7 +54,7 @@ func (element *Label) SetText (text string) {
|
||||
if element.text == text { return }
|
||||
|
||||
element.text = text
|
||||
element.drawer.SetText(text)
|
||||
element.drawer.SetText([]rune(text))
|
||||
element.updateMinimumSize()
|
||||
|
||||
if element.core.HasImage () {
|
||||
|
@ -26,7 +26,7 @@ func NewTextBox (placeholder, text string) (element *TextBox) {
|
||||
element.placeholderDrawer.SetFace(theme.FontFaceRegular())
|
||||
element.valueDrawer.SetFace(theme.FontFaceRegular())
|
||||
element.placeholder = placeholder
|
||||
element.placeholderDrawer.SetText(placeholder)
|
||||
element.placeholderDrawer.SetText([]rune(placeholder))
|
||||
element.updateMinimumSize()
|
||||
element.SetText(text)
|
||||
return
|
||||
@ -111,7 +111,7 @@ func (element *TextBox) SetPlaceholder (placeholder string) {
|
||||
if element.placeholder == placeholder { return }
|
||||
|
||||
element.placeholder = placeholder
|
||||
element.placeholderDrawer.SetText(placeholder)
|
||||
element.placeholderDrawer.SetText([]rune(placeholder))
|
||||
|
||||
element.updateMinimumSize()
|
||||
if element.core.HasImage () {
|
||||
@ -133,7 +133,7 @@ func (element *TextBox) SetText (text string) {
|
||||
if element.text == text { return }
|
||||
|
||||
element.text = text
|
||||
element.valueDrawer.SetText(text)
|
||||
element.valueDrawer.SetText([]rune(text))
|
||||
if element.cursor > element.valueDrawer.Length() {
|
||||
element.cursor = element.valueDrawer.Length()
|
||||
}
|
||||
|
Reference in New Issue
Block a user