streamdeck_oxide/view/
button.rs1use crate::Theme;
6
7#[derive(Clone, Copy)]
9pub enum ButtonState {
10 Default,
12 Pressed,
14 Active,
16 Inactive,
18 Error,
20}
21
22#[derive(Clone)]
27pub struct Button {
28 pub(crate) text: String,
30 pub(crate) icon: Option<&'static str>,
32 pub(crate) state: ButtonState,
34 pub(crate) theme: Option<Theme>,
36}
37
38impl Button {
39 pub fn new(text: String, icon: Option<&'static str>, state: ButtonState) -> Self {
41 Button {
42 text,
43 icon,
44 state,
45 theme: None,
46 }
47 }
48
49 pub fn text(text: String) -> Self {
51 Button {
52 text,
53 icon: None,
54 state: ButtonState::Default,
55 theme: None,
56 }
57 }
58
59 pub fn with_icon(text: String, icon: &'static str) -> Self {
61 Button {
62 text,
63 icon: Some(icon),
64 state: ButtonState::Default,
65 theme: None,
66 }
67 }
68
69 pub fn with_state(text: String, state: ButtonState) -> Self {
71 Button {
72 text,
73 icon: None,
74 state,
75 theme: None,
76 }
77 }
78
79 pub fn with_icon_and_state(text: String, icon: &'static str, state: ButtonState) -> Self {
81 Button {
82 text,
83 icon: Some(icon),
84 state,
85 theme: None,
86 }
87 }
88
89 pub fn updated_text(&self, text: String) -> Self {
91 Button {
92 text,
93 icon: self.icon,
94 state: self.state,
95 theme: self.theme.clone(),
96 }
97 }
98
99 pub fn updated_icon(&self, icon: &'static str) -> Self {
101 Button {
102 text: self.text.clone(),
103 icon: Some(icon),
104 state: self.state,
105 theme: self.theme.clone(),
106 }
107 }
108
109 pub fn updated_state(&self, state: ButtonState) -> Self {
111 Button {
112 text: self.text.clone(),
113 icon: self.icon,
114 state,
115 theme: self.theme.clone(),
116 }
117 }
118
119 pub fn with_theme(self, theme: Theme) -> Self {
121 Button {
122 theme: Some(theme),
123 ..self
124 }
125 }
126}
127
128impl Default for Button {
129 fn default() -> Self {
130 Button {
131 text: "".to_string(),
132 icon: None,
133 state: ButtonState::Default,
134 theme: None,
135 }
136 }
137}