use image::DynamicImage;
use image::Rgba;
use resvg::tiny_skia::Color;
#[derive(Clone)]
pub enum Button {
Icon {
svg_data: &'static str,
background: Color,
foreground: Color,
},
IconWithText {
svg_data: &'static str,
text: String,
background: Color,
foreground: Color,
},
Text {
text: String,
background: Color,
foreground: Color,
},
CustomImage { image: DynamicImage },
Gradient {
start_color: Rgba<u8>,
end_color: Rgba<u8>,
},
}
pub struct RenderConfig {
pub(crate) width: u32,
pub(crate) height: u32,
pub(crate) font_data: &'static [u8],
pub(crate) font_scale: f32,
}
impl RenderConfig {
pub fn new(width: u32, height: u32, font_data: &'static [u8], font_scale: f32) -> Self {
RenderConfig {
width,
height,
font_data,
font_scale,
}
}
}
impl Default for RenderConfig {
fn default() -> Self {
RenderConfig {
width: 72,
height: 72,
font_data: include_bytes!("../../fonts/Roboto-Medium.ttf"),
font_scale: 14.0,
}
}
}
impl Button {
pub fn text(text: impl Into<String>, background: Color, foreground: Color) -> Self {
Button::Text {
text: text.into(),
background,
foreground,
}
}
pub fn icon(svg_data: &'static str, background: Color, foreground: Color) -> Self {
Button::Icon {
svg_data,
background,
foreground,
}
}
pub fn icon_with_text(
svg_data: &'static str,
text: impl Into<String>,
background: Color,
foreground: Color,
) -> Self {
Button::IconWithText {
svg_data,
text: text.into(),
background,
foreground,
}
}
pub fn custom_image(image: DynamicImage) -> Self {
Button::CustomImage { image }
}
pub fn gradient(start_color: Rgba<u8>, end_color: Rgba<u8>) -> Self {
Button::Gradient {
start_color,
end_color,
}
}
}