From fdb54e9b0c814bbe90d71a48e4ade152c33966c7 Mon Sep 17 00:00:00 2001 From: Ruben Kharel Date: Tue, 7 May 2024 20:39:09 -0400 Subject: [PATCH] add tidy up button --- src/custom_widgets.rs | 13 ++++++++ src/pages/app.rs | 71 ----------------------------------------- src/pages/blog.rs | 2 +- src/pages/mod.rs | 7 ++-- src/pages/playground.rs | 19 +++++++++++ src/pages/resume.rs | 6 ++-- src/wrap_pages.rs | 26 +++++++++++++++ 7 files changed, 67 insertions(+), 77 deletions(-) delete mode 100644 src/pages/app.rs create mode 100644 src/pages/playground.rs diff --git a/src/custom_widgets.rs b/src/custom_widgets.rs index 17b0515..67d3164 100644 --- a/src/custom_widgets.rs +++ b/src/custom_widgets.rs @@ -28,3 +28,16 @@ pub fn footer(ui: &mut egui::Ui) { }); } +pub fn organize_items(ui: &mut egui::Ui) { + // ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| { + if ui + .add( + egui::Button::new("Tidy up") + ) + .clicked() + { + ui.ctx().memory_mut(|mem| mem.reset_areas()); + ui.close_menu(); + } + // }); +} \ No newline at end of file diff --git a/src/pages/app.rs b/src/pages/app.rs deleted file mode 100644 index 9afa0e6..0000000 --- a/src/pages/app.rs +++ /dev/null @@ -1,71 +0,0 @@ -use egui_extras::install_image_loaders; - -/// We derive Deserialize/Serialize so we can persist app state on shutdown. -#[derive(serde::Deserialize, serde::Serialize)] -#[serde(default)] // if we add new fields, give them default values when deserializing old state -pub struct TemplateApp { - // Example stuff: - label: String, - - #[serde(skip)] // This how you opt-out of serialization of a field - value: f32, -} - -impl Default for TemplateApp { - fn default() -> Self { - Self { - // Example stuff: - label: "Hello World!".to_owned(), - value: 2.7, - } - } -} - -impl TemplateApp { - /// Called once before the first frame. - pub fn new(cc: &eframe::CreationContext<'_>) -> Self { - // This is also where you can customize the look and feel of egui using - // `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`. - - install_image_loaders(&cc.egui_ctx); - // Load previous app state (if any). - // Note that you must enable the `persistence` feature for this to work. - if let Some(storage) = cc.storage { - return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default(); - } - Default::default() - } -} - -impl eframe::App for TemplateApp { - /// Called by the frame work to save state before shutdown. - fn save(&mut self, storage: &mut dyn eframe::Storage) { - eframe::set_value(storage, eframe::APP_KEY, self); - } - - /// Called each time the UI needs repainting, which may be many times per second. - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { - // Put your widgets into a `SidePanel`, `TopBottomPanel`, `CentralPanel`, `Window` or `Area`. - // For inspiration and more examples, go to https://emilk.github.io/egui - - egui::TopBottomPanel::top("top_panel").show(ctx, |ui| { - // The top panel is often a good place for a menu bar: - - egui::menu::bar(ui, |ui| { - // NOTE: no File->Quit on web pages! - let is_web = cfg!(target_arch = "wasm32"); - if !is_web { - ui.menu_button("Home", |ui| { - if ui.button("Quit").clicked() { - ctx.send_viewport_cmd(egui::ViewportCommand::Close); - } - }); - ui.add_space(16.0); - } - egui::widgets::global_dark_light_mode_switch(ui); - // egui::widgets::global_dark_light_mode_buttons(ui); - }); - }); - - } -} diff --git a/src/pages/blog.rs b/src/pages/blog.rs index e60911a..6217b6c 100644 --- a/src/pages/blog.rs +++ b/src/pages/blog.rs @@ -1,7 +1,7 @@ use egui_commonmark::{CommonMarkCache, CommonMarkViewer}; use include_dir::{include_dir, Dir}; -use crate::custom_widgets::{powered_by_egui_and_eframe, footer}; +use crate::custom_widgets::{powered_by_egui_and_eframe, footer, organize_items}; #[derive(Debug, serde::Deserialize, serde::Serialize)] pub struct Blogs { diff --git a/src/pages/mod.rs b/src/pages/mod.rs index c7aaab4..16128ce 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -4,5 +4,8 @@ pub use resume::ResumePage; mod blog; pub use blog::BlogPage; -mod app; -pub use app::TemplateApp; +// mod app; +// pub use app::TemplateApp; + +mod playground; +pub use playground::Playground; diff --git a/src/pages/playground.rs b/src/pages/playground.rs new file mode 100644 index 0000000..7604f97 --- /dev/null +++ b/src/pages/playground.rs @@ -0,0 +1,19 @@ +#[derive(serde::Deserialize, serde::Serialize)] +pub struct Playground; + +impl Default for Playground { + fn default() -> Self { + Self + } +} + +impl eframe::App for Playground { + fn update(&mut self, _ctx: &egui::Context, _frame: &mut eframe::Frame) { + egui::CentralPanel::default().show(_ctx, |ui| { + ui.heading("Playground"); + ui.label("This is a playground page."); + }); + } + + fn save(&mut self, _storage: &mut dyn eframe::Storage) {} +} \ No newline at end of file diff --git a/src/pages/resume.rs b/src/pages/resume.rs index 7a7268d..b6f924a 100644 --- a/src/pages/resume.rs +++ b/src/pages/resume.rs @@ -16,7 +16,7 @@ mod interests; pub use self::links::Links; mod links; -pub use crate::custom_widgets::powered_by_egui_and_eframe; +pub use crate::custom_widgets::{powered_by_egui_and_eframe, footer, organize_items}; #[derive(Debug, serde::Deserialize, serde::Serialize)] struct Resume { @@ -177,9 +177,9 @@ impl eframe::App for ResumePage { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { + footer(ui); powered_by_egui_and_eframe(ui); - // insert everything inside drag and drop - + egui::Window::new(format!( "{} | {}", self.resume.header.name, self.resume.header.current_title diff --git a/src/wrap_pages.rs b/src/wrap_pages.rs index d4e767f..13d1a09 100644 --- a/src/wrap_pages.rs +++ b/src/wrap_pages.rs @@ -1,4 +1,5 @@ use std::fmt; +use crate::custom_widgets::organize_items; #[derive(Default)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -6,6 +7,7 @@ use std::fmt; pub struct State { resume_page: crate::pages::ResumePage, blog_page: crate::pages::BlogPage, + playground_page: crate::pages::Playground, selected_anchor: Anchor, } @@ -15,6 +17,7 @@ pub struct State { enum Anchor { Blog, Resume, + Playground // Clear, } @@ -24,6 +27,19 @@ enum Command { Nothing, } + + + +//██████╗ ██╗ █████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗ ███╗ ██╗ ██████╗ +//██╔══██╗ ██║ ██╔══██╗ ╚██╗ ██╔╝ ██╔════╝ ██╔══██╗ ██╔═══██╗ ██║ ██║ ████╗ ██║ ██╔══██╗ +//██████╔╝ ██║ ███████║ ╚████╔╝ ██║ ███╗ ██████╔╝ ██║ ██║ ██║ ██║ ██╔██╗ ██║ ██║ ██║ +//██╔═══╝ ██║ ██╔══██║ ╚██╔╝ ██║ ██║ ██╔══██╗ ██║ ██║ ██║ ██║ ██║╚██╗██║ ██║ ██║ +//██║ ███████╗ ██║ ██║ ██║ ╚██████╔╝ ██║ ██║ ╚██████╔╝ ╚██████╔╝ ██║ ╚████║ ██████╔╝ +//╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ + + + + impl Anchor { #[cfg(target_arch = "wasm32")] fn all() -> Vec { @@ -82,6 +98,11 @@ impl WrapPages { Anchor::Resume, &mut self.state.resume_page as &mut dyn eframe::App, ), + ( + "Playground", + Anchor::Playground, + &mut self.state.playground_page as &mut dyn eframe::App, + ), ]; vec.into_iter() @@ -114,6 +135,10 @@ impl WrapPages { } } } + + ui.separator(); + + organize_items(ui); self.state.selected_anchor = selected_anchor; } } @@ -122,6 +147,7 @@ impl eframe::App for WrapPages { fn save(&mut self, storage: &mut dyn eframe::Storage) { eframe::set_value(storage, eframe::APP_KEY, &self.state.blog_page); eframe::set_value(storage, eframe::APP_KEY, &self.state.resume_page); + eframe::set_value(storage, eframe::APP_KEY, &self.state.playground_page); } fn clear_color(&self, visuals: &egui::Visuals) -> [f32; 4] {