Skip to main content

danceinterpreter_rs/ui/config_window/
mod.rs

1pub mod bottombar;
2pub mod dialog;
3pub mod item_row;
4pub mod playlist_view;
5pub mod search_bar;
6pub mod sidebar;
7pub mod statics_view;
8pub mod top_bar;
9
10pub use dialog::DialogState;
11pub use playlist_view::PLAYLIST_SCROLLABLE_ID;
12
13use crate::ui::config_window::sidebar::Sidebar;
14use crate::{DanceInterpreter, Message, Window};
15use iced::widget::{column as col, row, stack};
16use iced::{Color, Element, Size, Theme, window};
17use std::time::Instant;
18
19pub struct ConfigWindow {
20    pub id: window::Id,
21    pub closed: bool,
22    pub size: Size,
23    pub enable_autoscroll: bool,
24    pub sidebar: Sidebar,
25    pub is_statics_view: bool,
26    pub theme: Theme,
27    pub follow_system_theme: bool,
28
29    pub search_visible: bool,
30    pub search_query: String,
31    pub active_dialog: Option<DialogState>,
32    pub color_picker_open: Option<String>,
33    pub color_picker_old_color: Option<Color>,
34
35    pub dummy_song_title: String,
36    pub dummy_song_artist: String,
37    pub dummy_song_dance: String,
38}
39
40impl Window for ConfigWindow {
41    fn new(id: window::Id) -> Self {
42        Self {
43            id,
44            closed: false,
45            size: Size::default(),
46
47            enable_autoscroll: true,
48            sidebar: Sidebar::new(),
49            is_statics_view: false,
50            theme: Theme::Dark,
51            follow_system_theme: true,
52
53            search_visible: false,
54            search_query: String::new(),
55            active_dialog: None,
56            color_picker_open: None,
57            color_picker_old_color: None,
58
59            dummy_song_title: String::new(),
60            dummy_song_artist: String::new(),
61            dummy_song_dance: String::new(),
62        }
63    }
64
65    fn on_resize(&mut self, size: Size) {
66        self.size = size;
67    }
68
69    fn on_close(&mut self) {
70        self.closed = true;
71    }
72
73    fn is_closed(&self) -> bool {
74        self.closed
75    }
76}
77
78impl ConfigWindow {
79    pub fn view<'a>(&'a self, dance_interpreter: &'a DanceInterpreter) -> Element<'a, Message> {
80        let top_bar = top_bar::build(self, dance_interpreter);
81
82        let mut main_column = col![top_bar];
83
84        if self.search_visible {
85            let search_bar = search_bar::build_search_bar(&self.search_query);
86            main_column = main_column.push(search_bar);
87        }
88
89        let content_view = if self.is_statics_view {
90            statics_view::build(self, dance_interpreter)
91        } else {
92            playlist_view::build(self, dance_interpreter)
93        };
94
95        main_column = main_column.push(content_view);
96
97        let side_bar = self
98            .sidebar
99            .build(dance_interpreter)
100            .width(self.sidebar.state.interpolate(
101                0.0,
102                (self.size.width / 5.0).min(400.0),
103                Instant::now(),
104            ));
105        let bottom_bar = bottombar::build(dance_interpreter);
106        let main_view = col![row![main_column, side_bar], bottom_bar].spacing(5);
107
108        if let Some(state) = &self.active_dialog {
109            let dialog = dialog::build_dialog(state, dance_interpreter);
110            stack![main_view, dialog].into()
111        } else {
112            main_view.into()
113        }
114    }
115}