summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md19
1 files changed, 16 insertions, 3 deletions
diff --git a/README.md b/README.md
index 0602024..f54ab82 100644
--- a/README.md
+++ b/README.md
@@ -208,8 +208,12 @@ the paragraph's own); `reveal` (only the first N glyphs drawn, the layout
still the whole text's: typewriter text costs nothing extra); and `caret`
(a byte index). The `Layout` is `w`, `h`, `lines`, `glyphs` (a glyph is a
codepoint) and `caret`: the left of the caret's glyph, the top of its line
-and the line's height. `f.host.textSize(scale, bytes)` and
-`textSizeIn(face, scale, bytes)` still measure one line.
+and the line's height. `sk.text.places(bytes, paragraph, out)` is the
+same layout with every byte's place in `out` (a `Caret` a byte and one for
+the end, each where a caret before that byte sits): what an editor draws
+ranges with and finds the byte under the pointer by, in one layout.
+`f.host.textSize(scale, bytes)` and `textSizeIn(face, scale, bytes)` still
+measure one line.
Advances are whole pixels at the size drawn (HarfBuzz's, each rounded), so
a width is not a multiple of the scale (ten digits are 80 px at scale 1,
@@ -261,8 +265,17 @@ _ = f.paragraph(box.x, box.y, line, .{ .width = box.w, .face = .sans, .reveal =
const done = s.shown >= sk.text.layout(line, .{ .width = box.w, .face = .sans }).glyphs; // in update too
// A caret and per-token colours and sizes in source text.
-const drawn = f.paragraph(x, y, source, .{ .face = .code, .spans = tokens, .caret = cursor });
+const src: sk.text.Paragraph = .{ .face = .code, .spans = tokens, .caret = cursor };
+const drawn = f.paragraph(x, y, source, src);
f.fill(sk.Rect{ .x = drawn.caret.x, .y = drawn.caret.y, .w = 1, .h = drawn.caret.h }, 0xffcc00);
+
+// The byte under the pointer (in update too; px, py from the paragraph's
+// x, y): the last whose line holds py and whose x is at or left of px.
+_ = sk.text.places(source, src, places); // a Caret a byte and one more
+var hit: ?usize = null;
+for (places[0..source.len], 0..) |c, i| {
+ if (py >= c.y and py < c.y + c.h and px >= c.x) hit = i;
+}
```
## Drawing shapes