Skip to content

Commit

Permalink
feat: add custom loading screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Oct 16, 2023
1 parent eb708ec commit 570c4dc
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 23 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,62 @@ fn main() {
app_namespace: ("org".into(), "fishfolk".into(), "jumpy".into()),
asset_dir: "assets".into(),
packs_dir: "packs".into(),
custom_load_progress: Some(Box::new(load_progress)),
}
.app()
.run();
}

fn load_progress(assets: &AssetServer, ctx: &egui::Context) {
let errored = assets.load_progress.errored();
egui::CentralPanel::default()
.frame(egui::Frame::default().fill(egui::Color32::from_rgb(0x26, 0x2b, 0x44)))
.show(ctx, |ui| {
let height = ui.available_height();
let ctx = ui.ctx().clone();

let space_size = 0.03;
let spinner_size = 0.10;
let text_size = 0.034;
ui.vertical_centered(|ui| {
ui.add_space(height * 0.3);

if errored > 0 {
let err_color = egui::Color32::RED;
ui.label(
egui::RichText::new("⚠")
.color(err_color)
.size(height * spinner_size),
);
ui.add_space(height * space_size);
ui.label(
egui::RichText::new(format!(
"Error loading {errored} asset{}.",
if errored > 1 { "s" } else { "" }
))
.color(err_color)
.size(height * text_size * 0.75),
);
} else {
let rect = ui
.label(
egui::RichText::new("⚓")
.color(egui::Color32::WHITE)
.size(height * spinner_size),
)
.rect;
egui::Spinner::new().paint_at(ui, rect.expand(spinner_size * height * 0.2));
ui.add_space(height * space_size);
ui.label(
egui::RichText::new("Loading")
.color(egui::Color32::WHITE)
.size(height * text_size),
);
}
});

ctx.data_mut(|d| {
d.insert_temp(ui.id(), (spinner_size, space_size, text_size));
})
});
}

0 comments on commit 570c4dc

Please sign in to comment.