Skip to main content

uzor_core/widgets/
checkbox.rs

1//! Checkbox widget layout and configuration
2//!
3//! Provides checkbox configuration and response types for headless architecture.
4//! Rendering is delegated to platform-specific implementations.
5
6use crate::types::{WidgetState, Rect};
7use serde::{Deserialize, Serialize};
8
9/// Checkbox configuration
10#[derive(Clone, Debug, Serialize, Deserialize)]
11pub struct CheckboxConfig {
12    /// Checkbox label
13    pub label: String,
14    /// Whether checkbox is checked
15    pub checked: bool,
16    /// Whether checkbox is disabled
17    pub disabled: bool,
18}
19
20impl Default for CheckboxConfig {
21    fn default() -> Self {
22        Self {
23            label: String::new(),
24            checked: false,
25            disabled: false,
26        }
27    }
28}
29
30impl CheckboxConfig {
31    pub fn new(label: &str) -> Self {
32        Self {
33            label: label.to_string(),
34            ..Default::default()
35        }
36    }
37
38    pub fn with_checked(mut self, checked: bool) -> Self {
39        self.checked = checked;
40        self
41    }
42
43    pub fn with_disabled(mut self, disabled: bool) -> Self {
44        self.disabled = disabled;
45        self
46    }
47}
48
49/// Checkbox interaction response
50#[derive(Clone, Debug, Default, Serialize, Deserialize)]
51pub struct CheckboxResponse {
52    /// Whether checkbox was toggled this frame
53    pub toggled: bool,
54    /// New checked state (if toggled)
55    pub new_checked: bool,
56    /// Whether checkbox is currently hovered
57    pub hovered: bool,
58    /// Current widget state (Normal, Hovered, Pressed, etc.)
59    pub state: WidgetState,
60    /// Checkbox rectangle (for platform rendering)
61    pub rect: Rect,
62}