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)]
11#[derive(Default)]
12pub struct CheckboxConfig {
13    /// Checkbox label
14    pub label: String,
15    /// Whether checkbox is checked
16    pub checked: bool,
17    /// Whether checkbox is disabled
18    pub disabled: bool,
19}
20
21
22impl CheckboxConfig {
23    pub fn new(label: &str) -> Self {
24        Self {
25            label: label.to_string(),
26            ..Default::default()
27        }
28    }
29
30    pub fn with_checked(mut self, checked: bool) -> Self {
31        self.checked = checked;
32        self
33    }
34
35    pub fn with_disabled(mut self, disabled: bool) -> Self {
36        self.disabled = disabled;
37        self
38    }
39}
40
41/// Checkbox interaction response
42#[derive(Clone, Debug, Default, Serialize, Deserialize)]
43pub struct CheckboxResponse {
44    /// Whether checkbox was toggled this frame
45    pub toggled: bool,
46    /// New checked state (if toggled)
47    pub new_checked: bool,
48    /// Whether checkbox is currently hovered
49    pub hovered: bool,
50    /// Current widget state (Normal, Hovered, Pressed, etc.)
51    pub state: WidgetState,
52    /// Checkbox rectangle (for platform rendering)
53    pub rect: Rect,
54}