Phase 4: named live-apply dispatch for Stock/Instrumentation (xframe-widgets)

Widget trait gains set_named_color/double/int/bool/string, set_y_range,
set_anchor and set_value_str (default: false = model-only). XGraph gains
axis/line/up/down/candle/annotation/text colours + line_width (per-kind
table defaults); the y-labels use axis_color and Line series use
line_width. InstrumentWidget gains brightness (C lamp factor
0.08+0.92*b/100 plumbed into draw_led/draw_panel_lamp/draw_beacon,
per-tier into draw_stack_light, channels+lens into draw_rgb_led),
decimal_places (LedDigits formatting) and stack tier brightness, plus
the full colour/level/on dispatch (lens/lit/dim routed per kind).
ChartWidget gains anchors + overlay colour and dispatches colours into
the XGraph (and any series present), view/axis props into the PlotView,
y-range and anchors. Toggle/Button dispatch "on" (checked / latched).
Props with no Rust counterpart (alarm bands, flash-rate/phase, switch
line-widths/positions, per-indicator colours, symbol/labels, etc.)
return false and stay model-only; the generator still emits them.
This commit is contained in:
cnmcdee committed 2026-11-30 14:57:51 +00:00
1 parent 8bbc094c62
commit f4611498d9
3 files changed
+540 -31

No files matched your search

+436 -30
View File
@@ -11,7 +11,7 @@
use xframe_core::draw::{draw_checkmark, draw_polished, draw_text_at, draw_text_centered, draw_text_left, draw_triangle_down, draw_triangle_left, draw_triangle_right, draw_triangle_up, text_width};
use xframe_core::{DrawTarget, Srgb, Style, StyleManager};
use crate::graph::XGraph;
use crate::graph::{SeriesKind, XGraph};
use crate::icons::load_icon;
use crate::state::{button, Key, Rect, WidgetState};
use crate::widget::{button_press, button_release_click, draw_button_body, key_activates, resolve_style, Archetype, Widget};
@@ -199,6 +199,18 @@ impl ButtonWidget {
}
archetype_impl!(ButtonWidget, Archetype::Button,
// Phase 4: "on" sets the latched state (stored; the Rust Button
// draw shows no latched visual). Button colours have no Rust field
// (the draw is style-driven) and stay model-only.
fn set_named_bool(&mut self, name: &str, v: bool) -> bool {
match name {
"on" => {
self.on = v;
true
}
_ => false,
}
}
fn set_direction(&mut self, d: i32) {
self.direction = d.clamp(0, 4);
}
@@ -395,6 +407,19 @@ impl ToggleWidget {
}
archetype_impl!(ToggleWidget, Archetype::Toggle,
// Phase 4: "on" flips the checkmark (live). Switch colours, key-in,
// lever/pointer line-widths and position/positions have no Rust
// field (the Toggle draw is a generic button + checkmark) and stay
// model-only.
fn set_named_bool(&mut self, name: &str, v: bool) -> bool {
match name {
"on" => {
self.set_checked(v);
true
}
_ => false,
}
}
fn checked(&self) -> bool {
self.checked
}
@@ -2278,6 +2303,12 @@ pub struct ChartWidget {
pub graph: XGraph,
/// Annotation overlay kind (Arrow, Trendline, FibRetracement, ...).
pub overlay: Option<String>,
/// Annotation anchor points (bar, price); C++ `set_anchors` /
/// `set_anchor`. Stored — the Rust chart draws no overlays yet.
pub anchors: [(f64, f64); 3],
/// Annotation overlay colour (C++ `set_color`); stored — the Rust
/// chart draws no overlays yet.
pub color: Srgb,
}
impl ChartWidget {
@@ -2296,6 +2327,24 @@ impl ChartWidget {
click_count: 0,
on_click_cb: None,
graph: XGraph::new_widget(name, kind, x, y, w, h),
anchors: [(0.0, 100.0), (10.0, 100.0), (20.0, 100.0)],
color: match kind {
"Arrow" => Srgb::new(200, 30, 30),
"Brush" => Srgb::new(200, 30, 200),
"Ellipse" => Srgb::new(0, 140, 120),
"FibExtension" => Srgb::new(180, 80, 0),
"FibRetracement" => Srgb::new(180, 120, 0),
"HorizontalLine" => Srgb::new(0, 120, 200),
"MeasureTool" => Srgb::new(0, 140, 120),
"ParallelChannel" => Srgb::new(0, 120, 200),
"Pitchfork" => Srgb::new(120, 60, 180),
"PriceLabel" => Srgb::new(0, 120, 200),
"Rectangle" => Srgb::new(0, 120, 200),
"TextAnnotation" => Srgb::new(160, 90, 0),
"Trendline" => Srgb::new(200, 30, 30),
"VerticalLine" => Srgb::new(120, 60, 180),
_ => Srgb::new(0, 120, 200),
},
overlay,
}
}
@@ -2311,6 +2360,134 @@ impl ChartWidget {
}
archetype_impl!(ChartWidget, Archetype::Chart,
// Phase 4 named dispatch (§2.22): colours go to the inner XGraph
// (and to any series already present, so they repaint); view and
// axis props go to the PlotView; anchors are stored. Props with no
// Rust counterpart (symbol, labels, annotation-text, base-value,
// baseline, bins, brick-size, window, the per-indicator colours)
// stay model-only (false).
fn set_named_color(&mut self, name: &str, c: Srgb) -> bool {
match name {
"grid-color" => {
self.graph.grid_color = c;
true
}
"axis-color" => {
self.graph.axis_color = c;
true
}
"line-color" => {
self.graph.line_color = c;
for s in &mut self.graph.series {
if s.kind == SeriesKind::Line {
s.color = c;
}
}
true
}
"up-color" => {
self.graph.up_color = c;
for s in &mut self.graph.series {
if matches!(s.kind, SeriesKind::OhlcBars | SeriesKind::Candlesticks) {
s.up_color = c;
}
}
true
}
"down-color" => {
self.graph.down_color = c;
for s in &mut self.graph.series {
if matches!(s.kind, SeriesKind::OhlcBars | SeriesKind::Candlesticks) {
s.down_color = c;
}
}
true
}
"candle-up-color" => {
self.graph.candle_up_color = c;
for s in &mut self.graph.series {
if s.kind == SeriesKind::Candlesticks {
s.up_color = c;
}
}
true
}
"candle-down-color" => {
self.graph.candle_down_color = c;
for s in &mut self.graph.series {
if s.kind == SeriesKind::Candlesticks {
s.down_color = c;
}
}
true
}
"annotation-color" => {
self.graph.annotation_color = c;
true
}
"text-color" => {
self.graph.text_color = c;
true
}
"color" => {
self.color = c;
true
}
_ => false,
}
}
fn set_named_double(&mut self, name: &str, v: f64) -> bool {
match name {
"view-first" => {
self.graph.view.first = v;
true
}
"view-count" => {
self.graph.view.count = v;
true
}
_ => false,
}
}
fn set_named_int(&mut self, name: &str, v: i32) -> bool {
match name {
"axis-width" => {
self.graph.view.axis_w = v.max(0);
true
}
"axis-height" => {
self.graph.view.axis_h = v.max(0);
true
}
"line-width" => {
self.graph.line_width = v.max(0);
true
}
_ => false,
}
}
fn set_named_bool(&mut self, name: &str, v: bool) -> bool {
match name {
"auto-y" => {
self.graph.view.auto_y = v;
true
}
_ => false,
}
}
fn set_y_range(&mut self, min: f64, max: f64) -> bool {
self.graph.view.y_min = min;
self.graph.view.y_max = max;
true
}
fn set_anchor(&mut self, i: usize, bar: f64, price: f64) -> bool {
if i < 3 {
self.anchors[i] = (bar, price);
true
} else {
false
}
}
fn sync_bounds(&mut self) {
let b = self.state.bounds;
self.graph.state.bounds = b;
@@ -3231,6 +3408,7 @@ fn draw_led(
label: &str,
rgb: (u8, u8, u8),
on: bool,
bright: i32,
white: u32,
dark: u32,
lead: u32,
@@ -3248,7 +3426,12 @@ fn draw_led(
target.set_foreground(lead);
target.fill_rect(cx - 10, lead_top, 4, lead_h);
target.fill_rect(cx + 6, lead_top, 4, lead_h);
let f = if on { 1.0 } else { 0.10 };
// C lamp factor: on scales with brightness, off is 0.10.
let f = if on {
0.08 + 0.92 * (bright.clamp(0, 100) as f64 / 100.0)
} else {
0.10
};
let col = (((rgb.0 as f64 * f) as u32) << 16)
| (((rgb.1 as f64 * f) as u32) << 8)
| ((rgb.2 as f64 * f) as u32);
@@ -3277,6 +3460,7 @@ fn draw_panel_lamp(
label: &str,
rgb: (u8, u8, u8),
on: bool,
bright: i32,
white: u32,
bezel: u32,
ring: u32,
@@ -3292,7 +3476,12 @@ fn draw_panel_lamp(
target.fill_arc(cx - r, cy - r, 2 * r, 2 * r, 0, 360 * 64);
target.set_foreground(ring);
target.fill_arc(cx - r + 3, cy - r + 3, 2 * (r - 3), 2 * (r - 3), 0, 360 * 64);
let f = if on { 1.0 } else { 0.10 };
// C lamp factor: on scales with brightness, off is 0.10.
let f = if on {
0.08 + 0.92 * (bright.clamp(0, 100) as f64 / 100.0)
} else {
0.10
};
let col = (((rgb.0 as f64 * f) as u32) << 16)
| (((rgb.1 as f64 * f) as u32) << 8)
| ((rgb.2 as f64 * f) as u32);
@@ -3318,18 +3507,19 @@ fn draw_beacon(target: &mut dyn DrawTarget, style: &Style, b: Rect, label: &str,
dark: u32,
amber: u32,
on: bool,
bright: i32,
) {
let sx = b.w as f64 / 720.0;
let sy = b.h as f64 / 480.0;
// Lamp off dims the beacon (C++ lamp on/off; off-factor as the stack tiers use).
let amber = if on {
amber
// C lamp factor: on scales with brightness, off is 0.10.
let f = if on {
0.08 + 0.92 * (bright.clamp(0, 100) as f64 / 100.0)
} else {
let f = 0.10;
((((amber >> 16) & 0xff) as f64 * f) as u32) << 16
| ((((amber >> 8) & 0xff) as f64 * f) as u32) << 8
| (((amber & 0xff) as f64 * f) as u32)
0.10
};
let amber = ((((amber >> 16) & 0xff) as f64 * f) as u32) << 16
| ((((amber >> 8) & 0xff) as f64 * f) as u32) << 8
| (((amber & 0xff) as f64 * f) as u32);
target.set_foreground(white);
target.fill_rect(b.x, b.y, b.w, b.h);
let cx = (b.x + b.x + b.w) / 2;
@@ -3390,6 +3580,9 @@ fn draw_stack_light(target: &mut dyn DrawTarget, style: &Style, b: Rect, label:
red_on: bool,
amber_on: bool,
green_on: bool,
red_bright: i32,
amber_bright: i32,
green_bright: i32,
) {
let sx = b.w as f64 / 720.0;
let sy = b.h as f64 / 480.0;
@@ -3404,14 +3597,19 @@ fn draw_stack_light(target: &mut dyn DrawTarget, style: &Style, b: Rect, label:
let (rr, rg, rb) = tier_rgb(red);
let (ar, ag, ab) = tier_rgb(amber);
let (gr, gg, gb) = tier_rgb(green);
let tiers: [(i32, i32, i32, bool, &str); 3] = [
(rr, rg, rb, red_on, "R"),
(ar, ag, ab, amber_on, "A"),
(gr, gg, gb, green_on, "G"),
let tiers: [(i32, i32, i32, bool, i32, &str); 3] = [
(rr, rg, rb, red_on, red_bright, "R"),
(ar, ag, ab, amber_on, amber_bright, "A"),
(gr, gg, gb, green_on, green_bright, "G"),
];
for (i, (r, g, bl, on, lab)) in tiers.iter().enumerate() {
for (i, (r, g, bl, on, bright, lab)) in tiers.iter().enumerate() {
let y = b.y + 8 + (i as i32) * (th + 4);
let f = if *on { 1.0 } else { 0.10 };
// C lamp factor per tier: on scales with that tier's brightness.
let f = if *on {
0.08 + 0.92 * ((*bright).clamp(0, 100) as f64 / 100.0)
} else {
0.10
};
let col = (((*r as f64 * f) as u32) << 16)
| (((*g as f64 * f) as u32) << 8)
| ((*bl as f64 * f) as u32);
@@ -3456,6 +3654,7 @@ fn draw_rgb_led(target: &mut dyn DrawTarget, style: &Style, b: Rect, label: &str
red_on: bool,
green_on: bool,
blue_on: bool,
bright: i32,
) {
let sx = b.w as f64 / 720.0;
let sy = b.h as f64 / 480.0;
@@ -3466,7 +3665,15 @@ fn draw_rgb_led(target: &mut dyn DrawTarget, style: &Style, b: Rect, label: &str
let r = (b.w.min(b.h) / 4).max(8);
target.set_foreground(dark);
target.fill_rect(cx - r - 8, cy - r - 8, 2 * r + 16, 2 * r + 16);
target.set_foreground(0xffff00);
// Lens brightness: the C factor applied to the lit lens when any
// channel is on (off is the dark plate colour, as before).
let lf = if red_on || green_on || blue_on {
0.08 + 0.92 * (bright.clamp(0, 100) as f64 / 100.0)
} else {
0.10
};
let lens = (((0xff as f64 * lf) as u32) << 16) | (((0xff as f64 * lf) as u32) << 8);
target.set_foreground(lens);
target.fill_arc(cx - r, cy - r, 2 * r, 2 * r, 0, 360 * 64);
let hr = (r / 4).max(2);
target.set_foreground(white);
@@ -3476,9 +3683,18 @@ fn draw_rgb_led(target: &mut dyn DrawTarget, style: &Style, b: Rect, label: &str
let cols: [u32; 3] = [red_ch, green_ch, blue_ch];
let sq = (20.0 * sx) as i32;
let syy = b.y + b.h - (40.0 * sy) as i32;
let cf = 0.08 + 0.92 * (bright.clamp(0, 100) as f64 / 100.0);
for i in 0..3 {
let sxx = cx - (33.0 * sx) as i32 + (i as i32) * (24.0 * sx) as i32;
target.set_foreground(if on[i] { cols[i] } else { dark });
let ch = if on[i] {
let c = cols[i];
((((c >> 16 & 0xff) as f64 * cf) as u32) << 16)
| ((((c >> 8 & 0xff) as f64 * cf) as u32) << 8)
| (((c & 0xff) as f64 * cf) as u32)
} else {
dark
};
target.set_foreground(ch);
target.fill_rect(sxx, syy, sq, sq);
target.set_foreground(outline);
target.draw_rect(sxx, syy, sq, sq);
@@ -4466,6 +4682,18 @@ pub struct InstrumentWidget {
/// Bar-meter marker width (C++ `InstBarMeter::marker_line_width_`, 3;
/// the Rust draw scales it by the horizontal factor).
pub marker_line_width: i32,
/// Lamp brightness 0..=100 (C++ `set_brightness`; Led / PanelLamp /
/// Beacon / RgbStatusLed). The draws scale the lit colour by
/// `0.08 + 0.92 * brightness / 100` when on, 0.10 when off.
pub brightness: i32,
/// LedDigits decimal places (C++ `set_decimal_places`; LedDigits1 = 0,
/// LedDigits2-6 = 1).
pub decimal_places: i32,
/// Stack-light per-tier brightness 0..=100 (C++
/// `set_red/amber/green_brightness`).
pub stack_red_brightness: i32,
pub stack_amber_brightness: i32,
pub stack_green_brightness: i32,
}
impl InstrumentWidget {
@@ -4672,6 +4900,17 @@ impl InstrumentWidget {
blue_on: false,
needle_line_width: 3,
marker_line_width: 3,
brightness: 100,
decimal_places: if kind == "LedDigits1" {
0
} else if kind.starts_with("LedDigits") {
1
} else {
0
},
stack_red_brightness: 100,
stack_amber_brightness: 100,
stack_green_brightness: 100,
}
}
pub fn new_widget(name: &str, kind: &str, x: i32, y: i32, w: i32, h: i32) -> InstrumentWidget {
@@ -5000,6 +5239,173 @@ impl InstrumentWidget {
}
archetype_impl!(InstrumentWidget, Archetype::Instrument,
// Phase 4 named dispatch (§2.22): colours route to the matching
// field (lens/lit/dim are per-kind: Led -> led_color, PanelLamp ->
// lamp_color, LedDigits -> seg7_*, Seg14/16 -> seg14/16_*); levels
// and values are the state value; on/brightness/line-widths are
// live fields. Alarm bands, flash-rate/phase and the BarMeter
// horizontal flag have no Rust field and stay model-only (false).
fn set_named_color(&mut self, name: &str, c: Srgb) -> bool {
match name {
"white-color" => self.white_color = c,
"face-color" => self.face_color = c,
"ink-color" => self.ink_color = c,
"red-color" => self.red_color = c,
"amber-color" => self.amber_color = c,
"green-color" => self.green_color = c,
"blue-color" => self.blue_color = c,
"dark-color" => self.dark_color = c,
"lead-color" => self.lead_color = c,
"bezel-color" => self.bezel_color = c,
"ring-color" => self.ring_color = c,
"outline-color" => self.outline_color = c,
"panel-color" => self.panel_color = c,
"tick-color" => self.tick_color = c,
"needle-color" => self.needle_color = c,
"pale-color" => self.pale_color = c,
"fill-color" => self.fill_color = c,
"grid-color" => self.grid_color = c,
"hover-color" => self.hover_color = c,
"beacon-color" => self.beacon_color = c,
"steel-color" => self.steel_color = c,
"surface-color" => self.surface_color = c,
"seg-bg-color" => self.seg_bg_color = c,
"seg-bezel-color" => self.seg_bezel_color = c,
"seg-label-color" => self.seg_label_color = c,
"segment-on-color" => self.segment_on_color = c,
"segment-off-color" => self.segment_off_color = c,
"stack-red-color" => self.stack_red_color = c,
"stack-amber-color" => self.stack_amber_color = c,
"stack-green-color" => self.stack_green_color = c,
"red-channel-color" => self.red_channel_color = c,
"green-channel-color" => self.green_channel_color = c,
"blue-channel-color" => self.blue_channel_color = c,
"lens-color" => {
if self.kind.starts_with("Led") {
self.led_color = c;
} else {
self.lamp_color = c;
}
}
"lit-color" => {
if self.kind.starts_with("Seg14") {
self.seg14_lit_color = c;
} else if self.kind.starts_with("Seg16") {
self.seg16_lit_color = c;
} else {
self.seg7_lit_color = c;
}
}
"dim-color" => {
if self.kind.starts_with("Seg14") {
self.seg14_dim_color = c;
} else if self.kind.starts_with("Seg16") {
self.seg16_dim_color = c;
} else {
self.seg7_dim_color = c;
}
}
"label-color" => self.seg_label_color = c,
"tier-outline-color" | "swatch-outline-color" => self.outline_color = c,
_ => return false,
}
true
}
fn set_named_double(&mut self, name: &str, v: f64) -> bool {
match name {
"value" | "level" => {
self.set_value(v);
true
}
_ => false,
}
}
fn set_named_int(&mut self, name: &str, v: i32) -> bool {
match name {
"brightness" => {
self.brightness = v.clamp(0, 100);
true
}
"decimal-places" => {
self.decimal_places = v.clamp(0, 2);
true
}
"needle-line-width" => {
self.needle_line_width = v.max(0);
true
}
"marker-line-width" => {
self.marker_line_width = v.max(0);
true
}
"red-brightness" => {
self.stack_red_brightness = v.clamp(0, 100);
true
}
"amber-brightness" => {
self.stack_amber_brightness = v.clamp(0, 100);
true
}
"green-brightness" => {
self.stack_green_brightness = v.clamp(0, 100);
true
}
_ => false,
}
}
fn set_named_bool(&mut self, name: &str, v: bool) -> bool {
match name {
"on" => {
self.on = v;
true
}
"all-on" => {
if self.kind == "StackLight" {
self.stack_red_on = v;
self.stack_amber_on = v;
self.stack_green_on = v;
} else {
self.red_on = v;
self.green_on = v;
self.blue_on = v;
}
true
}
"red-on" => {
if self.kind == "StackLight" {
self.stack_red_on = v;
} else {
self.red_on = v;
}
true
}
"green-on" => {
if self.kind == "StackLight" {
self.stack_green_on = v;
} else {
self.green_on = v;
}
true
}
"amber-on" => {
self.stack_amber_on = v;
true
}
"blue-on" => {
self.blue_on = v;
true
}
_ => false,
}
}
fn set_value_str(&mut self, v: &str) -> bool {
if self.kind.starts_with("Seg14Display") || self.kind.starts_with("Seg16Display") {
self.display_text = v.to_string();
true
} else {
false
}
}
fn draw(&self, target: &mut dyn DrawTarget, styles: &mut StyleManager) {
if !self.state.visible {
return;
@@ -5011,7 +5417,7 @@ archetype_impl!(InstrumentWidget, Archetype::Instrument,
let (mn, mx, value) = (self.state.min, self.state.max, self.state.value);
if let Some(n) = k.strip_prefix("LedDigits") {
let digits: u32 = n.parse().unwrap_or(1);
let dp: u32 = if digits <= 1 { 0 } else { 1 };
let dp: u32 = self.decimal_places.max(0) as u32;
let shown = led_shown_digits(value, digits, dp);
let cells: Vec<char> = shown.chars().collect();
let dp_after = if dp > 0 {
@@ -5067,17 +5473,17 @@ archetype_impl!(InstrumentWidget, Archetype::Instrument,
return;
}
match k {
"LedRed" => draw_led(target, &style, b, &label, self.led_rgb(), self.on, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.lead_color.to_pixel()),
"LedGreen" => draw_led(target, &style, b, &label, self.led_rgb(), self.on, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.lead_color.to_pixel()),
"LedBlue" => draw_led(target, &style, b, &label, self.led_rgb(), self.on, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.lead_color.to_pixel()),
"PanelLampAmber" => draw_panel_lamp(target, &style, b, &label, self.lamp_rgb(), self.on, self.white_color.to_pixel(), self.bezel_color.to_pixel(), self.ring_color.to_pixel()),
"PanelLampBlue" => draw_panel_lamp(target, &style, b, &label, self.lamp_rgb(), self.on, self.white_color.to_pixel(), self.bezel_color.to_pixel(), self.ring_color.to_pixel()),
"PanelLampGreen" => draw_panel_lamp(target, &style, b, &label, self.lamp_rgb(), self.on, self.white_color.to_pixel(), self.bezel_color.to_pixel(), self.ring_color.to_pixel()),
"PanelLampRed" => draw_panel_lamp(target, &style, b, &label, self.lamp_rgb(), self.on, self.white_color.to_pixel(), self.bezel_color.to_pixel(), self.ring_color.to_pixel()),
"PanelLampWhite" => draw_panel_lamp(target, &style, b, &label, self.lamp_rgb(), self.on, self.white_color.to_pixel(), self.bezel_color.to_pixel(), self.ring_color.to_pixel()),
"Beacon" => draw_beacon(target, &style, b, &label, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.beacon_color.to_pixel(), self.on),
"StackLight" => draw_stack_light(target, &style, b, &label, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.outline_color.to_pixel(), self.stack_red_color.to_pixel(), self.stack_amber_color.to_pixel(), self.stack_green_color.to_pixel(), self.stack_red_on, self.stack_amber_on, self.stack_green_on),
"RgbStatusLed" => draw_rgb_led(target, &style, b, &label, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.outline_color.to_pixel(), self.red_channel_color.to_pixel(), self.green_channel_color.to_pixel(), self.blue_channel_color.to_pixel(), self.red_on, self.green_on, self.blue_on),
"LedRed" => draw_led(target, &style, b, &label, self.led_rgb(), self.on, self.brightness, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.lead_color.to_pixel()),
"LedGreen" => draw_led(target, &style, b, &label, self.led_rgb(), self.on, self.brightness, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.lead_color.to_pixel()),
"LedBlue" => draw_led(target, &style, b, &label, self.led_rgb(), self.on, self.brightness, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.lead_color.to_pixel()),
"PanelLampAmber" => draw_panel_lamp(target, &style, b, &label, self.lamp_rgb(), self.on, self.brightness, self.white_color.to_pixel(), self.bezel_color.to_pixel(), self.ring_color.to_pixel()),
"PanelLampBlue" => draw_panel_lamp(target, &style, b, &label, self.lamp_rgb(), self.on, self.brightness, self.white_color.to_pixel(), self.bezel_color.to_pixel(), self.ring_color.to_pixel()),
"PanelLampGreen" => draw_panel_lamp(target, &style, b, &label, self.lamp_rgb(), self.on, self.brightness, self.white_color.to_pixel(), self.bezel_color.to_pixel(), self.ring_color.to_pixel()),
"PanelLampRed" => draw_panel_lamp(target, &style, b, &label, self.lamp_rgb(), self.on, self.brightness, self.white_color.to_pixel(), self.bezel_color.to_pixel(), self.ring_color.to_pixel()),
"PanelLampWhite" => draw_panel_lamp(target, &style, b, &label, self.lamp_rgb(), self.on, self.brightness, self.white_color.to_pixel(), self.bezel_color.to_pixel(), self.ring_color.to_pixel()),
"Beacon" => draw_beacon(target, &style, b, &label, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.beacon_color.to_pixel(), self.on, self.brightness),
"StackLight" => draw_stack_light(target, &style, b, &label, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.outline_color.to_pixel(), self.stack_red_color.to_pixel(), self.stack_amber_color.to_pixel(), self.stack_green_color.to_pixel(), self.stack_red_on, self.stack_amber_on, self.stack_green_on, self.stack_red_brightness, self.stack_amber_brightness, self.stack_green_brightness),
"RgbStatusLed" => draw_rgb_led(target, &style, b, &label, self.white_color.to_pixel(), self.dark_color.to_pixel(), self.outline_color.to_pixel(), self.red_channel_color.to_pixel(), self.green_channel_color.to_pixel(), self.blue_channel_color.to_pixel(), self.red_on, self.green_on, self.blue_on, self.brightness),
"AnalogGauge" => draw_dial_gauge(target, &style, b, &label, mn, mx, value, 1.01, "", self.white_color.to_pixel(), self.face_color.to_pixel(), self.ink_color.to_pixel(), self.red_color.to_pixel(), self.needle_line_width),
"PressureGauge" => draw_dial_gauge(target, &style, b, &label, mn, mx, value, 0.8, " psi", self.white_color.to_pixel(), self.face_color.to_pixel(), self.ink_color.to_pixel(), self.red_color.to_pixel(), self.needle_line_width),
"TemperatureGauge" => draw_dial_gauge(target, &style, b, &label, mn, mx, value, 0.7727, " C", self.white_color.to_pixel(), self.face_color.to_pixel(), self.ink_color.to_pixel(), self.red_color.to_pixel(), self.needle_line_width),
+73 -1
View File
@@ -275,6 +275,21 @@ pub struct XGraph {
pub x_labels: Vec<String>,
/// Grid-line colour (was hardcoded 0xe1e1e1 in `draw`).
pub grid_color: Srgb,
/// Y-axis label colour (C++ `set_axis_color`).
pub axis_color: Srgb,
/// Line-series colour / width (C++ `set_line_color` / `set_line_width`).
pub line_color: Srgb,
pub line_width: i32,
/// Candle / OHLC up-down colours (C++ `set_up_color` / `set_down_color`).
pub up_color: Srgb,
pub down_color: Srgb,
/// Candle-body colours (C++ `set_candle_up_color` / `set_candle_down_color`).
pub candle_up_color: Srgb,
pub candle_down_color: Srgb,
/// Annotation overlay text colour (C++ `set_annotation_color` /
/// `set_text_color`); stored — the Rust chart draws no overlays yet.
pub annotation_color: Srgb,
pub text_color: Srgb,
pub view: PlotView,
pub dragging: bool,
pub drag_start_x: i32,
@@ -294,6 +309,49 @@ impl XGraph {
pub fn new_widget(name: &str, kind: &str, x: i32, y: i32, w: i32, h: i32) -> XGraph {
let mut state = WidgetState::new(name, x, y, w, h);
state.text = "Graph".to_string();
// Phase 4 colours: per-kind table defaults (see props.rs).
// (axis, line, line_width, up, down, candle_up, candle_down,
// annotation, text)
let phase4 = match kind {
"AccumulationDistribution" => (Srgb::new(150, 150, 150), Srgb::new(0, 150, 0), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"AreaChart" => (Srgb::new(150, 150, 150), Srgb::new(0, 100, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"Arrow" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 3, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"BaselineChart" => (Srgb::new(150, 150, 150), Srgb::new(0, 100, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"Brush" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 4, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"CandlestickChart" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"CorrelationView" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"Ellipse" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"FibExtension" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"FibRetracement" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"HeikinAshi" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"HollowCandles" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"HorizontalLine" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"IndexedComparison" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"LineChart" => (Srgb::new(150, 150, 150), Srgb::new(0, 100, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"MeasureTool" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"MoneyFlowChart" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"MultiSymbolChart" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"OBVChart" => (Srgb::new(150, 150, 150), Srgb::new(0, 100, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"OHLCBarChart" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"OverlayChart" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"ParallelChannel" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"Pitchfork" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"PriceLabel" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"RatioChart" => (Srgb::new(150, 150, 150), Srgb::new(120, 60, 180), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"Rectangle" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"RelativePerformance" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"Renko" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"SectorComparison" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"SpreadChart" => (Srgb::new(150, 150, 150), Srgb::new(0, 100, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"TextAnnotation" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"Trendline" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"VWAP" => (Srgb::new(150, 150, 150), Srgb::new(0, 100, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"VerticalLine" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 2, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"VolumeBars" => (Srgb::new(150, 150, 150), Srgb::new(0, 100, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"VolumeCandles" => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
"VolumeProfile" => (Srgb::new(150, 150, 150), Srgb::new(0, 100, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
_ => (Srgb::new(150, 150, 150), Srgb::new(0, 120, 200), 1, Srgb::new(0, 150, 0), Srgb::new(200, 30, 30), Srgb::new(120, 190, 120), Srgb::new(200, 120, 120), Srgb::new(160, 90, 0), Srgb::new(20, 20, 20)),
};
XGraph {
view: PlotView::new(state.bounds),
state,
@@ -301,6 +359,15 @@ impl XGraph {
series: Vec::new(),
x_labels: Vec::new(),
grid_color: Srgb::new(225, 225, 225),
axis_color: phase4.0,
line_color: phase4.1,
line_width: phase4.2,
up_color: phase4.3,
down_color: phase4.4,
candle_up_color: phase4.5,
candle_down_color: phase4.6,
annotation_color: phase4.7,
text_color: phase4.8,
dragging: false,
drag_start_x: 0,
drag_start_first: 0.0,
@@ -463,6 +530,7 @@ impl XGraph {
target.set_foreground(s.color.to_pixel());
match s.kind {
SeriesKind::Line => {
target.set_line_width(self.line_width.max(1) as u32);
let mut prev: Option<(i32, i32)> = None;
for i in 0..s.line.len() {
let v = s.line[i];
@@ -481,6 +549,7 @@ impl XGraph {
}
prev = Some((cx, cy));
}
target.set_line_width(1);
}
SeriesKind::OhlcBars | SeriesKind::Candlesticks => {
let bw = ((self.view.item_w(total) * 0.6) as i32).max(1);
@@ -548,6 +617,9 @@ impl Widget for XGraph {
return;
}
let (lo, hi) = self.y_range();
// Y-axis labels use the widget's axis colour.
let mut axis_style = style.clone();
axis_style.text_color = self.axis_color.to_pixel();
// Grid + y labels.
let step = PlotView::nice_step(hi - lo, 6);
let mut v = (lo / step).ceil() * step;
@@ -564,7 +636,7 @@ impl Widget for XGraph {
let tw = style.text_width(&lab);
draw_text_at(
target,
&style,
&axis_style,
self.view.plot_x() - tw - 6,
gy + 4,
&lab,
+31
View File
@@ -318,6 +318,37 @@ pub trait Widget {
fn set_max_length(&mut self, _v: i32) {}
fn set_xalign(&mut self, _v: f64) {}
// --- Phase 4 (Inspector properties §2.22 Stock/Instrumentation) ---
// Generic named dispatch: the designer canvas routes Phase 4 table
// props here by kind; archetypes override the ones their class
// supports and return true when the prop changed live state, false
// when the prop is model-only for that archetype (the model still
// holds the value and the generator emits it).
fn set_named_color(&mut self, _name: &str, _c: Srgb) -> bool {
false
}
fn set_named_double(&mut self, _name: &str, _v: f64) -> bool {
false
}
fn set_named_int(&mut self, _name: &str, _v: i32) -> bool {
false
}
fn set_named_bool(&mut self, _name: &str, _v: bool) -> bool {
false
}
fn set_named_string(&mut self, _name: &str, _v: &str) -> bool {
false
}
fn set_y_range(&mut self, _min: f64, _max: f64) -> bool {
false
}
fn set_anchor(&mut self, _i: usize, _bar: f64, _price: f64) -> bool {
false
}
fn set_value_str(&mut self, _v: &str) -> bool {
false
}
// -- containers (default: no children) --
fn children_count(&self) -> usize {
0