Settings panel ui

This commit is contained in:
2024-11-15 14:58:09 +02:00
parent a060161c64
commit b29caa58b4
10 changed files with 132 additions and 68 deletions

View File

@@ -12,7 +12,7 @@ lazy_static::lazy_static!(
);
pub trait Window: std::fmt::Debug + Send {
fn draw(&self, ui: &mut egui::Ui, state: &mut GuiState) -> crate::Result<()>;
fn draw(&mut self, ui: &mut egui::Ui, state: &mut GuiState) -> crate::Result<()>;
}
#[derive(Debug, Clone, Hash, PartialEq, PartialOrd, Ord, Eq)]
@@ -36,25 +36,38 @@ impl Windows {
}
pub fn add_all_windows(&mut self) {
self.add_new_window(WindowId::Error, "Error!", Box::<error::ErrorW>::default())
self.add_new_window(WindowId::Error, "Error!", Box::<error::ErrorW>::default());
self.add_new_window(WindowId::Settings, "Settings", Box::<settings::SettingsW>::default());
}
pub fn add_new_window(&mut self, id: WindowId, title: &str, cb: Box<dyn Window>) {
let builder = ViewportBuilder::default()
.with_window_type(egui::X11WindowType::Dialog)
.with_title(title);
self.windows.insert(id.clone(), (ViewportId::from_hash_of(id.clone()), builder));
WINDOWS.lock().unwrap().insert(id, cb);
}
pub fn draw_all(&mut self, ctx: &egui::Context, state: &mut GuiState) {
let theme = handle_error_ui!(xmpd_settings::Settings::get()).theme.clone();
for (win_id, (vp_id, builder)) in &self.windows {
if self.is_open(&win_id) {
ctx.show_viewport_immediate(vp_id.clone(), builder.clone(), |ctx, _vp_class| {
ctx.input(|inp| {
self.toggle(win_id, !inp.viewport().close_requested());
});
egui::CentralPanel::default().show(ctx, |ui| {
WINDOWS.lock().unwrap().get(&win_id).unwrap().draw(ui, state)
egui::CentralPanel::default()
.frame(
egui::Frame::none()
.fill(theme.primary_bg_color)
.stroke(egui::Stroke::new(
1.0,
theme.secondary_bg_color,
)),
)
.show(ctx, |ui| {
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
WINDOWS.lock().unwrap().get_mut(&win_id).unwrap().draw(ui, state)
})
});
}