macro_rules! define_animations {
(
$(
$(#[$attr:meta])*
$variant:ident($app:ty) {
title: $title:literal,
name: $name:literal,
}
),* $(,)?
) => {
#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub(crate) enum Animation {
Base,
$(
$(#[$attr])*
$variant($app),
)*
}
impl Default for Animation {
fn default() -> Self {
Self::Base
}
}
impl Animation {
pub(crate) fn show(
&mut self,
ui: &mut egui::Ui,
error_manager: &mut ErrorManager,
) {
match self {
Self::Base => {
bladvak::utils::central_ui(ui, |ui| {
ui.label("Welcome to yakb");
ui.add(egui::Hyperlink::new("https://yakb.n4n5.dev").open_in_new_tab(true));
});
}
$(
Self::$variant(app) => {
app.show(ui, error_manager);
}
)*
}
}
}
impl YakbApp {
pub(crate) fn show_menu(&mut self, ui: &mut egui::Ui) {
if ui
.selectable_label(matches!(self.animation, Animation::Base), "Base")
.clicked()
{
self.animation = Animation::Base;
}
$(
if ui.selectable_label(
matches!(self.animation, Animation::$variant(_)),
$title,
)
.clicked()
{
self.animation = Animation::$variant(<$app>::default());
}
)*
}
}
impl TryFrom<&str> for Animation {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
$(
$name => Ok(Self::$variant(<$app>::default())),
)*
_ => Err("No animation".to_string()),
}
}
}
};
}
pub(crate) use define_animations;