ludic.ui: a bar's min, max and value read without ui_attr's new null for a miss (ui_attr_float), and the action answer ring made full with the state - craft's bar kept a block a frame, pack/shop/journal kept one frame filling the ring
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8c72437ecc
commit
fc22c3f250
4 changed files with 17 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ function ct_part(ui_st: mut UiState, n: UiNode, cls: string, text: string) -> Ui
|
|||
# <progress value max> and <meter value min max>: 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
|
||||
|
|
|
|||
|
|
@ -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)) }
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue