From 47b7feeab8e19f27c8bb5064efb2576e6f83593b Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Sat, 4 Oct 2025 08:55:36 +0200 Subject: [PATCH] Improve visuals slightly --- src/app.rs | 31 +++++++++++++---------- src/folder.rs | 62 +++++++++++++++++++++++++++++++++++++++++++--- src/preferences.rs | 7 +++++- 3 files changed, 82 insertions(+), 18 deletions(-) diff --git a/src/app.rs b/src/app.rs index 30aecf3..e9e52dd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -15,8 +15,8 @@ use crate::{ util::{GuiSender, file_mtime, log_error}, }; use egui::{ - Align, Button, Context, FontData, FontDefinitions, FontFamily, FontId, Image, Key, Modifiers, - PointerButton, RichText, ScrollArea, Theme, Widget, include_image, + Align, Button, Context, FontData, FontDefinitions, FontFamily, FontId, Frame, Image, Key, + Modifiers, PointerButton, RichText, ScrollArea, Theme, Widget, include_image, }; use eyre::eyre; @@ -471,19 +471,24 @@ impl eframe::App for App { }); }); - egui::CentralPanel::default().show(ctx, |ui| { - if let Some(Tab::File(file_editor)) = self - .open_tab_index - .and_then(|i| self.tabs.get_mut(i)) - .map(|(_tab_id, tab)| tab) - { - file_editor.show(ui, &self.preferences); - } + egui::CentralPanel::default() + .frame(Frame { + fill: ctx.style().visuals.window_fill(), + ..Frame::central_panel(&ctx.style()) + }) + .show(ctx, |ui| { + if let Some(Tab::File(file_editor)) = self + .open_tab_index + .and_then(|i| self.tabs.get_mut(i)) + .map(|(_tab_id, tab)| tab) + { + file_editor.show(ui, &self.preferences); + } - ui.with_layout(egui::Layout::bottom_up(Align::LEFT), |ui| { - egui::warn_if_debug_build(ui); + ui.with_layout(egui::Layout::bottom_up(Align::LEFT), |ui| { + egui::warn_if_debug_build(ui); + }); }); - }); } } diff --git a/src/folder.rs b/src/folder.rs index 6cf9628..5169a33 100644 --- a/src/folder.rs +++ b/src/folder.rs @@ -7,7 +7,7 @@ use std::{ thread, }; -use egui::{Response, Ui}; +use egui::{Button, Color32, Response, Stroke, TextWrapMode, Ui, Vec2, Widget}; use eyre::{Context, OptionExt, eyre}; use serde::{Deserialize, Serialize}; @@ -52,20 +52,59 @@ impl Deref for FolderResponse<'_> { impl LoadedFolder { pub fn show<'a>(&'a mut self, ui: &mut Ui) -> FolderResponse<'a> { let mut open_file = None; + + let draw_highlight = |ui: &mut Ui, rect| { + ui.painter().rect( + rect, + 2.0, + if ui.visuals().dark_mode { + Color32::from_white_alpha(16) + } else { + Color32::from_black_alpha(16) + }, + Stroke::NONE, + egui::StrokeKind::Outside, + ); + }; + let inner = ui .collapsing(&self.name, |ui| { for folder in &mut self.child_folders { open_file = open_file.or(folder.show(ui).open_file); } + let w = ui.available_width(); + + let mut first = true; + for file in &mut self.child_files { - if ui.button(&file.name).clicked() { + if !first { + ui.add_space(2.0); + } + first = false; + + let button = Button::new(&file.name) + .min_size(Vec2::new(w, 0.0)) + .wrap_mode(TextWrapMode::Truncate) + .frame(false) + .corner_radius(0.0) + .ui(ui); + + if button.hovered() { + draw_highlight(ui, button.rect); + } + + if button.clicked() { open_file = Some(file.path.as_path()) }; } }) .header_response; + if inner.hovered() { + draw_highlight(ui, inner.rect); + } + FolderResponse { inner, open_file } } @@ -94,12 +133,19 @@ impl LoadedFolder { log::error!("Symlinks not yet supported, skipping {path:?}"); continue; } else if file_type.is_file() { - child_files.push(File { name, path }); + if filter_file(&name) { + child_files.push(File { name, path }); + } } else if file_type.is_dir() { - child_folders.push(Folder::NotLoaded { name, path }); + if filter_folder(&name) { + child_folders.push(Folder::NotLoaded { name, path }); + } } } + child_folders.sort_by_key(|folder| folder.name().to_owned()); + child_files.sort_by_key(|file| (!file.name.ends_with(".md"), file.name.clone())); + let folder = LoadedFolder { name, path, @@ -216,3 +262,11 @@ impl<'de> Deserialize<'de> for Folder { Ok(Folder::NotLoaded { name, path }) } } + +fn filter_folder(_folder_name: &str) -> bool { + true +} + +fn filter_file(file_name: &str) -> bool { + file_name != ".DS_Store" +} diff --git a/src/preferences.rs b/src/preferences.rs index a0f6839..ce223f3 100644 --- a/src/preferences.rs +++ b/src/preferences.rs @@ -49,7 +49,12 @@ impl Preferences { let mut dark_visuals = Visuals::dark(); let mut light_visuals = Visuals::light(); - dark_visuals.code_bg_color = Color32::BLACK; + dark_visuals.window_fill = Color32::from_rgb(0x1e, 0x1e, 0x1e); + dark_visuals.panel_fill = Color32::from_rgb(0x26, 0x26, 0x26); + + light_visuals.window_fill = Color32::WHITE; + light_visuals.panel_fill = Color32::from_rgb(0xf6, 0xf6, 0xf6); + dark_visuals.code_bg_color = Color32::BLACK; light_visuals.code_bg_color = Color32::WHITE;