mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 00:45:35 +00:00
text: add io.Reader Layout method to Shaper
use them for Editor, which is no longer required to construct a string for laying out its content. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+4
-6
@@ -273,13 +273,11 @@ func (e *Editor) layout(gtx *layout.Context, sh text.Shaper) {
|
||||
}
|
||||
e.shapes = e.shapes[:0]
|
||||
for {
|
||||
start, end, layout, off, ok := it.Next()
|
||||
_, _, layout, off, ok := it.Next()
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
// TODO: remove
|
||||
str := e.rr.String()[start:end]
|
||||
path := sh.Shape(gtx, e.font, str, layout)
|
||||
path := sh.Shape(gtx, e.font, layout)
|
||||
e.shapes = append(e.shapes, line{off, path})
|
||||
}
|
||||
|
||||
@@ -433,9 +431,9 @@ 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) {
|
||||
txt := e.rr.String()
|
||||
e.rr.Reset()
|
||||
opts := text.LayoutOptions{MaxWidth: e.maxWidth}
|
||||
lines := s.Layout(c, font, txt, opts)
|
||||
lines, _ := s.Layout(c, font, &e.rr, opts)
|
||||
dims := linesDimens(lines)
|
||||
for i := 0; i < len(lines)-1; i++ {
|
||||
// To avoid layout flickering while editing, assume a soft newline takes
|
||||
|
||||
Reference in New Issue
Block a user