L
ling-wallet
↓ 0 downloadsLing Wallet: a post-quantum privacy-coin wallet, full node and HyperTorus miner for LNG
Keywords wallet, cryptocurrency, lng, node, miner, ling
lingfu install ling-walletCode / Files (116)
ling/ui/gfx.ling
# gfx.ling — LingStation line-work primitives on top of the px_* builtins:
# outlines, corner brackets, hatching, tile lettering, framed panels, badges.
# A rect is passed as x, y, w, h; functions that hand one back return [x, y, w, h].
fn fill(x, y, w, h, c) {
if w > 0 && h > 0 { px_rect(x, y, w, h, c) }
}
fn fill_a(x, y, w, h, c, a) {
if w > 0 && h > 0 { px_rect(x, y, w, h, c, a) }
}
fn hline(x, y, w, c, a) {
if w > 0 { px_rect(x, y, w, 1, c, a) }
}
fn vline(x, y, h, c, a) {
if h > 0 { px_rect(x, y, 1, h, c, a) }
}
fn outline(x, y, w, h, c, a) {
if w > 0 && h > 0 { px_outline(x, y, w, h, c, a) }
}
# Corner brackets with arm length n.
fn brackets(x, y, w, h, n0, c, a) {
bind n = max(1, min(n0, min(floor(w / 2), floor(h / 2))))
bind x1 = x + w - 1
bind y1 = y + h - 1
px_rect(x, y, n, 1, c, a)
px_rect(x, y + 1, 1, n - 1, c, a)
px_rect(x1 - n + 1, y, n, 1, c, a)
px_rect(x1, y + 1, 1, n - 1, c, a)
px_rect(x, y1, n, 1, c, a)
px_rect(x, y1 - n + 1, 1, n - 1, c, a)
px_rect(x1 - n + 1, y1, n, 1, c, a)
px_rect(x1, y1 - n + 1, 1, n - 1, c, a)
}
# 1 px hatch lines; rising = 45 degrees up to the right.
fn hatch(x, y, w, h, c, rising, sp, a) {
if w >= 1 && h >= 1 { px_hatch(x, y, w, h, c, sel(rising, 45, 0 - 45), sp, a) }
}
fn cross(x, y, w, h, c, sp, a) {
hatch(x, y, w, h, c, true, sp, a)
hatch(x, y, w, h, c, false, sp, a)
}
fn line(x0, y0, x1, y1, c, a) { px_line(x0, y0, x1, y1, c, a) }
fn disc(cx, cy, r, c, a) { px_disc(cx, cy, r, c, a) }
fn ring(cx, cy, r, c, a) { px_ring(cx, cy, r, c, a) }
# Soft glow: a few stacked translucent discs.
fn glow(cx, cy, r, c, a) {
px_disc(cx, cy, r, c, a * 0.25)
px_disc(cx, cy, r * 0.6, c, a * 0.35)
px_disc(cx, cy, r * 0.3, c, a * 0.5)
}
# One letter in a square tile.
fn tile(x, y, s, ch, col, on) { tile_word(x, y, s, ch, col, on) }
fn tile_word_w(s, text) { return str_len(text) * (s + 1) - 1 }
# A word, one letter per tile (spaces leave a gap); returns the width.
# The sidebar and every panel title run through here each frame, so the
# per-word font metrics and colours are worked out once, not per letter.
fn tile_word(x, y, s, text, col, on) {
bind up = str_upper(text)
bind n = str_len(up)
bind size = max(8, round(s * 0.8))
bind tc = sel(on, C_TEXT_STRONG, lift(col, 0.3))
bind top = y + s / 2 + t_cap(F_HEAD, size) / 2 - list_get(FONT_ASC, F_HEAD) * size
bind arm = floor(s * 0.28)
bind i = 0
while i < n {
bind ch = substr(up, i, 1)
if ch != " " {
bind tx = x + i * (s + 1)
if on { px_hatch(tx + 1, y + 1, s - 2, s - 2, col, 45, 3, 0.55) }
px_outline(tx, y, s, s, col, 0.55)
if s >= 16 { brackets(tx, y, s, s, arm, col, 1) }
px_text(F_HEAD, tx + round((s - font_width(F_HEAD, size, ch)) / 2), top, size, tc, ch)
}
bind i = i + 1
}
return tile_word_w(s, text)
}
# Double-rule framed panel with corner brackets, a tile-lettered title tab and a
# crosshatch accent. Returns the inner content rect.
fn panel(x, y, w, h, title, col) {
fill(x, y, w, h, C_PANEL)
outline(x, y, w, h, C_LINE_SOFT, 1)
outline(x + 3, y + 3, w - 6, h - 6, C_LINE_FAINT, 1)
brackets(x - 1, y - 1, w + 2, h + 2, 10, col, 0.9)
cross(x + w - 60, y + 6, 48, 6, col, 3, 0.35)
if title != "" {
bind s = 14
bind tw = tile_word_w(s, title) + 12
fill(x + 14, y - 8, tw, 16, C_BG)
tile_word(x + 20, y - 7, s, title, col, false)
}
return [x + 20, y + 24, w - 40, h - 40]
}
# Small outlined badge centred on `mid`; returns its width.
fn badge(x, mid, text, col, filled) {
bind w = label_w(text) + 14
if filled {
fill_a(x, mid - 10, w, 20, col, 0.16)
hatch(x + 1, mid - 9, w - 2, 18, col, true, 3, 0.25)
}
outline(x, mid - 10, w, 20, col, 0.85)
label(x + 7, mid + t_cap(F_UI, 13) / 2, text, lift(col, 0.25))
return w
}
fn badge_w(text) { return label_w(text) + 14 }
fn in_rect(px, py, x, y, w, h) { return px >= x && py >= y && px < x + w && py < y + h }