#[derive(Clone, Copy, PartialEq)]
pub struct Keybind {
pub key: &'static str,
pub alt: bool,
pub ctrl: bool,
}
impl Keybind {
#[cfg(target_arch = "wasm32")]
pub(crate) fn matches(&self, key: &str, alt: bool, ctrl: bool) -> bool {
self.key == key && self.alt == alt && self.ctrl == ctrl
}
}
#[derive(Clone, Copy, PartialEq)]
pub struct Keybinds {
pub undo: Keybind = Keybind { key: "u", alt: false, ctrl: false },
pub redo: Keybind = Keybind { key: "U", alt: false, ctrl: false },
pub close: Keybind = Keybind { key: "Backspace", alt: false, ctrl: false },
pub maximize: Keybind = Keybind { key: "f", alt: false, ctrl: false },
pub help: Keybind = Keybind { key: "?", alt: false, ctrl: false },
}
impl Default for Keybinds {
fn default() -> Self {
Self { .. }
}
}
#[derive(Clone, Default, PartialEq)]
pub struct Config {
pub keybinds: Keybinds,
pub actions: Vec<(Keybind, dioxus::prelude::Callback<crate::render::packed::PackedApi>)>,
pub steps: u32 = 64,
pub rows: u32 = 36,
}
#[derive(Clone, Copy, Debug, Default, serde::Deserialize, Eq, Hash, PartialEq, serde::Serialize)]
pub enum Breakpoint {
Xs,
Sm,
Md,
Lg,
#[default]
Xl,
}
impl Breakpoint {
pub(crate) fn of(width: f64) -> Self {
match width {
w if w < 576.0 => Self::Xs,
w if w < 768.0 => Self::Sm,
w if w < 992.0 => Self::Md,
w if w < 1200.0 => Self::Lg,
_ => Self::Xl,
}
}
const fn design(self) -> f64 {
match self {
Self::Xs => 576.0,
Self::Sm => 768.0,
Self::Md => 992.0,
Self::Lg => 1200.0,
Self::Xl => 1600.0,
}
}
pub(crate) fn scale_cols(self, base: u32) -> u32 {
((base as f64 * self.design() / Self::Xl.design()).round() as u32).max(1)
}
}
impl std::fmt::Display for Breakpoint {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Xs => "xs",
Self::Sm => "sm",
Self::Md => "md",
Self::Lg => "lg",
Self::Xl => "xl",
})
}
}