Skip to main content

uzor_core/widgets/
toolbar.rs

1//! Toolbar widget configuration and geometry
2//!
3//! Provides toolbar configuration and geometry calculation
4//! for headless architecture.
5
6use crate::types::{Rect, WidgetState};
7use serde::{Deserialize, Serialize};
8
9/// Toolbar orientation
10#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
11pub enum ToolbarOrientation {
12    #[default]
13    Horizontal,
14    Vertical,
15}
16
17/// Toolbar item configuration
18#[derive(Clone, Debug, Serialize, Deserialize)]
19pub enum ToolbarItem {
20    /// Button with text
21    Button {
22        id: String,
23        text: Option<String>,
24        active: bool,
25        disabled: bool,
26        min_width: f64,
27    },
28    /// Visual separator
29    Separator,
30    /// Flexible spacer
31    Spacer,
32    /// Label (non-interactive text)
33    Label {
34        id: String,
35        text: String,
36    },
37}
38
39impl ToolbarItem {
40    pub fn button(id: &str, text: &str) -> Self {
41        Self::Button {
42            id: id.to_string(),
43            text: Some(text.to_string()),
44            active: false,
45            disabled: false,
46            min_width: 0.0,
47        }
48    }
49
50    pub fn id(&self) -> Option<&str> {
51        match self {
52            Self::Button { id, .. } => Some(id),
53            Self::Label { id, .. } => Some(id),
54            Self::Separator | Self::Spacer => None,
55        }
56    }
57}
58
59/// Section alignment
60#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
61pub enum SectionAlign {
62    #[default]
63    Start,
64    End,
65}
66
67/// Toolbar section configuration
68#[derive(Clone, Debug, Serialize, Deserialize)]
69pub struct ToolbarSection {
70    pub items: Vec<ToolbarItem>,
71    pub show_separator: bool,
72    pub align: SectionAlign,
73}
74
75impl ToolbarSection {
76    pub fn new(items: Vec<ToolbarItem>) -> Self {
77        Self {
78            items,
79            show_separator: false,
80            align: SectionAlign::Start,
81        }
82    }
83}
84
85/// Toolbar configuration
86#[derive(Clone, Debug, Serialize, Deserialize)]
87pub struct ToolbarConfig {
88    pub sections: Vec<ToolbarSection>,
89    pub orientation: ToolbarOrientation,
90    pub item_size: f64,
91    pub spacing: f64,
92    pub padding: f64,
93}
94
95impl Default for ToolbarConfig {
96    fn default() -> Self {
97        Self {
98            sections: Vec::new(),
99            orientation: ToolbarOrientation::Horizontal,
100            item_size: 32.0,
101            spacing: 4.0,
102            padding: 8.0,
103        }
104    }
105}
106
107/// Toolbar interaction response
108#[derive(Clone, Debug, Default, Serialize, Deserialize)]
109pub struct ToolbarResponse {
110    pub clicked: Option<String>,
111    pub hovered: Option<String>,
112    pub item_geometries: Vec<ToolbarItemGeometry>,
113}
114
115/// Geometry and state for a single toolbar item
116#[derive(Clone, Debug, Serialize, Deserialize)]
117pub struct ToolbarItemGeometry {
118    pub id: Option<String>,
119    pub rect: Rect,
120    pub state: WidgetState,
121    pub item_type: ToolbarItemType,
122}
123
124#[derive(Clone, Debug, Serialize, Deserialize)]
125pub enum ToolbarItemType {
126    Button,
127    Separator,
128    Spacer,
129    Label,
130}
131
132// TODO: Implement headless toolbar geometry calculation and interaction detection