uzor 1.5.0

Core UI engine — geometry, interaction, input state
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
//! Panel toolbar definitions
//!
//! Panel crates use these types to describe their toolbar layout.
//! The panel renders the toolbar itself using RenderContext + these definitions.

use serde::{Serialize, Deserialize};

/// Icon identifier for toolbar buttons (string-based, maps to SVG icon registry)
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ToolbarIconId(pub String);

impl ToolbarIconId {
    pub fn new(name: &str) -> Self {
        Self(name.to_string())
    }

    pub fn name(&self) -> &str {
        &self.0
    }
}

impl From<&str> for ToolbarIconId {
    fn from(s: &str) -> Self {
        Self::new(s)
    }
}

impl From<String> for ToolbarIconId {
    fn from(s: String) -> Self {
        Self(s)
    }
}

/// A single toolbar item
#[derive(Clone, Debug)]
pub enum ToolbarItemDef {
    /// Button with icon and/or text
    Button {
        id: &'static str,
        icon: Option<ToolbarIconId>,
        text: Option<String>,
        active: bool,
        disabled: bool,
        min_width: f64,
        /// Optional tooltip text shown on hover
        tooltip: Option<&'static str>,
        /// Draw a line through the label — the "feature currently OFF"
        /// presentation for toggle chips whose label is the feature name
        /// itself (e.g. an "Imb" chip: plain = on, struck = off).
        strikethrough: bool,
    },
    /// Icon-only button
    IconButton {
        id: &'static str,
        icon: ToolbarIconId,
        active: bool,
        disabled: bool,
        /// Optional tooltip text shown on hover
        tooltip: Option<&'static str>,
    },
    /// Dropdown button (panel handles the popup rendering)
    Dropdown {
        id: &'static str,
        icon: Option<ToolbarIconId>,
        text: Option<String>,
        active: bool,
        show_chevron: bool,
        items: Vec<DropdownItemDef>,
        /// If true, first click activates last tool, second click opens dropdown
        quick_select: bool,
        /// Grid layout columns for dropdown (None = vertical list)
        grid_columns: Option<u8>,
        min_width: f64,
        /// Optional tooltip text shown on hover
        tooltip: Option<&'static str>,
    },
    /// Visual separator
    Separator,
    /// Flexible spacer
    Spacer,
}

impl ToolbarItemDef {
    pub fn button(id: &'static str) -> Self {
        Self::Button {
            id,
            icon: None,
            text: None,
            active: false,
            disabled: false,
            min_width: 0.0,
            tooltip: None,
            strikethrough: false,
        }
    }

    /// Strike the label through (Button only) — see the field docs.
    pub fn with_strikethrough(mut self, on: bool) -> Self {
        if let Self::Button { strikethrough: ref mut s, .. } = &mut self {
            *s = on;
        }
        self
    }

    pub fn icon_button(id: &'static str, icon: impl Into<ToolbarIconId>) -> Self {
        Self::IconButton {
            id,
            icon: icon.into(),
            active: false,
            disabled: false,
            tooltip: None,
        }
    }

    pub fn dropdown(id: &'static str, items: Vec<DropdownItemDef>) -> Self {
        Self::Dropdown {
            id,
            icon: None,
            text: None,
            active: false,
            show_chevron: true,
            items,
            quick_select: false,
            grid_columns: None,
            min_width: 0.0,
            tooltip: None,
        }
    }

    pub fn quick_select(id: &'static str, items: Vec<DropdownItemDef>) -> Self {
        Self::Dropdown {
            id,
            icon: None,
            text: None,
            active: false,
            show_chevron: false,
            items,
            quick_select: true,
            grid_columns: None,
            min_width: 0.0,
            tooltip: None,
        }
    }

    /// Suppress the dropdown chevron — for split controls where a labeled
    /// button IS the dropdown trigger and needs no extra glyph.
    pub fn without_chevron(mut self) -> Self {
        if let Self::Dropdown { show_chevron: ref mut c, .. } = &mut self {
            *c = false;
        }
        self
    }

    pub fn with_icon(mut self, icon: impl Into<ToolbarIconId>) -> Self {
        match &mut self {
            Self::Button { icon: ref mut i, .. } => *i = Some(icon.into()),
            Self::Dropdown { icon: ref mut i, .. } => *i = Some(icon.into()),
            _ => {}
        }
        self
    }

    pub fn with_text(mut self, text: impl Into<String>) -> Self {
        match &mut self {
            Self::Button { text: ref mut t, .. } => *t = Some(text.into()),
            Self::Dropdown { text: ref mut t, .. } => *t = Some(text.into()),
            _ => {}
        }
        self
    }

    pub fn with_active(mut self, active: bool) -> Self {
        match &mut self {
            Self::Button { active: ref mut a, .. } => *a = active,
            Self::IconButton { active: ref mut a, .. } => *a = active,
            Self::Dropdown { active: ref mut a, .. } => *a = active,
            _ => {}
        }
        self
    }

    pub fn with_min_width(mut self, w: f64) -> Self {
        match &mut self {
            Self::Button { min_width: ref mut mw, .. } => *mw = w,
            Self::Dropdown { min_width: ref mut mw, .. } => *mw = w,
            _ => {}
        }
        self
    }

    /// Set the tooltip text shown when hovering this item.
    pub fn with_tooltip(mut self, text: &'static str) -> Self {
        match &mut self {
            Self::Button { tooltip: ref mut t, .. } => *t = Some(text),
            Self::IconButton { tooltip: ref mut t, .. } => *t = Some(text),
            Self::Dropdown { tooltip: ref mut t, .. } => *t = Some(text),
            _ => {}
        }
        self
    }

    /// Get the tooltip text for this item, if any.
    pub fn tooltip(&self) -> Option<&'static str> {
        match self {
            Self::Button { tooltip, .. } => *tooltip,
            Self::IconButton { tooltip, .. } => *tooltip,
            Self::Dropdown { tooltip, .. } => *tooltip,
            _ => None,
        }
    }

    pub fn id(&self) -> &str {
        match self {
            Self::Button { id, .. } => id,
            Self::IconButton { id, .. } => id,
            Self::Dropdown { id, .. } => id,
            Self::Separator | Self::Spacer => "",
        }
    }
}

/// Dropdown menu item
#[derive(Clone, Debug)]
pub enum DropdownItemDef {
    /// Clickable action item
    Action {
        id: String,
        label: String,
        icon: Option<ToolbarIconId>,
        shortcut: Option<String>,
    },
    /// Action item with an inline text-input field rendered to the right of
    /// the label. Selecting the row (left side) fires the action; clicking
    /// the input lets the user edit a numeric / short-string parameter that
    /// is committed on Enter.
    ///
    /// `field_id` is the `WidgetId` string that addresses the text-input
    /// in the host's `InputCoordinator::text_fields` store — the host
    /// registers it once at startup with its own filter/max_len config.
    ActionWithInput {
        id: String,
        label: String,
        icon: Option<ToolbarIconId>,
        /// Text-field store key for the inline input (e.g. `"bar_mode_param"`).
        field_id: String,
        /// Default text shown when the input is empty (placeholder).
        default_text: String,
    },
    /// Submenu (nested dropdown)
    Submenu {
        id: String,
        label: String,
        icon: Option<ToolbarIconId>,
        items: Vec<DropdownItemDef>,
        grid_columns: Option<u8>,
    },
    /// Section header text
    Header {
        label: String,
    },
    /// Visual separator
    Separator,
}

impl DropdownItemDef {
    pub fn action(id: impl Into<String>, label: impl Into<String>) -> Self {
        Self::Action {
            id: id.into(),
            label: label.into(),
            icon: None,
            shortcut: None,
        }
    }

    /// Build an action item with an inline parameter-input field.
    ///
    /// `field_id` must match a key previously registered on the host's
    /// `TextFieldStore`. `default_text` is the placeholder shown when the
    /// field is empty.
    pub fn action_with_input(
        id: impl Into<String>,
        label: impl Into<String>,
        field_id: impl Into<String>,
        default_text: impl Into<String>,
    ) -> Self {
        Self::ActionWithInput {
            id: id.into(),
            label: label.into(),
            icon: None,
            field_id: field_id.into(),
            default_text: default_text.into(),
        }
    }

    pub fn with_icon(mut self, icon: impl Into<ToolbarIconId>) -> Self {
        match &mut self {
            Self::Action { icon: ref mut i, .. } => *i = Some(icon.into()),
            Self::ActionWithInput { icon: ref mut i, .. } => *i = Some(icon.into()),
            Self::Submenu { icon: ref mut i, .. } => *i = Some(icon.into()),
            _ => {}
        }
        self
    }

    pub fn with_shortcut(mut self, shortcut: impl Into<String>) -> Self {
        if let Self::Action { shortcut: ref mut s, .. } = &mut self {
            *s = Some(shortcut.into());
        }
        self
    }
}

/// A group of toolbar items with optional separator
#[derive(Clone, Debug)]
pub struct ToolbarSectionDef {
    pub items: Vec<ToolbarItemDef>,
    pub show_separator: bool,
    /// Section alignment (Start = left/top, End = right/bottom)
    pub align: SectionAlign,
}

/// Section alignment within toolbar
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum SectionAlign {
    #[default]
    Start,
    End,
}

impl ToolbarSectionDef {
    pub fn new(items: Vec<ToolbarItemDef>) -> Self {
        Self {
            items,
            show_separator: false,
            align: SectionAlign::Start,
        }
    }

    pub fn with_separator(mut self) -> Self {
        self.show_separator = true;
        self
    }

    pub fn align_end(mut self) -> Self {
        self.align = SectionAlign::End;
        self
    }
}

/// Toolbar orientation
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum ToolbarOrientation {
    #[default]
    Horizontal,
    Vertical,
}

/// Complete toolbar definition for a panel
#[derive(Clone, Debug)]
pub struct PanelToolbarDef {
    pub sections: Vec<ToolbarSectionDef>,
    pub orientation: ToolbarOrientation,
    /// Height (horizontal) or width (vertical) of the toolbar
    pub size: f64,
    /// Individual item size (button height/width)
    pub item_size: f64,
    /// Icon size within items
    pub icon_size: f64,
    /// Spacing between items
    pub spacing: f64,
    /// Padding at toolbar edges
    pub padding: f64,
}

impl Default for PanelToolbarDef {
    fn default() -> Self {
        Self {
            sections: Vec::new(),
            orientation: ToolbarOrientation::Horizontal,
            size: 32.0,
            item_size: 28.0,
            icon_size: 16.0,
            spacing: 2.0,
            padding: 4.0,
        }
    }
}

impl PanelToolbarDef {
    pub fn horizontal(sections: Vec<ToolbarSectionDef>) -> Self {
        Self {
            sections,
            orientation: ToolbarOrientation::Horizontal,
            ..Default::default()
        }
    }

    pub fn vertical(sections: Vec<ToolbarSectionDef>) -> Self {
        Self {
            sections,
            orientation: ToolbarOrientation::Vertical,
            size: 40.0,
            item_size: 32.0,
            icon_size: 18.0,
            spacing: 2.0,
            padding: 4.0,
        }
    }

    pub fn with_size(mut self, size: f64) -> Self {
        self.size = size;
        self
    }
}