code wiki / _hdl_build / nx_browser_forms_paint.nx
nx_browser_forms_paint.nx source
↩ module page · 60 lines · 2858 B
1// nx_browser_forms_paint.nx -- RENDER layer for the Nishi-browser form fields: draw a <input>/<textarea>
2// as a bordered box with its current value + a caret when focused (password fields masked). Composes the
3// shipped paint primitives (nx_paint_solid_rect + nx_paint_text) over the pure field state from
4// nx_browser_forms. The browser calls this in a post-layout OVERLAY pass (one call per field, with the
5// field's layout rect) -- decoupled from the CSS engine (which has no <input> styling). Pure framebuffer
6// so it is pixel-gate-provable (nx_browser_forms_render_gate). license_tier: ORIGINAL
7import "nx_browser_forms.nx"
8import "nx_paint_solid_rect.nx"
9import "nx_paint_text.nx"
10
11func bfp_col(c: *CssColor, r: i64, g: i64, b: i64, a: i64) -> i64 { c.r = r; c.g = g; c.b = b; c.a = a; return 0 }
12
13// draw field `fld` as a box at (x,y,w,h). focused=1 -> blue border + caret; else gray border. Returns 0.
14func bf_paint_field(fb: *Framebuffer, x: i64, y: i64, w: i64, h: i64, fld: *BrField, focused: i64) -> i64 {
15 // white field background
16 let bg: *CssColor = sys_mmap(NX_CSS_COLOR_BYTES) as *CssColor
17 bfp_col(bg, 255, 255, 255, 255)
18 nx_paint_solid_rect(fb, x, y, w, h, bg)
19 // border (1px), blue if focused else gray
20 let bc: *CssColor = sys_mmap(NX_CSS_COLOR_BYTES) as *CssColor
21 if focused == 1 { bfp_col(bc, 37, 99, 235, 255) } else { bfp_col(bc, 176, 176, 184, 255) }
22 nx_paint_solid_rect(fb, x, y, w, 1, bc)
23 let yb: i64 = y + h - 1
24 nx_paint_solid_rect(fb, x, yb, w, 1, bc)
25 nx_paint_solid_rect(fb, x, y, 1, h, bc)
26 let xr: i64 = x + w - 1
27 nx_paint_solid_rect(fb, xr, y, 1, h, bc)
28 // value text (mask password with '*'); left pad 5, top pad 4
29 let tx: i64 = x + 5
30 let ty: i64 = y + 4
31 let tc: *CssColor = sys_mmap(NX_CSS_COLOR_BYTES) as *CssColor
32 bfp_col(tc, 28, 28, 30, 255)
33 let vis: i64 = fld.val_len
34 if fld.kind == BF_K_PASSWORD {
35 // masked bullets (font-independent): one small filled dot per char (the '••••' look)
36 var d: i64 = 0
37 while d < vis {
38 let dx: i64 = tx + d * NX_PAINT_TEXT_CELL_W
39 nx_paint_solid_rect(fb, dx, ty + 2, 3, 3, tc)
40 d = d + 1
41 }
42 } else {
43 let disp: *u8 = sys_mmap(vis + 8)
44 var i: i64 = 0
45 while i < vis { disp[i] = fld.val[i]; i = i + 1 }
46 if vis > 0 { nx_paint_text(fb, tx, ty, disp, vis, tc) }
47 }
48 // caret after the value when focused (cell width = NX_PAINT_TEXT_CELL_W)
49 if focused == 1 {
50 let caret_x: i64 = tx + vis * NX_PAINT_TEXT_CELL_W
51 let cc: *CssColor = sys_mmap(NX_CSS_COLOR_BYTES) as *CssColor
52 bfp_col(cc, 28, 28, 30, 255)
53 var ch: i64 = h - 6
54 if ch < 4 { ch = 4 }
55 nx_paint_solid_rect(fb, caret_x, y + 3, 1, ch, cc)
56 }
57 return 0
58}
59
60func main() -> i64 { return 0 }