Make folder-list collapsible
This commit is contained in:
20
src/app.rs
20
src/app.rs
@ -8,8 +8,8 @@ use std::{
|
||||
|
||||
use crate::{file_editor::FileEditor, folder::Folder, preferences::Preferences, util::GuiSender};
|
||||
use egui::{
|
||||
Align, Button, Color32, Context, FontData, FontDefinitions, Key, Modifiers, PointerButton,
|
||||
RichText, ScrollArea, Stroke,
|
||||
Align, Button, Color32, Context, FontData, FontDefinitions, Image, Key, Modifiers,
|
||||
PointerButton, RichText, ScrollArea, Stroke, Widget, include_image,
|
||||
};
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
@ -26,6 +26,7 @@ pub struct App {
|
||||
|
||||
tabs: Vec<(TabId, Tab)>,
|
||||
|
||||
show_folders: bool,
|
||||
folders: Vec<Folder>,
|
||||
|
||||
open_tab_index: Option<usize>,
|
||||
@ -106,6 +107,7 @@ impl Default for App {
|
||||
tabs: vec![(1, Tab::File(FileEditor::new("note.md")))],
|
||||
open_tab_index: None,
|
||||
next_tab_id: 2,
|
||||
show_folders: false,
|
||||
folders: vec![],
|
||||
}
|
||||
}
|
||||
@ -186,6 +188,9 @@ impl App {
|
||||
Stroke::new(1.0, Color32::from_rgb(200, 200, 200));
|
||||
});
|
||||
|
||||
// enable features on egui_extras to add more image types
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
|
||||
if let Some(storage) = cc.storage {
|
||||
return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
|
||||
}
|
||||
@ -345,7 +350,16 @@ impl eframe::App for App {
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(8.0);
|
||||
|
||||
let image = Image::new(include_image!("../assets/collapse-icon.svg"));
|
||||
let image = image.tint(ui.style().visuals.text_color());
|
||||
if Button::image(image).ui(ui).clicked() {
|
||||
self.show_folders = !self.show_folders;
|
||||
}
|
||||
|
||||
if !self.jobs.handles.is_empty() {
|
||||
ui.add_space(8.0);
|
||||
ui.spinner();
|
||||
}
|
||||
|
||||
@ -374,7 +388,7 @@ impl eframe::App for App {
|
||||
|
||||
egui::SidePanel::left("file browser")
|
||||
.resizable(true)
|
||||
.show(ctx, |ui| {
|
||||
.show_animated(ctx, self.show_folders, |ui| {
|
||||
if ui.button("refresh").clicked() {
|
||||
for folder in &mut self.folders {
|
||||
folder.unload();
|
||||
|
||||
Reference in New Issue
Block a user