bevy_ui_builders/validation/
types.rs

1//! Validation component types
2
3use bevy::prelude::*;
4use crate::ValidationRule;
5
6/// Marker component - attach to any input that needs validation
7#[derive(Component, Debug, Clone)]
8pub struct Validated {
9    /// Validation rules to apply
10    pub rules: Vec<ValidationRule>,
11}
12
13impl Validated {
14    /// Create a new validated component with rules
15    pub fn new(rules: Vec<ValidationRule>) -> Self {
16        Self { rules }
17    }
18}
19
20/// Current validation state for an input
21#[derive(Component, Debug, Clone)]
22pub struct ValidationState {
23    /// Whether the current value is valid
24    pub is_valid: bool,
25    /// Error message if invalid
26    pub error_message: Option<String>,
27}
28
29impl Default for ValidationState {
30    fn default() -> Self {
31        Self {
32            is_valid: true,
33            error_message: None,
34        }
35    }
36}
37
38impl ValidationState {
39    /// Create a new valid state
40    pub fn valid() -> Self {
41        Self {
42            is_valid: true,
43            error_message: None,
44        }
45    }
46
47    /// Create a new invalid state with error message
48    pub fn invalid(message: String) -> Self {
49        Self {
50            is_valid: false,
51            error_message: Some(message),
52        }
53    }
54}