Skip to main content

danceinterpreter_rs/ui/config_window/
bottombar.rs

1use crate::dataloading::dataprovider::song_data_provider::SongChange;
2use crate::ui::with_tooltip;
3use crate::{DanceInterpreter, Message};
4use iced::alignment::{Horizontal, Vertical};
5use iced::widget::scrollable::{Direction, Scrollbar};
6use iced::widget::{Button, Column, button, column as col, container, row, scrollable, text};
7use iced::{Element, Font, Length, Theme, font};
8
9pub(crate) fn build(dance_interpreter: &'_ DanceInterpreter) -> Column<'_, Message> {
10    let statics_buttons = get_statics_buttons(dance_interpreter);
11
12    let statics_scrollable = scrollable(row(statics_buttons).spacing(5))
13        .direction(Direction::Horizontal(Scrollbar::new()))
14        .spacing(5)
15        .width(Length::Fill);
16
17    let statics_bar = container(statics_scrollable)
18        .width(Length::Shrink)
19        .style(|t: &Theme| {
20            container::Style::default().background(t.extended_palette().background.weakest.color)
21        });
22
23    col![statics_bar].align_x(Horizontal::Left).spacing(5)
24}
25
26pub(crate) fn get_statics_buttons(
27    dance_interpreter: &'_ DanceInterpreter,
28) -> Vec<Element<'_, Message>> {
29    let bold_font = Font {
30        family: font::Family::SansSerif,
31        weight: font::Weight::Bold,
32        stretch: font::Stretch::Normal,
33        style: font::Style::Normal,
34    };
35
36    let btn_blank: Button<Message> =
37        button(text("Blank").align_y(Vertical::Center).font(bold_font))
38            .style(button::secondary)
39            .on_press(Message::SongChanged(SongChange::Blank));
40    let btn_traktor: Button<Message> =
41        button(text("Traktor").align_y(Vertical::Center).font(bold_font))
42            .style(button::secondary)
43            .on_press(Message::SongChanged(SongChange::Traktor));
44    let mut statics: Vec<Element<_>> = dance_interpreter
45        .data_provider
46        .statics
47        .iter()
48        .enumerate()
49        .map(|(idx, s)| {
50            with_tooltip(
51                button(text(&s.dance).font(bold_font))
52                    .style(button::secondary)
53                    .on_press(Message::SongChanged(SongChange::StaticAbsolute(idx))),
54                format!("Show {} static", s.dance),
55            )
56        })
57        .collect();
58    statics.insert(0, with_tooltip(btn_blank, "Show blank screen"));
59    statics.insert(1, with_tooltip(btn_traktor, "Show current Traktor song"));
60    statics
61}