Improve visuals slightly
This commit is contained in:
11
src/app.rs
11
src/app.rs
@ -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,7 +471,12 @@ impl eframe::App for App {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
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
|
if let Some(Tab::File(file_editor)) = self
|
||||||
.open_tab_index
|
.open_tab_index
|
||||||
.and_then(|i| self.tabs.get_mut(i))
|
.and_then(|i| self.tabs.get_mut(i))
|
||||||
|
|||||||
@ -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,11 +133,18 @@ 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() {
|
||||||
|
if filter_file(&name) {
|
||||||
child_files.push(File { name, path });
|
child_files.push(File { name, path });
|
||||||
|
}
|
||||||
} else if file_type.is_dir() {
|
} else if file_type.is_dir() {
|
||||||
|
if filter_folder(&name) {
|
||||||
child_folders.push(Folder::NotLoaded { name, path });
|
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,
|
||||||
@ -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"
|
||||||
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user