streamdeck_oxide/button/
types.rs

1use image::DynamicImage;
2use image::Rgba;
3use resvg::tiny_skia::Color;
4
5/// Represents different types of buttons for the Stream Deck
6#[derive(Clone)]
7pub enum Button {
8    /// A button with just an SVG icon
9    Icon {
10        svg_data: &'static str,
11        background: Color,
12        foreground: Color,
13    },
14    /// A button with an SVG icon and text label
15    IconWithText {
16        svg_data: &'static str,
17        text: String,
18        background: Color,
19        foreground: Color,
20    },
21    /// A button with only text
22    Text {
23        text: String,
24        background: Color,
25        foreground: Color,
26    },
27    /// A button with a custom image
28    CustomImage { image: DynamicImage },
29    /// A button with a gradient background
30    Gradient {
31        start_color: Rgba<u8>,
32        end_color: Rgba<u8>,
33    },
34}
35
36/// Configuration for rendering buttons
37pub struct RenderConfig {
38    pub(crate) width: u32,
39    pub(crate) height: u32,
40    pub(crate) font_data: &'static [u8],
41    pub(crate) font_scale: f32,
42}
43
44impl RenderConfig {
45    /// Create a new render config
46    pub fn new(width: u32, height: u32, font_data: &'static [u8], font_scale: f32) -> Self {
47        RenderConfig {
48            width,
49            height,
50            font_data,
51            font_scale,
52        }
53    }
54}
55
56impl Default for RenderConfig {
57    fn default() -> Self {
58        RenderConfig {
59            width: 72,
60            height: 72,
61            font_data: include_bytes!("../../fonts/Roboto-Medium.ttf"),
62            font_scale: 14.0,
63        }
64    }
65}
66
67impl Button {
68    /// Create a new text button
69    pub fn text(text: impl Into<String>, background: Color, foreground: Color) -> Self {
70        Button::Text {
71            text: text.into(),
72            background,
73            foreground,
74        }
75    }
76
77    /// Create a new icon button
78    pub fn icon(svg_data: &'static str, background: Color, foreground: Color) -> Self {
79        Button::Icon {
80            svg_data,
81            background,
82            foreground,
83        }
84    }
85
86    /// Create a new icon with text button
87    pub fn icon_with_text(
88        svg_data: &'static str,
89        text: impl Into<String>,
90        background: Color,
91        foreground: Color,
92    ) -> Self {
93        Button::IconWithText {
94            svg_data,
95            text: text.into(),
96            background,
97            foreground,
98        }
99    }
100
101    /// Create a new custom image button
102    pub fn custom_image(image: DynamicImage) -> Self {
103        Button::CustomImage { image }
104    }
105
106    /// Create a new gradient button
107    pub fn gradient(start_color: Rgba<u8>, end_color: Rgba<u8>) -> Self {
108        Button::Gradient {
109            start_color,
110            end_color,
111        }
112    }
113}