streamdeck_oxide/button/
types.rs1use image::DynamicImage;
2use image::Rgba;
3use resvg::tiny_skia::Color;
4
5#[derive(Clone)]
7pub enum Button {
8 Icon {
10 svg_data: &'static str,
11 background: Color,
12 foreground: Color,
13 },
14 IconWithText {
16 svg_data: &'static str,
17 text: String,
18 background: Color,
19 foreground: Color,
20 },
21 Text {
23 text: String,
24 background: Color,
25 foreground: Color,
26 },
27 CustomImage { image: DynamicImage },
29 Gradient {
31 start_color: Rgba<u8>,
32 end_color: Rgba<u8>,
33 },
34}
35
36pub 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 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 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 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 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 pub fn custom_image(image: DynamicImage) -> Self {
103 Button::CustomImage { image }
104 }
105
106 pub fn gradient(start_color: Rgba<u8>, end_color: Rgba<u8>) -> Self {
108 Button::Gradient {
109 start_color,
110 end_color,
111 }
112 }
113}