danceinterpreter_rs/ui/config_window/
bottombar.rs1use crate::dataloading::dataprovider::ItemChange;
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 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::Shrink);
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]
24 .width(Length::Fill)
25 .align_x(Horizontal::Center)
26 .spacing(5)
27}
28
29pub fn get_statics_buttons(dance_interpreter: &'_ DanceInterpreter) -> Vec<Element<'_, Message>> {
30 let bold_font = Font {
31 family: font::Family::SansSerif,
32 weight: font::Weight::Bold,
33 stretch: font::Stretch::Normal,
34 style: font::Style::Normal,
35 };
36
37 let btn_blank: Button<Message> =
38 button(text("Blank").align_y(Vertical::Center).font(bold_font))
39 .style(button::secondary)
40 .on_press(Message::ItemChanged(ItemChange::Blank));
41 let btn_traktor: Button<Message> =
42 button(text("Traktor").align_y(Vertical::Center).font(bold_font))
43 .style(button::secondary)
44 .on_press(Message::ItemChanged(ItemChange::Traktor));
45 let mut statics: Vec<Element<_>> = dance_interpreter
46 .data_provider
47 .statics()
48 .iter()
49 .filter(|(_, s)| s.is_favorite)
50 .map(|(name, s)| {
51 with_tooltip(
52 button(text(&s.name).font(bold_font))
53 .style(button::secondary)
54 .on_press(Message::ItemChanged(ItemChange::StaticAbsolute(
55 name.clone(),
56 ))),
57 format!("Show {} static", s.name),
58 )
59 })
60 .collect();
61 statics.insert(0, with_tooltip(btn_blank, "Show blank screen"));
62 statics.insert(1, with_tooltip(btn_traktor, "Show current Traktor song"));
63 statics
64}