Added info, warn, and error toasts
This commit is contained in:
74
xmpd-gui/src/windows/debug.rs
Normal file
74
xmpd-gui/src/windows/debug.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use egui::RichText;
|
||||
|
||||
use crate::components::{toast::{self, ToastType}, CompGetter};
|
||||
|
||||
use super::Window;
|
||||
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct DebugW {
|
||||
toast_title: String,
|
||||
toast_descr: String,
|
||||
toast_type: ToastType,
|
||||
}
|
||||
|
||||
impl Window for DebugW {
|
||||
fn draw(&mut self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
|
||||
ui.group(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.label(
|
||||
RichText::new("DEBUG")
|
||||
.heading()
|
||||
);
|
||||
ui.horizontal(|ui| {
|
||||
{
|
||||
ui.group(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.label(
|
||||
RichText::new("Toast")
|
||||
.heading()
|
||||
);
|
||||
Self::add_input_field(&mut self.toast_title, ui, "Title");
|
||||
Self::add_input_field(&mut self.toast_descr, ui, "Description");
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Type:");
|
||||
egui::ComboBox::from_id_source("debug_combo")
|
||||
.selected_text(format!("{:?}", self.toast_type))
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut self.toast_type, ToastType::Info, "Info");
|
||||
ui.selectable_value(&mut self.toast_type, ToastType::Warn, "Warn");
|
||||
ui.selectable_value(&mut self.toast_type, ToastType::Error, "Error");
|
||||
}
|
||||
);
|
||||
});
|
||||
if ui.button("Add").clicked() {
|
||||
toast::Toast::get().unwrap().show_toast(&self.toast_title, &self.toast_descr, self.toast_type);
|
||||
}
|
||||
if ui.button("Throw Error").clicked() {
|
||||
handle_error_ui!(Err(anyhow::anyhow!("{}: {}", self.toast_title, self.toast_descr)));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl DebugW {
|
||||
fn add_input_field(inp: &mut String, ui: &mut egui::Ui, name: &str) {
|
||||
ui.horizontal(|ui|{
|
||||
ui.label(format!("{name}: "));
|
||||
ui.text_edit_singleline(inp);
|
||||
});
|
||||
}
|
||||
fn add_input_field_ml(inp: &mut String, ui: &mut egui::Ui, name: &str) {
|
||||
ui.horizontal(|ui|{
|
||||
ui.label(format!("{name}: "));
|
||||
ui.text_edit_multiline(inp);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user