bevy_ui_builders/checkbox/
types.rs1use bevy::prelude::*;
4
5#[derive(Component, Debug, Clone, Copy)]
7pub struct Checkbox;
8
9#[derive(Component, Debug, Clone, Copy, PartialEq, Eq)]
11pub enum CheckboxState {
12 Unchecked,
14 Checked,
16}
17
18impl Default for CheckboxState {
19 fn default() -> Self {
20 Self::Unchecked
21 }
22}
23
24impl CheckboxState {
25 pub fn toggle(&mut self) {
27 *self = match self {
28 Self::Unchecked => Self::Checked,
29 Self::Checked => Self::Unchecked,
30 };
31 }
32
33 pub fn is_checked(&self) -> bool {
35 matches!(self, Self::Checked)
36 }
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum CheckboxStyle {
42 Default,
44 Primary,
46 Success,
48 Danger,
50}
51
52impl Default for CheckboxStyle {
53 fn default() -> Self {
54 Self::Primary
55 }
56}
57
58impl CheckboxStyle {
59 pub fn checked_color(&self) -> Color {
61 match self {
62 Self::Default => crate::styles::colors::SECONDARY,
63 Self::Primary => crate::styles::colors::PRIMARY,
64 Self::Success => crate::styles::colors::SUCCESS,
65 Self::Danger => crate::styles::colors::DANGER,
66 }
67 }
68
69 pub fn unchecked_color(&self) -> Color {
71 crate::styles::colors::BACKGROUND_SECONDARY
72 }
73
74 pub fn border_color(&self) -> Color {
76 crate::styles::colors::BORDER_DEFAULT
77 }
78}
79
80#[derive(Component, Debug, Clone, Copy)]
82pub struct CheckboxStyleComponent(pub CheckboxStyle);
83
84#[derive(Component, Debug, Clone, Copy)]
86pub struct CheckboxCheckmark;