diff --git a/packages/ludic.ui/backend.ludic b/packages/ludic.ui/backend.ludic index 584d735e..9d59d10c 100644 --- a/packages/ludic.ui/backend.ludic +++ b/packages/ludic.ui/backend.ludic @@ -43,7 +43,7 @@ export state UiState { mm_ivals: []Val = null ev_depth: int = 0 # eval.ludic: a call's arguments, in lists kept one a depth ev_args: []Val = new []Val - @max(64) ev_ring: []Val = new []Val # eval.ludic: calls' answers while an action runs, EV_RING of them + @max(64) ev_ring: []Val = ev_ring_new() # eval.ludic: calls' answers while an action runs, EV_RING of them, made with the state ev_ring_at: int = 0 cv_texts: []string = new []string # units_pieces.ludic: a value's var() pieces, kept tx_pieces: [][]string = new [][]string # eval_text.ludic: a text's pieces, a list a depth diff --git a/packages/ludic.ui/controls_build.ludic b/packages/ludic.ui/controls_build.ludic index 0ebb8779..18f6122d 100644 --- a/packages/ludic.ui/controls_build.ludic +++ b/packages/ludic.ui/controls_build.ludic @@ -20,11 +20,11 @@ function ct_part(ui_st: mut UiState, n: UiNode, cls: string, text: string) -> Ui # and : a track with a fill as far as the value function ct_build_bar(ui_st: mut UiState, n: UiNode) -> void { n.dir = UI_ROW - let lo = Value.as_float(ui_attr(n, "min")) - var hi = Value.as_float(ui_attr(n, "max")) + let lo = ui_attr_float(n, "min", 0.0) + var hi = ui_attr_float(n, "max", 0.0) if hi <= lo { hi = lo + 1.0 } let fill = ct_part(ui_st, n, "ui-fill", "") - fill.w_pct = Math.clamp((Value.as_float(ui_attr(n, "value")) - lo) / (hi - lo), 0.0, 1.0) * 100.0 + fill.w_pct = Math.clamp((ui_attr_float(n, "value", 0.0) - lo) / (hi - lo), 0.0, 1.0) * 100.0 ui_kept(n.children, fill) } function ct_build(ui_st: mut UiState, n: UiNode) -> void { @@ -54,10 +54,10 @@ function ct_build(ui_st: mut UiState, n: UiNode) -> void { } } function ct_build_range(ui_st: mut UiState, n: UiNode) -> void { - let lo = Value.as_float(ui_attr(n, "min")) - var hi = Value.as_float(ui_attr(n, "max")) + let lo = ui_attr_float(n, "min", 0.0) + var hi = ui_attr_float(n, "max", 0.0) if hi <= lo { hi = lo + 1.0 } - let v = Value.as_float(ui_attr(n, "value")) + let v = ui_attr_float(n, "value", 0.0) let track = ct_part(ui_st, n, "ui-track", "") let fill = ct_part(ui_st, n, "ui-fill", "") fill.w_pct = Math.clamp((v - lo) / (hi - lo), 0.0, 1.0) * 100.0 diff --git a/packages/ludic.ui/eval.ludic b/packages/ludic.ui/eval.ludic index c30df4d4..49e1499c 100644 --- a/packages/ludic.ui/eval.ludic +++ b/packages/ludic.ui/eval.ludic @@ -77,5 +77,10 @@ function ev_into(ui_st: mut UiState) -> Val { return ring[at] } const EV_RING: int = 64 +function ev_ring_new() -> []Val { + let l = new []Val + for i in 0 .. EV_RING { push(l, Value.null()) } + return l +} function ui_eval_text(ui_st: mut UiState, x: UiExpr, e: UiEnv) -> string { return vl_text(ui_eval(ui_st, x, e)) } function ui_eval_bool(ui_st: mut UiState, x: UiExpr, e: UiEnv) -> bool { return vl_truthy(ui_eval(ui_st, x, e)) } diff --git a/packages/ludic.ui/native.ludic b/packages/ludic.ui/native.ludic index f4a69575..0a040561 100644 --- a/packages/ludic.ui/native.ludic +++ b/packages/ludic.ui/native.ludic @@ -94,6 +94,11 @@ export function ui_attr_has(n: UiNode, key: string) -> bool { } return false } +# an attribute as a number, `none` when it is not there - without ui_attr's new null for a miss +export function ui_attr_float(n: UiNode, key: string, none: float) -> float { + if not ui_attr_has(n, key) { return none } + return Value.as_float(ui_attr(n, key)) +} export function ui_attr_text(n: UiNode, key: string) -> string { if n.akeys == null { return "" } for i in 0 .. len(n.akeys) {