Improve visuals slightly

This commit is contained in:
2025-10-04 08:55:36 +02:00
parent b1eb5f91be
commit 47b7feeab8
3 changed files with 82 additions and 18 deletions

View File

@ -15,8 +15,8 @@ use crate::{
util::{GuiSender, file_mtime, log_error}, util::{GuiSender, file_mtime, log_error},
}; };
use egui::{ use egui::{
Align, Button, Context, FontData, FontDefinitions, FontFamily, FontId, Image, Key, Modifiers, Align, Button, Context, FontData, FontDefinitions, FontFamily, FontId, Frame, Image, Key,
PointerButton, RichText, ScrollArea, Theme, Widget, include_image, Modifiers, PointerButton, RichText, ScrollArea, Theme, Widget, include_image,
}; };
use eyre::eyre; use eyre::eyre;
@ -471,19 +471,24 @@ impl eframe::App for App {
}); });
}); });
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default()
if let Some(Tab::File(file_editor)) = self .frame(Frame {
.open_tab_index fill: ctx.style().visuals.window_fill(),
.and_then(|i| self.tabs.get_mut(i)) ..Frame::central_panel(&ctx.style())
.map(|(_tab_id, tab)| tab) })
{ .show(ctx, |ui| {
file_editor.show(ui, &self.preferences); 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| { ui.with_layout(egui::Layout::bottom_up(Align::LEFT), |ui| {
egui::warn_if_debug_build(ui); egui::warn_if_debug_build(ui);
});
}); });
});
} }
} }

View File

@ -7,7 +7,7 @@ use std::{
thread, thread,
}; };
use egui::{Response, Ui}; use egui::{Button, Color32, Response, Stroke, TextWrapMode, Ui, Vec2, Widget};
use eyre::{Context, OptionExt, eyre}; use eyre::{Context, OptionExt, eyre};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -52,20 +52,59 @@ impl Deref for FolderResponse<'_> {
impl LoadedFolder { impl LoadedFolder {
pub fn show<'a>(&'a mut self, ui: &mut Ui) -> FolderResponse<'a> { pub fn show<'a>(&'a mut self, ui: &mut Ui) -> FolderResponse<'a> {
let mut open_file = None; 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 let inner = ui
.collapsing(&self.name, |ui| { .collapsing(&self.name, |ui| {
for folder in &mut self.child_folders { for folder in &mut self.child_folders {
open_file = open_file.or(folder.show(ui).open_file); 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 { 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()) open_file = Some(file.path.as_path())
}; };
} }
}) })
.header_response; .header_response;
if inner.hovered() {
draw_highlight(ui, inner.rect);
}
FolderResponse { inner, open_file } FolderResponse { inner, open_file }
} }
@ -94,12 +133,19 @@ impl LoadedFolder {
log::error!("Symlinks not yet supported, skipping {path:?}"); log::error!("Symlinks not yet supported, skipping {path:?}");
continue; continue;
} else if file_type.is_file() { } 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() { } 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 { let folder = LoadedFolder {
name, name,
path, path,
@ -216,3 +262,11 @@ impl<'de> Deserialize<'de> for Folder {
Ok(Folder::NotLoaded { name, path }) Ok(Folder::NotLoaded { name, path })
} }
} }
fn filter_folder(_folder_name: &str) -> bool {
true
}
fn filter_file(file_name: &str) -> bool {
file_name != ".DS_Store"
}

View File

@ -49,7 +49,12 @@ impl Preferences {
let mut dark_visuals = Visuals::dark(); let mut dark_visuals = Visuals::dark();
let mut light_visuals = Visuals::light(); 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; dark_visuals.code_bg_color = Color32::BLACK;
light_visuals.code_bg_color = Color32::WHITE; light_visuals.code_bg_color = Color32::WHITE;