TextDrawer does not separate whitespace from printables
This commit is contained in:
parent
4d87972235
commit
0c22977693
@ -20,7 +20,6 @@ type wordLayout struct {
|
|||||||
spaceAfter int
|
spaceAfter int
|
||||||
breaksAfter int
|
breaksAfter int
|
||||||
text []characterLayout
|
text []characterLayout
|
||||||
whitespace []characterLayout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Align specifies a text alignment method.
|
// Align specifies a text alignment method.
|
||||||
@ -120,9 +119,13 @@ func (drawer *TextDrawer) Draw (
|
|||||||
offset.X + word.position.X + character.x,
|
offset.X + word.position.X + character.x,
|
||||||
offset.Y + word.position.Y),
|
offset.Y + word.position.Y),
|
||||||
character.character)
|
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.
|
// the maximum height.
|
||||||
|
|
||||||
draw.DrawMask (
|
draw.DrawMask (
|
||||||
@ -198,11 +201,6 @@ func (drawer *TextDrawer) PositionOf (index int) (position image.Point) {
|
|||||||
position.X = word.position.X + character.x
|
position.X = word.position.X + character.x
|
||||||
if index < 1 { return }
|
if index < 1 { return }
|
||||||
}
|
}
|
||||||
for _, character := range word.whitespace {
|
|
||||||
index --
|
|
||||||
position.X = word.position.X + character.x
|
|
||||||
if index < 1 { return }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -220,13 +218,6 @@ func (drawer *TextDrawer) AtPosition (position image.Point) (index int) {
|
|||||||
}
|
}
|
||||||
cursor ++
|
cursor ++
|
||||||
}
|
}
|
||||||
for _, character := range word.whitespace {
|
|
||||||
bounds := drawer.boundsOfChar(character).Add(word.position)
|
|
||||||
if position.In(bounds) {
|
|
||||||
return cursor
|
|
||||||
}
|
|
||||||
cursor ++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
@ -313,7 +304,7 @@ func (drawer *TextDrawer) recalculate () {
|
|||||||
_, advance, ok := drawer.face.GlyphBounds(character)
|
_, advance, ok := drawer.face.GlyphBounds(character)
|
||||||
index ++
|
index ++
|
||||||
if !ok { continue }
|
if !ok { continue }
|
||||||
word.whitespace = append(word.whitespace, characterLayout {
|
word.text = append(word.text, characterLayout {
|
||||||
x: currentCharacterX.Round(),
|
x: currentCharacterX.Round(),
|
||||||
character: character,
|
character: character,
|
||||||
width: advance.Ceil(),
|
width: advance.Ceil(),
|
||||||
@ -366,8 +357,8 @@ func (drawer *TextDrawer) recalculate () {
|
|||||||
// add a little null to the last character
|
// add a little null to the last character
|
||||||
if len(drawer.layout) > 0 {
|
if len(drawer.layout) > 0 {
|
||||||
lastWord := &drawer.layout[len(drawer.layout) - 1]
|
lastWord := &drawer.layout[len(drawer.layout) - 1]
|
||||||
lastWord.whitespace = append (
|
lastWord.text = append (
|
||||||
lastWord.whitespace,
|
lastWord.text,
|
||||||
characterLayout {
|
characterLayout {
|
||||||
x: currentCharacterX.Round(),
|
x: currentCharacterX.Round(),
|
||||||
})
|
})
|
||||||
|
@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo/input"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
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/textmanip"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||||
|
|
||||||
@ -341,13 +342,15 @@ func (element *TextBox) redo () {
|
|||||||
func (element *TextBox) draw () {
|
func (element *TextBox) draw () {
|
||||||
bounds := element.Bounds()
|
bounds := element.Bounds()
|
||||||
|
|
||||||
// FIXME: take index into account
|
|
||||||
state := theme.PatternState {
|
state := theme.PatternState {
|
||||||
Disabled: !element.Enabled(),
|
Disabled: !element.Enabled(),
|
||||||
Focused: element.Focused(),
|
Focused: element.Focused(),
|
||||||
}
|
}
|
||||||
pattern := element.theme.Pattern(theme.PatternSunken, state)
|
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)
|
artist.FillRectangle(element.core, pattern, bounds)
|
||||||
|
|
||||||
offset := bounds.Min.Add (image.Point {
|
offset := bounds.Min.Add (image.Point {
|
||||||
X: element.config.Padding() - element.scroll,
|
X: element.config.Padding() - element.scroll,
|
||||||
Y: element.config.Padding(),
|
Y: element.config.Padding(),
|
||||||
@ -362,7 +365,7 @@ func (element *TextBox) draw () {
|
|||||||
end := element.valueDrawer.PositionOf(canon.End).Add(offset)
|
end := element.valueDrawer.PositionOf(canon.End).Add(offset)
|
||||||
end.Y += element.valueDrawer.LineHeight().Round()
|
end.Y += element.valueDrawer.LineHeight().Round()
|
||||||
artist.FillRectangle (
|
artist.FillRectangle (
|
||||||
element.core,
|
innerCanvas,
|
||||||
accent,
|
accent,
|
||||||
image.Rectangle { start, end })
|
image.Rectangle { start, end })
|
||||||
}
|
}
|
||||||
@ -374,7 +377,7 @@ func (element *TextBox) draw () {
|
|||||||
theme.PatternForeground,
|
theme.PatternForeground,
|
||||||
theme.PatternState { Disabled: true })
|
theme.PatternState { Disabled: true })
|
||||||
element.placeholderDrawer.Draw (
|
element.placeholderDrawer.Draw (
|
||||||
element.core,
|
innerCanvas,
|
||||||
foreground,
|
foreground,
|
||||||
offset.Sub(textBounds.Min))
|
offset.Sub(textBounds.Min))
|
||||||
} else {
|
} else {
|
||||||
@ -383,7 +386,7 @@ func (element *TextBox) draw () {
|
|||||||
foreground := element.theme.Pattern (
|
foreground := element.theme.Pattern (
|
||||||
theme.PatternForeground, state)
|
theme.PatternForeground, state)
|
||||||
element.valueDrawer.Draw (
|
element.valueDrawer.Draw (
|
||||||
element.core,
|
innerCanvas,
|
||||||
foreground,
|
foreground,
|
||||||
offset.Sub(textBounds.Min))
|
offset.Sub(textBounds.Min))
|
||||||
}
|
}
|
||||||
@ -395,7 +398,7 @@ func (element *TextBox) draw () {
|
|||||||
cursorPosition := element.valueDrawer.PositionOf (
|
cursorPosition := element.valueDrawer.PositionOf (
|
||||||
element.dot.End)
|
element.dot.End)
|
||||||
artist.Line (
|
artist.Line (
|
||||||
element.core,
|
innerCanvas,
|
||||||
foreground, 1,
|
foreground, 1,
|
||||||
cursorPosition.Add(offset),
|
cursorPosition.Add(offset),
|
||||||
image.Pt (
|
image.Pt (
|
||||||
|
@ -3,6 +3,10 @@ package theme
|
|||||||
import "image/color"
|
import "image/color"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
|
|
||||||
|
// var backgroundPattern = artist.Gradient {
|
||||||
|
// First: uhex(0xFF0000FF),
|
||||||
|
// Second: uhex(0x00FF00FF),
|
||||||
|
// }
|
||||||
var accentPattern = artist.NewUniform(hex(0x408090FF))
|
var accentPattern = artist.NewUniform(hex(0x408090FF))
|
||||||
var backgroundPattern = artist.NewUniform(color.Gray16 { 0xAAAA })
|
var backgroundPattern = artist.NewUniform(color.Gray16 { 0xAAAA })
|
||||||
var foregroundPattern = artist.NewUniform(color.Gray16 { 0x0000 })
|
var foregroundPattern = artist.NewUniform(color.Gray16 { 0x0000 })
|
||||||
|
Reference in New Issue
Block a user