veloren_voxygen/ui/ice/component/
neat_button.rs

1use crate::ui::ice as ui;
2use iced::{Button, Element, Length, button::State};
3use ui::{
4    style::button::Style,
5    widget::{AspectRatioContainer, FillText},
6};
7
8pub fn neat_button<M: Clone + 'static>(
9    state: &mut State,
10    label: impl Into<String>,
11    fill_fraction: f32,
12    button_style: Style,
13    message: Option<M>,
14) -> Element<M, ui::IcedRenderer> {
15    let button = Button::new(state, FillText::new(label).fill_fraction(fill_fraction))
16        .height(Length::Fill)
17        .width(Length::Fill)
18        .style(button_style);
19
20    let button = match message {
21        Some(message) => button.on_press(message),
22        None => button,
23    };
24
25    let container = AspectRatioContainer::new(button);
26    let container = match button_style.active().0 {
27        Some((img, _)) => container.ratio_of_image(img),
28        None => container,
29    };
30
31    container.into()
32}