Phase 4: canvas apply_prop for Stock/Instrumentation (lightgui-designer)
A Phase 4 block before the generic branches routes a Stock/Inst widget's own table props through the named dispatch (pairs together from the model: y-min/y-max -> set_y_range, anchor-N-bar/price -> set_anchor, grid-rows/cols -> set_grid_size; singletons by table kind; Str "value" -> set_value_str so Seg displays are not parsed as f64). minimum/maximum, Double "value" and "position" are deliberately not intercepted -- the existing set_range / set_value / set_position branches already apply them. Props the archetype does not implement stay model-only (the model holds them; the generator emits them).
This commit is contained in:
1 parent
f4611498d9
commit
45b36e89ef
1 file changed
+157
@@ -1453,6 +1453,163 @@ pub fn apply_prop(app: &Shared, id: u64, name: &str, value: &str) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
// --- Phase 4 (§2.22 Stock/Instrumentation) ---
|
||||
// Props from a Stock/Inst widget's own table are applied through the
|
||||
// widget's named dispatch. This runs before the generic branches so
|
||||
// chart "grid-color" does not hit the calendar branch below and Seg
|
||||
// "value" (a string) does not hit the f64 branch. Pairs are read
|
||||
// from the model and applied together. Props the archetype does not
|
||||
// implement stay model-only (set_prop already stored them, and the
|
||||
// generator emits them).
|
||||
if (wtype.starts_with("Stock") || wtype.starts_with("Inst"))
|
||||
&& lightgui_core::props_for(&wtype)
|
||||
.iter()
|
||||
.any(|d| d.name == name)
|
||||
&& name != "minimum"
|
||||
&& name != "maximum"
|
||||
&& name != "position"
|
||||
&& !(name == "value"
|
||||
&& lightgui_core::find_prop(&wtype, "value")
|
||||
.is_some_and(|d| d.kind == lightgui_core::PropKind::Double))
|
||||
{
|
||||
// Pairs first.
|
||||
if name == "y-min" || name == "y-max" {
|
||||
let (ymin, ymax) = {
|
||||
let a = app.borrow();
|
||||
let Some(i) = a.find_index(id) else {
|
||||
return;
|
||||
};
|
||||
let get = |n: &str, dflt: f64| {
|
||||
a.items[i]
|
||||
.model
|
||||
.props
|
||||
.get(n)
|
||||
.and_then(|v| v.parse::<f64>().ok())
|
||||
.unwrap_or(dflt)
|
||||
};
|
||||
(get("y-min", 0.0), get("y-max", 1.0))
|
||||
};
|
||||
let mut a = app.borrow_mut();
|
||||
if let Some(i) = a.find_index(id) {
|
||||
a.items[i].wdg.set_y_range(ymin, ymax);
|
||||
}
|
||||
drop(a);
|
||||
redraw_canvas(app);
|
||||
return;
|
||||
}
|
||||
if let Some(rest) = name.strip_prefix("anchor-") {
|
||||
// anchor-N-bar / anchor-N-price (N = 1..=3).
|
||||
if let Some(n) = rest.chars().next().and_then(|c| c.to_digit(10)) {
|
||||
if (1..=3).contains(&n) {
|
||||
let (bar, price) = {
|
||||
let a = app.borrow();
|
||||
let Some(i) = a.find_index(id) else {
|
||||
return;
|
||||
};
|
||||
let get = |sfx: &str, dflt: f64| {
|
||||
a.items[i]
|
||||
.model
|
||||
.props
|
||||
.get(&format!("anchor-{n}-{sfx}"))
|
||||
.and_then(|v| v.parse::<f64>().ok())
|
||||
.unwrap_or(dflt)
|
||||
};
|
||||
(get("bar", 0.0), get("price", 100.0))
|
||||
};
|
||||
let mut a = app.borrow_mut();
|
||||
if let Some(i) = a.find_index(id) {
|
||||
a.items[i].wdg.set_anchor((n - 1) as usize, bar, price);
|
||||
}
|
||||
drop(a);
|
||||
redraw_canvas(app);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if name == "grid-rows" || name == "grid-cols" {
|
||||
let (cols, rows) = {
|
||||
let a = app.borrow();
|
||||
let Some(i) = a.find_index(id) else {
|
||||
return;
|
||||
};
|
||||
let get = |n: &str, dflt: i32| {
|
||||
a.items[i]
|
||||
.model
|
||||
.props
|
||||
.get(n)
|
||||
.and_then(|v| v.parse::<i32>().ok())
|
||||
.unwrap_or(dflt)
|
||||
};
|
||||
(get("grid-cols", 2), get("grid-rows", 3))
|
||||
};
|
||||
let mut a = app.borrow_mut();
|
||||
if let Some(i) = a.find_index(id) {
|
||||
a.items[i].wdg.set_grid_size(cols, rows);
|
||||
}
|
||||
drop(a);
|
||||
redraw_canvas(app);
|
||||
return;
|
||||
}
|
||||
// Singletons, by the table kind.
|
||||
if name == "value" {
|
||||
// Str-kind value (Seg displays): the f64 branch below would
|
||||
// parse it as 0.0.
|
||||
let mut a = app.borrow_mut();
|
||||
if let Some(i) = a.find_index(id) {
|
||||
a.items[i].wdg.set_value_str(value);
|
||||
}
|
||||
drop(a);
|
||||
redraw_canvas(app);
|
||||
return;
|
||||
}
|
||||
let kind = lightgui_core::find_prop(&wtype, name).map(|d| d.kind);
|
||||
match kind {
|
||||
Some(lightgui_core::PropKind::Color) => {
|
||||
if let Some((r, g, b)) = parse_color(value) {
|
||||
let mut a = app.borrow_mut();
|
||||
if let Some(i) = a.find_index(id) {
|
||||
a.items[i]
|
||||
.wdg
|
||||
.set_named_color(name, Srgb::new(r, g, b));
|
||||
}
|
||||
drop(a);
|
||||
}
|
||||
}
|
||||
Some(lightgui_core::PropKind::Double) => {
|
||||
let v = value.parse::<f64>().unwrap_or(0.0);
|
||||
let mut a = app.borrow_mut();
|
||||
if let Some(i) = a.find_index(id) {
|
||||
a.items[i].wdg.set_named_double(name, v);
|
||||
}
|
||||
drop(a);
|
||||
}
|
||||
Some(lightgui_core::PropKind::Int) => {
|
||||
let v = value.parse::<i32>().unwrap_or(0);
|
||||
let mut a = app.borrow_mut();
|
||||
if let Some(i) = a.find_index(id) {
|
||||
a.items[i].wdg.set_named_int(name, v);
|
||||
}
|
||||
drop(a);
|
||||
}
|
||||
Some(lightgui_core::PropKind::Bool) => {
|
||||
let mut a = app.borrow_mut();
|
||||
if let Some(i) = a.find_index(id) {
|
||||
a.items[i].wdg.set_named_bool(name, value == "true");
|
||||
}
|
||||
drop(a);
|
||||
}
|
||||
Some(lightgui_core::PropKind::Str) => {
|
||||
let mut a = app.borrow_mut();
|
||||
if let Some(i) = a.find_index(id) {
|
||||
a.items[i].wdg.set_named_string(name, value);
|
||||
}
|
||||
drop(a);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
redraw_canvas(app);
|
||||
return;
|
||||
}
|
||||
if name == "value" {
|
||||
let v = value.parse::<f64>().unwrap_or(0.0);
|
||||
let mut a = app.borrow_mut();
|
||||
|
||||
Reference in new issue
Block a user