pub mod edit_mode;
pub use edit_mode::*;
use crate::{message::*, nuhxboard::*, types::*};
use iced::{
widget::{column, container, text},
window, Theme,
};
use iced_multi_window::Window;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ErrorPopup {
pub error: Error,
}
impl Window<NuhxBoard, Theme, Message> for ErrorPopup {
fn class(&self) -> &'static str {
"error"
}
fn id(&self) -> String {
format!("{}_{:?}", self.class(), self.error)
}
fn settings(&self) -> window::Settings {
window::Settings {
size: iced::Size {
width: 400.0,
height: 150.0,
},
resizable: false,
..Default::default()
}
}
fn theme(&self, _app: &NuhxBoard) -> Theme {
Theme::Light
}
fn title(&self, _app: &NuhxBoard) -> String {
"Error".to_string()
}
fn view<'a>(&self, _app: &'a NuhxBoard) -> iced::Element<'a, Message, Theme> {
let error = &self.error;
let kind = match error {
Error::ConfigOpen(_) => "Keyboard file could not be opened.",
Error::ConfigParse(_) => "Keyboard file could not be parsed.",
Error::StyleOpen(_) => "Style file could not be opened.",
Error::StyleParse(_) => "Style file could not be parsed.",
Error::UnknownKey(_) => "Unknown Key.",
Error::UnknownButton(_) => "Unknown Mouse Button.",
};
let info = match error {
Error::ConfigParse(e) => e.clone(),
Error::ConfigOpen(e) => e.clone(),
Error::StyleParse(e) => e.clone(),
Error::StyleOpen(e) => e.clone(),
Error::UnknownKey(key) => format!("Key: {:?}", key),
Error::UnknownButton(button) => format!("Button: {:?}", button),
};
container(
column![text("Error:"), text(kind), text("More info:"), text(info),]
.align_x(iced::Alignment::Center),
)
.height(iced::Length::Fill)
.width(iced::Length::Fill)
.align_x(iced::alignment::Horizontal::Center)
.align_y(iced::alignment::Vertical::Center)
.into()
}
}