Skip to content

Commit 03cc4d6

Browse files
committed
pict: repairs for line numbering and "paragraph" text alignment
Bring line-number styling closer to Scribble styling. Also, text alignment via `beside` with `~attach: #'paragraph` did not work right for scaled picts.
1 parent 69730dc commit 03cc4d6

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

rhombus-pict-lib/rhombus/pict/private/last.rhm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,17 @@ fun
6060
let last_handle = rkt.#{pict-last}(h1)
6161
if last_handle
6262
| let (x, y) = rkt.#{lt-find}(h1, last_handle)
63+
let (x2, y2) = rkt.#{rb-find}(h1, last_handle)
6364
let last_p = path_end(last_handle)
64-
let last_p_distinct = rkt.inset(last_p, 0, 0, 0, 0)
65+
let lw = rkt.#{pict-width}(last_p)
66+
let lh = rkt.#{pict-height}(last_p)
67+
let last_p_distinct = rkt.scale(rkt.inset(last_p, 0, 0, 0, 0),
68+
if lw .= 0
69+
| 1
70+
| (x2 - x) / lw,
71+
if lh .= 0
72+
| 1
73+
| (y2 - y) / lh)
6574
let h2_distinct = rkt.inset(h2, 0, 0, 0, 0)
6675
let p = rkt_append(sep, last_p_distinct, h2_distinct)
6776
let (ldx, ldy) = rkt.#{lt-find}(p, last_p_distinct)

rhombus-pict-lib/rhombus/pict/rhombus.rhm

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#lang rhombus/static/and_meta
22
import:
3+
rhombus/rx open
34
pict open
45
pict/text open
56
shrubbery/render
@@ -38,18 +39,28 @@ fun rtt(str_s) :~ Pict:
3839
def (render_line,
3940
render_block):
4041
@render.make(~render:
41-
fun (kind, str):
42+
fun (kind, str :~ String):
4243
let p :~ Pict:
43-
if kind == #'variable
44-
| italicly: rtt(str)
45-
| rtt(str)
44+
match kind
45+
| #'variable:
46+
italicly: rtt(str)
47+
| #'lineno:
48+
recur loop (str :~ String = str ++ " "):
49+
match rx'" "+'.match_range_in(str)
50+
| RXMatch(s..e, _, _):
51+
beside.baseline(loop(str.substring(0..s)),
52+
tt(str.substring(s..e)),
53+
loop(str.substring(e..str.length())))
54+
| ~else: t(str)
55+
| ~else:
56+
rtt(str)
4657
match current_rhombus_colorize() && kind
4758
| #'value: p.colorize(current_literal_color())
4859
| #'result: p.colorize(current_result_color())
4960
| #'identifier || #'plain: p.colorize(current_identifier_color())
5061
| #'paren: p.colorize(current_paren_color())
5162
| #'comment: p.colorize(current_comment_color())
52-
| #'lineno: beside.baseline(p.colorize("blue").scale(0.8), rtt(" "))
63+
| #'lineno: p.colorize("blue").scale(0.8)
5364
| ~else: p
5465
~render_in_space:
5566
fun (space, str, od,

0 commit comments

Comments
 (0)