TextDrawer does not separate whitespace from printables

This commit is contained in:
Sasha Koshka 2023-02-14 18:11:11 -05:00
parent 4d87972235
commit 0c22977693
3 changed files with 21 additions and 23 deletions

View File

@ -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(),
})

View File

@ -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 (

View File

@ -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 })