code wiki / _hdl_build / nx_brand_spacescale.nx
nx_brand_spacescale.nx source
↩ module page · 35 lines · 1658 B
1// nx_brand_spacescale.nx -- generate a SPACING SCALE (the 4/8pt-grid rhythm) from a base unit: space|1..5 =
2// 1x/2x/3x/5x/8x base (a balanced ramp, every step ON the grid). No-float; valid .brand fragment that feeds the
3// token SSOT and passes the R2 spacing-grid guard BY CONSTRUCTION. REUSE: nx_brand_tokens (bt_app). Library.
4// 100% sovereign. license_tier: ORIGINAL
5import "nx_syscalls.nx"
6import "nx_brand_tokens.nx"
7
8func ss_put_int(out: *u8, pos: i64, cap: i64, v: i64) -> i64 {
9 if v == 0 { if pos < cap { out[pos] = 48 as u8 } return pos + 1 }
10 let d: *u8 = sys_mmap(24); var m: i64 = v; var k: i64 = 0
11 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
12 var p: i64 = pos; var i: i64 = k - 1
13 while i >= 0 { if p < cap { out[p] = d[i] } p = p + 1; i = i - 1 }
14 return p
15}
16func ss_emit_one(out: *u8, pos: i64, cap: i64, name: *u8, px: i64) -> i64 {
17 var q: i64 = pos
18 q = bt_app(out, q, cap, "token|space|" as *u8)
19 q = bt_app(out, q, cap, name)
20 q = bt_app(out, q, cap, "|" as *u8)
21 q = ss_put_int(out, q, cap, px)
22 q = bt_app(out, q, cap, "px\n" as *u8)
23 return q
24}
25// emit a 5-step spacing scale on the `base_px` grid into out (a .brand fragment); return length.
26func ss_emit_scale(base_px: i64, out: *u8, cap: i64) -> i64 {
27 var p: i64 = 0
28 p = ss_emit_one(out, p, cap, "1" as *u8, base_px * 1)
29 p = ss_emit_one(out, p, cap, "2" as *u8, base_px * 2)
30 p = ss_emit_one(out, p, cap, "3" as *u8, base_px * 3)
31 p = ss_emit_one(out, p, cap, "4" as *u8, base_px * 5)
32 p = ss_emit_one(out, p, cap, "5" as *u8, base_px * 8)
33 if p < cap { out[p] = 0 as u8 }
34 return p
35}