From 45f29e08be8063c28de6ea03273aa14610e87b2c Mon Sep 17 00:00:00 2001 From: FluxxCode Date: Sat, 13 Jan 2024 22:30:34 +0100 Subject: [PATCH] Add left panel ui --- examples/sandbox/Cargo.toml | 3 +++ examples/sandbox/src/main.rs | 6 ++++-- src/file_explorer.rs | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/examples/sandbox/Cargo.toml b/examples/sandbox/Cargo.toml index 979ee90b..8a4d40ff 100644 --- a/examples/sandbox/Cargo.toml +++ b/examples/sandbox/Cargo.toml @@ -8,3 +8,6 @@ edition = "2021" [dependencies] eframe = { version = "0.25.0", default-features = false, features = ["glow"] } egui-file-explorer = { version = "0.1.0", path = "../../"} + +# Enable image loading +egui_extras = { version = "0.25.0", default-features = false, features = ["all_loaders"]} diff --git a/examples/sandbox/src/main.rs b/examples/sandbox/src/main.rs index b3248a51..fbbb13b4 100644 --- a/examples/sandbox/src/main.rs +++ b/examples/sandbox/src/main.rs @@ -6,7 +6,9 @@ struct MyApp { } impl MyApp { - pub fn new() -> Self { + pub fn new(cc: &eframe::CreationContext) -> Self { + egui_extras::install_image_loaders(&cc.egui_ctx); + Self { file_explorer: FileExplorer::new() } @@ -32,6 +34,6 @@ fn main() -> eframe::Result<()> { eframe::run_native( "My egui application", options, - Box::new(|_| Box::new(MyApp::new())) + Box::new(|ctx| Box::new(MyApp::new(ctx))) ) } diff --git a/src/file_explorer.rs b/src/file_explorer.rs index 2109f4c5..f05d65e0 100644 --- a/src/file_explorer.rs +++ b/src/file_explorer.rs @@ -24,7 +24,7 @@ impl FileExplorer { .default_width(150.0) .width_range(80.0..=300.0) .show_inside(ui, |ui| { - self.update_left_panel(ui); + self.update_left_panel(ctx, ui); }); egui::TopBottomPanel::bottom("fe_bottom_panel") @@ -76,13 +76,40 @@ impl FileExplorer { }); }); }) + + // TODO: Search bar }); ui.add_space(ctx.style().spacing.item_spacing.y); } - fn update_left_panel(&mut self, ui: &mut egui::Ui) { - ui.label("This is the left panel!"); + fn update_left_panel(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) { + ui.label("Drives:"); + + // NOTE: These are currently only hardcoded test values! + ui.add_sized(egui::Vec2::new(ui.available_width(), 0.0), egui::Button::new("(C:)")); + ui.add_sized(egui::Vec2::new(ui.available_width(), 0.0), egui::Button::new("Toshiba(D:)")); + ui.add_sized(egui::Vec2::new(ui.available_width(), 0.0), + egui::Button::new("Samsung 980..(E:)")); + ui.add_sized(egui::Vec2::new(ui.available_width(), 0.0), egui::Button::new("(F:)")); + + ui.add_space(ctx.style().spacing.item_spacing.y * 4.0); + + ui.label("User:"); + + let folder_icon = egui::include_image!("../data/folder_icon.png"); + + // NOTE: These are currently only hardcoded test values! + ui.add_sized(egui::Vec2::new(ui.available_width(), 0.0), + egui::Button::image_and_text(folder_icon.clone(), "Desktop")); + ui.add_sized(egui::Vec2::new(ui.available_width(), 0.0), + egui::Button::image_and_text(folder_icon.clone(), "Documents")); + ui.add_sized(egui::Vec2::new(ui.available_width(), 0.0), + egui::Button::image_and_text(folder_icon.clone(), "Downloads")); + ui.add_sized(egui::Vec2::new(ui.available_width(), 0.0), + egui::Button::image_and_text(folder_icon.clone(), "Music")); + ui.add_sized(egui::Vec2::new(ui.available_width(), 0.0), + egui::Button::image_and_text(folder_icon.clone(), "Pictures")); } fn update_bottom_panel(&mut self, ui: &mut egui::Ui) {