Skip to main content

agg_gui/widgets/property_row/
value.rs

1//! Value type carried into a row renderer.
2//!
3//! Independent of any particular host's value system (node-editor's
4//! `PropertyValue`, atomartist's `PortValue`, etc.) — hosts translate
5//! their own variants into this borrow-form before calling
6//! [`paint_row`](super::render::paint_row).
7//!
8//! Borrow form keeps the dispatcher allocation-free: a host that
9//! stores its current value as `Arc<str>` or owned `String` hands a
10//! `&str` slice into `RowValue::Text(...)`. The renderer reads, never
11//! retains.
12
13/// Borrowed current value for a property row.
14#[derive(Clone, Copy, Debug)]
15pub enum RowValue<'a> {
16    /// Numeric value — rendered by `Slider` / `NumberDrag` / default.
17    Number(f64),
18    /// Boolean — rendered by the toggle painter.
19    Bool(bool),
20    /// RGBA in 0..=1. Rendered by the color painter as a swatch.
21    Color([f32; 4]),
22    /// Editable string content. Multi-line painters break on `\n`.
23    Text(&'a str),
24    /// Opaque display string for non-editable values — used by the
25    /// matrix renderer ("Identity"), image previews, geometry
26    /// summaries, etc.
27    Display(&'a str),
28}
29
30impl<'a> RowValue<'a> {
31    /// Borrowed string view of any text-like value — convenience for
32    /// renderers that just need to paint a short string regardless of
33    /// the underlying variant.
34    pub fn as_short_text(&self) -> Option<&str> {
35        match self {
36            RowValue::Text(s) | RowValue::Display(s) => Some(s),
37            _ => None,
38        }
39    }
40}