Improve visuals slightly
This commit is contained in:
@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user