aboutsummaryrefslogtreecommitdiff
path: root/src/core/components/help.rs
diff options
context:
space:
mode:
authorUMTS at Teleco <crt@teleco.ch>2025-12-13 02:51:15 +0100
committerUMTS at Teleco <crt@teleco.ch>2025-12-13 02:51:15 +0100
commit8323fdd73272a2882781aba3c499ba0be3dff2a6 (patch)
treeffbf86473933e69cfaeef30d5c6ea7e5b494856c /src/core/components/help.rs
committing to insanityHEADmaster
Diffstat (limited to 'src/core/components/help.rs')
-rw-r--r--src/core/components/help.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/core/components/help.rs b/src/core/components/help.rs
new file mode 100644
index 0000000..fb7ede8
--- /dev/null
+++ b/src/core/components/help.rs
@@ -0,0 +1,66 @@
+use eframe::egui;
+use egui_commonmark::{CommonMarkCache, CommonMarkViewer};
+
+#[derive(Clone, Copy)]
+pub struct HelpWindowOptions {
+ pub min_size: egui::Vec2,
+ pub max_size_factor: f32,
+ pub default_width_factor: f32,
+ pub default_height_factor: f32,
+}
+
+impl Default for HelpWindowOptions {
+ fn default() -> Self {
+ Self {
+ min_size: egui::vec2(320.0, 240.0),
+ max_size_factor: 0.9,
+ default_width_factor: 0.5,
+ default_height_factor: 0.6,
+ }
+ }
+}
+
+pub fn show_help_window(
+ ctx: &egui::Context,
+ cache: &mut CommonMarkCache,
+ id_source: impl std::hash::Hash,
+ title: &str,
+ markdown_content: &str,
+ is_open: &mut bool,
+ options: HelpWindowOptions,
+) {
+ if !*is_open {
+ return;
+ }
+
+ let viewport = ctx.available_rect();
+ let max_size = egui::vec2(
+ viewport.width() * options.max_size_factor,
+ viewport.height() * options.max_size_factor,
+ );
+ let default_size = egui::vec2(
+ (viewport.width() * options.default_width_factor)
+ .clamp(options.min_size.x, max_size.x.max(options.min_size.x)),
+ (viewport.height() * options.default_height_factor)
+ .clamp(options.min_size.y, max_size.y.max(options.min_size.y)),
+ );
+
+ let mut open = *is_open;
+ egui::Window::new(title)
+ .id(egui::Id::new(id_source))
+ .collapsible(false)
+ .resizable(true)
+ .default_size(default_size)
+ .min_size(options.min_size)
+ .max_size(max_size)
+ .open(&mut open)
+ .show(ctx, |ui| {
+ egui::ScrollArea::vertical()
+ .auto_shrink([false, false])
+ .show(ui, |ui| {
+ CommonMarkViewer::new().show(ui, cache, markdown_content);
+ });
+ });
+
+ *is_open = open;
+}