1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::ui::ice as ui;
use iced::{button::State, Button, Element, Length};
use ui::{
    style::button::Style,
    widget::{AspectRatioContainer, FillText},
};

pub fn neat_button<M: Clone + 'static>(
    state: &mut State,
    label: impl Into<String>,
    fill_fraction: f32,
    button_style: Style,
    message: Option<M>,
) -> Element<M, ui::IcedRenderer> {
    let button = Button::new(state, FillText::new(label).fill_fraction(fill_fraction))
        .height(Length::Fill)
        .width(Length::Fill)
        .style(button_style);

    let button = match message {
        Some(message) => button.on_press(message),
        None => button,
    };

    let container = AspectRatioContainer::new(button);
    let container = match button_style.active().0 {
        Some((img, _)) => container.ratio_of_image(img),
        None => container,
    };

    container.into()
}