generated from PlexSheep/rs-base
feat(info): add info diag
cargo devel CI / cargo CI (push) Successful in 2m57s
Details
cargo devel CI / cargo CI (push) Successful in 2m57s
Details
This commit is contained in:
parent
8f51a5ff44
commit
48d81d57b6
|
@ -25,3 +25,4 @@ libpt = { version = "0.6.0", features = ["cli"] }
|
||||||
clap = { version = "4.5.15", features = ["derive"] }
|
clap = { version = "4.5.15", features = ["derive"] }
|
||||||
image = "0.25.2"
|
image = "0.25.2"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
rfd = "0.14.1"
|
||||||
|
|
53
src/app.rs
53
src/app.rs
|
@ -1,6 +1,7 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use egui::IconData;
|
use egui::IconData;
|
||||||
use libpt::cli::args::{VerbosityLevel, HELP_TEMPLATE};
|
use libpt::cli::args::{VerbosityLevel, HELP_TEMPLATE};
|
||||||
|
use libpt::log::{debug, trace};
|
||||||
|
|
||||||
pub const TITLE: &str = "Rollator";
|
pub const TITLE: &str = "Rollator";
|
||||||
|
|
||||||
|
@ -21,6 +22,10 @@ pub struct RollatorApp {
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
#[command(flatten)]
|
#[command(flatten)]
|
||||||
pub(crate) verbosity: VerbosityLevel,
|
pub(crate) verbosity: VerbosityLevel,
|
||||||
|
|
||||||
|
#[serde(skip)]
|
||||||
|
#[clap(skip)]
|
||||||
|
show_info_window: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RollatorApp {
|
impl Default for RollatorApp {
|
||||||
|
@ -29,6 +34,7 @@ impl Default for RollatorApp {
|
||||||
label: TITLE.to_owned(),
|
label: TITLE.to_owned(),
|
||||||
value: 2.7,
|
value: 2.7,
|
||||||
verbosity: VerbosityLevel::INFO,
|
verbosity: VerbosityLevel::INFO,
|
||||||
|
show_info_window: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +60,43 @@ impl RollatorApp {
|
||||||
pub fn new_with_cli() -> Self {
|
pub fn new_with_cli() -> Self {
|
||||||
Self::parse()
|
Self::parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn info_diag(&mut self, ctx: &egui::Context) {
|
||||||
|
trace!("rendering info dialogue");
|
||||||
|
ctx.show_viewport_immediate(
|
||||||
|
egui::ViewportId::from_hash_of("immediate_viewport"),
|
||||||
|
egui::ViewportBuilder::default()
|
||||||
|
.with_title("Immediate Viewport")
|
||||||
|
.with_inner_size([500.0, 200.0]),
|
||||||
|
|ctx, class| {
|
||||||
|
assert!(
|
||||||
|
class == egui::ViewportClass::Immediate,
|
||||||
|
"This egui backend doesn't support multiple viewports"
|
||||||
|
);
|
||||||
|
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.spacing_mut().item_spacing.x = 0.0;
|
||||||
|
ui.label(format!("{TITLE} v{}", env!("CARGO_PKG_VERSION")));
|
||||||
|
ui.hyperlink_to("Source Code\n", env!("CARGO_PKG_REPOSITORY"));
|
||||||
|
ui.label(format!("Author: {}", env!("CARGO_PKG_AUTHORS")));
|
||||||
|
ui.label(format!("License: {}", env!("CARGO_PKG_LICENSE")));
|
||||||
|
ui.label(format!(
|
||||||
|
"\n{TITLE} is free software. If you paid for this you were scammed.\n"
|
||||||
|
));
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bottom_label(ui);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
});
|
||||||
|
if ctx.input(|i| i.viewport().close_requested()) {
|
||||||
|
// Tell parent viewport that we should not show next frame:
|
||||||
|
self.show_info_window = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl eframe::App for RollatorApp {
|
impl eframe::App for RollatorApp {
|
||||||
|
@ -75,17 +118,19 @@ impl eframe::App for RollatorApp {
|
||||||
let is_web = cfg!(target_arch = "wasm32");
|
let is_web = cfg!(target_arch = "wasm32");
|
||||||
if !is_web {
|
if !is_web {
|
||||||
ui.menu_button("File", |ui| {
|
ui.menu_button("File", |ui| {
|
||||||
if ui.button("Quit").clicked() {
|
if ui.button("Info").clicked() {
|
||||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
self.show_info_window = true;
|
||||||
}
|
}
|
||||||
});
|
ui.add_space(4.0);
|
||||||
ui.menu_button("AAAA", |ui| {
|
|
||||||
if ui.button("Quit").clicked() {
|
if ui.button("Quit").clicked() {
|
||||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.add_space(16.0);
|
ui.add_space(16.0);
|
||||||
}
|
}
|
||||||
|
if self.show_info_window {
|
||||||
|
self.info_diag(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
egui::widgets::global_dark_light_mode_buttons(ui);
|
egui::widgets::global_dark_light_mode_buttons(ui);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue