crisol-core 1.2.0

Crisol core: an egui-free data model, themes, metrics, localization, commands, state, and storage.
Documentation
//! The widget tree of a host spec.

use serde::{Deserialize, Serialize};

use super::*;
/// A widget in the spec tree.

#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(tag = "kind", rename_all = "snake_case")]
#[non_exhaustive]
/// # Example
///
/// ```
/// use crisol_core::spec::WidgetSpec;
/// ```
#[cfg_attr(feature = "schema", schemars(description = "A widget in the spec tree."))]
pub enum WidgetSpec {
    /// A label.
    Label {
        /// Text.
        text: String,
        /// Point size.
        size: f32,
        /// `default`, `muted`, `accent`, `danger`, `success`.
        tone: String,
        /// Strong weight.
        strong: bool,
    },
    /// A button that emits its command id.
    Button {
        /// Stable id.
        id: String,
        /// Label.
        label: String,
        /// `primary`, `secondary`, `ghost`, `outline`, `danger`.
        variant: String,
        /// Enabled state.
        enabled: bool,
    },
    /// A single-line text input.
    TextField {
        /// Stable id.
        id: String,
        /// Label.
        label: String,
        /// Initial value.
        value: String,
        /// Hint.
        hint: String,
    },
    /// A checkbox.
    Checkbox {
        /// Stable id.
        id: String,
        /// Label.
        label: String,
        /// Initial state.
        checked: bool,
    },
    /// A switch.
    Switch {
        /// Stable id.
        id: String,
        /// Label.
        label: String,
        /// Initial state.
        on: bool,
    },
    /// A select.
    Select {
        /// Stable id.
        id: String,
        /// Label.
        label: String,
        /// Options.
        options: Vec<String>,
        /// Selected index.
        selected: usize,
    },
    /// A slider.
    Slider {
        /// Stable id.
        id: String,
        /// Label.
        label: String,
        /// Minimum.
        min: f64,
        /// Maximum.
        max: f64,
        /// Value.
        value: f64,
        /// Step.
        step: f64,
    },
    /// A horizontal rule.
    Separator,
    /// Empty space.
    Spacer {
        /// Height in points.
        height: f32,
    },
    /// A horizontal row.
    Row {
        /// Children.
        children: Vec<WidgetSpec>,
        /// Gap in points.
        gap: f32,
    },
    /// A vertical column.
    Column {
        /// Children.
        children: Vec<WidgetSpec>,
        /// Gap in points.
        gap: f32,
    },
    /// A titled card.
    Card {
        /// Title.
        title: String,
        /// Children.
        children: Vec<WidgetSpec>,
    },
    /// A tab strip and its active content.
    Tabs {
        /// Stable id.
        id: String,
        /// Tabs.
        tabs: Vec<String>,
        /// Active index.
        active: usize,
        /// Content per tab.
        children: Vec<Vec<WidgetSpec>>,
    },
    /// An explorer-style tree.
    Tree {
        /// Stable id.
        id: String,
        /// Nodes.
        nodes: Vec<TreeSpec>,
        /// Selected key.
        selected: Option<String>,
    },
    /// A typed data grid over a host dataset.
    DataGrid {
        /// Stable id.
        id: String,
        /// Dataset name registered with `Host::set_dataset`.
        dataset: String,
        /// Viewport height.
        height: f32,
    },
    /// A plot over points or a host dataset.
    Plot {
        /// Stable id.
        id: String,
        /// Title.
        title: String,
        /// Series.
        series: Vec<SeriesSpec>,
        /// Height.
        height: f32,
        /// `cpu` or `gpu`.
        renderer: String,
    },
    /// A Rust extension widget registered with `Host::register_custom`.
    Custom {
        /// Registered widget kind.
        widget: String,
        /// Opaque properties passed to the extension.
        props: serde_json::Value,
    },
}