From 0c22977693badd404b32447885a2479378aa24bb Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 14 Feb 2023 18:11:11 -0500 Subject: [PATCH] TextDrawer does not separate whitespace from printables --- artist/text.go | 27 +++++++++------------------ elements/basic/textbox.go | 13 ++++++++----- theme/defaultpatterns.go | 4 ++++ 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/artist/text.go b/artist/text.go index f5a1524..135637a 100644 --- a/artist/text.go +++ b/artist/text.go @@ -20,7 +20,6 @@ type wordLayout struct { spaceAfter int breaksAfter int text []characterLayout - whitespace []characterLayout } // Align specifies a text alignment method. @@ -120,9 +119,13 @@ func (drawer *TextDrawer) Draw ( offset.X + word.position.X + character.x, offset.Y + word.position.Y), character.character) - if !ok { continue } + invalid := + !ok || + unicode.IsSpace(character.character) || + character.character == 0 + if invalid { continue } - // FIXME: clip destination rectangle if we are on the cusp of + // FIXME:? clip destination rectangle if we are on the cusp of // the maximum height. draw.DrawMask ( @@ -198,11 +201,6 @@ func (drawer *TextDrawer) PositionOf (index int) (position image.Point) { position.X = word.position.X + character.x if index < 1 { return } } - for _, character := range word.whitespace { - index -- - position.X = word.position.X + character.x - if index < 1 { return } - } } return } @@ -220,13 +218,6 @@ func (drawer *TextDrawer) AtPosition (position image.Point) (index int) { } cursor ++ } - for _, character := range word.whitespace { - bounds := drawer.boundsOfChar(character).Add(word.position) - if position.In(bounds) { - return cursor - } - cursor ++ - } } return -1 } @@ -313,7 +304,7 @@ func (drawer *TextDrawer) recalculate () { _, advance, ok := drawer.face.GlyphBounds(character) index ++ if !ok { continue } - word.whitespace = append(word.whitespace, characterLayout { + word.text = append(word.text, characterLayout { x: currentCharacterX.Round(), character: character, width: advance.Ceil(), @@ -366,8 +357,8 @@ func (drawer *TextDrawer) recalculate () { // add a little null to the last character if len(drawer.layout) > 0 { lastWord := &drawer.layout[len(drawer.layout) - 1] - lastWord.whitespace = append ( - lastWord.whitespace, + lastWord.text = append ( + lastWord.text, characterLayout { x: currentCharacterX.Round(), }) diff --git a/elements/basic/textbox.go b/elements/basic/textbox.go index da2e930..1511b69 100644 --- a/elements/basic/textbox.go +++ b/elements/basic/textbox.go @@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/theme" import "git.tebibyte.media/sashakoshka/tomo/config" import "git.tebibyte.media/sashakoshka/tomo/artist" +import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/textmanip" import "git.tebibyte.media/sashakoshka/tomo/elements/core" @@ -341,13 +342,15 @@ func (element *TextBox) redo () { func (element *TextBox) draw () { bounds := element.Bounds() - // FIXME: take index into account state := theme.PatternState { Disabled: !element.Enabled(), Focused: element.Focused(), } pattern := element.theme.Pattern(theme.PatternSunken, state) + inset := element.theme.Inset(theme.PatternSunken) + innerCanvas := canvas.Cut(element.core, inset.Apply(bounds)) artist.FillRectangle(element.core, pattern, bounds) + offset := bounds.Min.Add (image.Point { X: element.config.Padding() - element.scroll, Y: element.config.Padding(), @@ -362,7 +365,7 @@ func (element *TextBox) draw () { end := element.valueDrawer.PositionOf(canon.End).Add(offset) end.Y += element.valueDrawer.LineHeight().Round() artist.FillRectangle ( - element.core, + innerCanvas, accent, image.Rectangle { start, end }) } @@ -374,7 +377,7 @@ func (element *TextBox) draw () { theme.PatternForeground, theme.PatternState { Disabled: true }) element.placeholderDrawer.Draw ( - element.core, + innerCanvas, foreground, offset.Sub(textBounds.Min)) } else { @@ -383,7 +386,7 @@ func (element *TextBox) draw () { foreground := element.theme.Pattern ( theme.PatternForeground, state) element.valueDrawer.Draw ( - element.core, + innerCanvas, foreground, offset.Sub(textBounds.Min)) } @@ -395,7 +398,7 @@ func (element *TextBox) draw () { cursorPosition := element.valueDrawer.PositionOf ( element.dot.End) artist.Line ( - element.core, + innerCanvas, foreground, 1, cursorPosition.Add(offset), image.Pt ( diff --git a/theme/defaultpatterns.go b/theme/defaultpatterns.go index aa17ba5..82afd47 100644 --- a/theme/defaultpatterns.go +++ b/theme/defaultpatterns.go @@ -3,6 +3,10 @@ package theme import "image/color" import "git.tebibyte.media/sashakoshka/tomo/artist" +// var backgroundPattern = artist.Gradient { + // First: uhex(0xFF0000FF), + // Second: uhex(0x00FF00FF), +// } var accentPattern = artist.NewUniform(hex(0x408090FF)) var backgroundPattern = artist.NewUniform(color.Gray16 { 0xAAAA }) var foregroundPattern = artist.NewUniform(color.Gray16 { 0x0000 })