Phase 4: live-apply for Stock/Instrumentation props in the canvas
xframe_core_apply_prop gains a Phase 4 block, first in the type-specific section: for Stock*/Inst* classes, pairs apply together from the model (minimum/maximum -> set_range, y-min/y-max -> set_y_range, anchor-N-bar/ price -> set_anchor) and every other table prop goes through the named dispatch in registry.h (kind from find_prop). Unhandled props fall through to the generic branches. background drives set_bg_color via set_named_color(bg-color) for these classes, and a non-numeric value falls back to set_value_str (Seg displays). props.h must be included before X11 headers (Xlib.h defines Bool as int, breaking PropKind::Bool) and the Bool kind is the else branch, never named. Also fixes -Wmisleading-indentation in StockSectorComparison::set_labels_text.
This commit is contained in:
1 parent
e68fd2557d
commit
10f2b74a58
2 files changed
+87
-4
No files matched your search
@@ -13,6 +13,11 @@
|
||||
// every canvas event — including Expose — is consumed by GDK first.
|
||||
// The GDK handler is the only path that receives them.
|
||||
|
||||
// Phase 4: props.h FIRST -- <X11/Xlib.h> #defines Bool as int (see
|
||||
// xframe_canvas_core.h), which breaks the PropKind::Bool enumerator
|
||||
// if props.h is parsed after it.
|
||||
#include "props.h"
|
||||
|
||||
#include "xframe_canvas_core.h"
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
@@ -734,6 +739,10 @@ bool xframe_core_apply_prop(XFrameCanvasCore* c, int id,
|
||||
cls == "TMemo" || cls == "GtkPasswordEntry" ||
|
||||
cls == "GtkSearchEntry")
|
||||
p->wdg->set_fill_color(f);
|
||||
// Phase 4: Stock/Inst widgets draw their body from
|
||||
// bg_color_, not the style fill.
|
||||
if (cls.rfind("Stock", 0) == 0 || cls.rfind("Inst", 0) == 0)
|
||||
p->wdg->set_named_color("bg-color", f);
|
||||
}
|
||||
}
|
||||
if (name == "font-name" || name == "font-size" ||
|
||||
@@ -746,9 +755,78 @@ bool xframe_core_apply_prop(XFrameCanvasCore* c, int id,
|
||||
if (name == "font-underline" || name == "font-strikeout")
|
||||
return true;
|
||||
// --- type-specific setters (via the C2 IWidget virtuals) ---
|
||||
// --- Phase 4 Stock/Instrumentation (proposal 2.22, Flag 12) ---
|
||||
// For Stock*/Inst* classes the Inspector props are the per-widget
|
||||
// tables in props.h; they live-apply through the named dispatch in
|
||||
// registry.h (one virtual per arg type, the Holder forwards to the
|
||||
// widget's real setter). This block runs first so the generic GTK
|
||||
// branches below (grid-color, color, fill-color, position, value)
|
||||
// keep their behaviour for every other class. When the named
|
||||
// dispatch has no setter for the prop, fall through to those
|
||||
// branches (autosize, min/max constraints, ...).
|
||||
{
|
||||
const std::string& cls = lg::kWidgetNames[p->type];
|
||||
if (cls.rfind("Stock", 0) == 0 || cls.rfind("Inst", 0) == 0) {
|
||||
// Pairs: one setter takes two values, so the two props are
|
||||
// applied together from the model (never a half-applied pair).
|
||||
if (name == "minimum" || name == "maximum") {
|
||||
double mn = prop_double(p, "minimum", 0.0);
|
||||
double mx = prop_double(p, "maximum", 100.0);
|
||||
if (p->wdg->set_range(mn, mx)) return true;
|
||||
}
|
||||
if (name == "y-min" || name == "y-max") {
|
||||
double lo = prop_double(p, "y-min", 0.0);
|
||||
double hi = prop_double(p, "y-max", 1.0);
|
||||
if (p->wdg->set_y_range(lo, hi)) return true;
|
||||
}
|
||||
if (name.rfind("anchor-", 0) == 0 && name.size() > 7 &&
|
||||
name[7] >= '1' && name[7] <= '3') {
|
||||
int n = name[7] - '0';
|
||||
std::string bar_key =
|
||||
"anchor-" + std::to_string(n) + "-bar";
|
||||
std::string price_key =
|
||||
"anchor-" + std::to_string(n) + "-price";
|
||||
int bar = prop_int(p, bar_key, (n - 1) * 10);
|
||||
double price = prop_double(p, price_key, 100.0);
|
||||
if (p->wdg->set_anchor(n - 1, bar, price)) return true;
|
||||
}
|
||||
const PropDef* d = find_prop(cls, name);
|
||||
if (d) {
|
||||
bool handled = false;
|
||||
if (d->kind == PropKind::Color) {
|
||||
Srgb col;
|
||||
if (parse_hex_color(value, col))
|
||||
handled = p->wdg->set_named_color(name, col);
|
||||
} else if (d->kind == PropKind::Double) {
|
||||
double v = 0;
|
||||
if (parse_double_strict(value, v))
|
||||
handled = p->wdg->set_named_double(name, v);
|
||||
} else if (d->kind == PropKind::Int) {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v))
|
||||
handled = p->wdg->set_named_int(name, v);
|
||||
} else if (d->kind == PropKind::Str) {
|
||||
handled = p->wdg->set_named_string(name, value);
|
||||
} else if (d->kind == PropKind::Enum) {
|
||||
// No Enum props in the Phase 4 tables; stored only.
|
||||
} else {
|
||||
// Bool. PropKind::Bool cannot be named here: Xlib.h
|
||||
// #defines Bool as int (see xframe_canvas_core.h),
|
||||
// so the Bool case is the else (after Color/Double/
|
||||
// Int/Str/Enum above).
|
||||
handled = p->wdg->set_named_bool(name, value == "true");
|
||||
}
|
||||
if (handled) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (name == "value") {
|
||||
double v = 0;
|
||||
if (parse_double_strict(value, v)) return p->wdg->set_value(v);
|
||||
// Phase 4: Seg displays take a string value (set_value(string));
|
||||
// the Phase 4 block above already handled it for Stock/Inst
|
||||
// classes, this is the same fallback for any other class.
|
||||
p->wdg->set_value_str(value);
|
||||
return true;
|
||||
}
|
||||
if (name == "minimum" || name == "maximum") {
|
||||
|
||||
@@ -84,10 +84,15 @@ add_series("SYM-A", xframe::make_seeded_series(60, 42));
|
||||
// Pipe-separated form of set_labels, for the Inspector/generator
|
||||
// (a single string prop): "Tech|Energy|..." -> labels_.
|
||||
void set_labels_text(const std::string& text) {
|
||||
labels_.clear(); size_t start = 0;
|
||||
while (true) { size_t pos = text.find('|', start);
|
||||
labels_.push_back(text.substr(start, pos == std::string::npos ? std::string::npos : pos - start));
|
||||
if (pos == std::string::npos) break; start = pos + 1; }
|
||||
labels_.clear();
|
||||
size_t start = 0;
|
||||
while (true) {
|
||||
size_t pos = text.find('|', start);
|
||||
labels_.push_back(text.substr(
|
||||
start, pos == std::string::npos ? std::string::npos : pos - start));
|
||||
if (pos == std::string::npos) break;
|
||||
start = pos + 1;
|
||||
}
|
||||
}
|
||||
std::vector<std::string> labels() { return labels_; }
|
||||
std::vector<std::string> sector_names() { std::vector<std::string> out; for (size_t i = 0; i < series_.size(); ++i) { std::string lab = i < labels_.size() ? labels_[i] : "Other"; if (std::find(out.begin(), out.end(), lab) == out.end()) out.push_back(lab); } return out; }
|
||||
|
||||
Reference in new issue
Block a user