mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
text: remove SingleLine from LayoutOptions
Low level text layout should not deal with filtering newlines. Updates gio#61 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -81,12 +81,6 @@ func layoutText(buf *sfnt.Buffer, ppem fixed.Int26_6, str string, f *opentype, o
|
|||||||
}
|
}
|
||||||
for prev.idx < len(str) {
|
for prev.idx < len(str) {
|
||||||
c, s := utf8.DecodeRuneInString(str[prev.idx:])
|
c, s := utf8.DecodeRuneInString(str[prev.idx:])
|
||||||
nl := c == '\n'
|
|
||||||
if opts.SingleLine && nl {
|
|
||||||
nl = false
|
|
||||||
c = ' '
|
|
||||||
s = 1
|
|
||||||
}
|
|
||||||
a, ok := f.GlyphAdvance(buf, ppem, c)
|
a, ok := f.GlyphAdvance(buf, ppem, c)
|
||||||
if !ok {
|
if !ok {
|
||||||
prev.idx += s
|
prev.idx += s
|
||||||
@@ -99,7 +93,7 @@ func layoutText(buf *sfnt.Buffer, ppem fixed.Int26_6, str string, f *opentype, o
|
|||||||
x: prev.x + prev.adv,
|
x: prev.x + prev.adv,
|
||||||
valid: true,
|
valid: true,
|
||||||
}
|
}
|
||||||
if nl {
|
if c == '\n' {
|
||||||
// The newline is zero width; use the previous
|
// The newline is zero width; use the previous
|
||||||
// character for line measurements.
|
// character for line measurements.
|
||||||
prev.advs = append(prev.advs, 0)
|
prev.advs = append(prev.advs, 0)
|
||||||
|
|||||||
+1
-3
@@ -36,10 +36,8 @@ type Layout struct {
|
|||||||
|
|
||||||
// LayoutOptions specify the constraints of a text layout.
|
// LayoutOptions specify the constraints of a text layout.
|
||||||
type LayoutOptions struct {
|
type LayoutOptions struct {
|
||||||
// MaxWidth set the maximum width of the layout.
|
// MaxWidth is the available width of the layout.
|
||||||
MaxWidth int
|
MaxWidth int
|
||||||
// SingleLine specify that line breaks are ignored.
|
|
||||||
SingleLine bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Style is the font style.
|
// Style is the font style.
|
||||||
|
|||||||
+4
-3
@@ -5,6 +5,7 @@ package widget
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"math"
|
"math"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
@@ -399,7 +400,7 @@ func (e *Editor) moveCoord(c unit.Converter, pos image.Point) {
|
|||||||
|
|
||||||
func (e *Editor) layoutText(c unit.Converter, s *text.Shaper, font text.Font) ([]text.Line, layout.Dimensions) {
|
func (e *Editor) layoutText(c unit.Converter, s *text.Shaper, font text.Font) ([]text.Line, layout.Dimensions) {
|
||||||
txt := e.rr.String()
|
txt := e.rr.String()
|
||||||
opts := text.LayoutOptions{SingleLine: e.SingleLine, MaxWidth: e.maxWidth}
|
opts := text.LayoutOptions{MaxWidth: e.maxWidth}
|
||||||
textLayout := s.Layout(c, font, txt, opts)
|
textLayout := s.Layout(c, font, txt, opts)
|
||||||
lines := textLayout.Lines
|
lines := textLayout.Lines
|
||||||
dims := linesDimens(lines)
|
dims := linesDimens(lines)
|
||||||
@@ -463,8 +464,8 @@ func (e *Editor) deleteRuneForward() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Editor) append(s string) {
|
func (e *Editor) append(s string) {
|
||||||
if e.SingleLine && s == "\n" {
|
if e.SingleLine {
|
||||||
return
|
s = strings.ReplaceAll(s, "\n", "")
|
||||||
}
|
}
|
||||||
e.prepend(s)
|
e.prepend(s)
|
||||||
e.rr.caret += len(s)
|
e.rr.caret += len(s)
|
||||||
|
|||||||
Reference in New Issue
Block a user