streamdeck_oxide/view/
button.rs1#[derive(Clone, Copy)]
7pub enum ButtonState {
8 Default,
10 Pressed,
12 Active,
14 Inactive,
16 Error,
18}
19
20#[derive(Clone, Copy)]
25pub struct Button {
26 pub(crate) text: &'static str,
28 pub(crate) icon: Option<&'static str>,
30 pub(crate) state: ButtonState,
32}
33
34impl Button {
35 pub fn new(text: &'static str, icon: Option<&'static str>, state: ButtonState) -> Self {
37 Button { text, icon, state }
38 }
39
40 pub fn text(text: &'static str) -> Self {
42 Button {
43 text,
44 icon: None,
45 state: ButtonState::Default,
46 }
47 }
48
49 pub fn with_icon(text: &'static str, icon: &'static str) -> Self {
51 Button {
52 text,
53 icon: Some(icon),
54 state: ButtonState::Default,
55 }
56 }
57
58 pub fn with_state(text: &'static str, state: ButtonState) -> Self {
60 Button {
61 text,
62 icon: None,
63 state,
64 }
65 }
66
67 pub fn with_icon_and_state(text: &'static str, icon: &'static str, state: ButtonState) -> Self {
69 Button {
70 text,
71 icon: Some(icon),
72 state,
73 }
74 }
75
76 pub fn updated_text(&self, text: &'static str) -> Self {
78 Button {
79 text,
80 icon: self.icon,
81 state: self.state,
82 }
83 }
84
85 pub fn updated_icon(&self, icon: &'static str) -> Self {
87 Button {
88 text: self.text,
89 icon: Some(icon),
90 state: self.state,
91 }
92 }
93
94 pub fn updated_state(&self, state: ButtonState) -> Self {
96 Button {
97 text: self.text,
98 icon: self.icon,
99 state,
100 }
101 }
102}
103
104impl Default for Button {
105 fn default() -> Self {
106 Button {
107 text: "",
108 icon: None,
109 state: ButtonState::Default,
110 }
111 }
112}