Skip to content

Commit

Permalink
Add a close button to the loaded files (#22)
Browse files Browse the repository at this point in the history
* Add a close button

* Format and lint

* Put the close button next to the collapse view

Co-authored-by: Anil Tuncel <[email protected]>
  • Loading branch information
adrien-berchet and anilbey authored Dec 8, 2022
1 parent 2f3815b commit d65190e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::gui::egui::Ui;
use crate::hdf;
use crate::plot::Demo;
use eframe::egui;
use eframe::egui::RichText;

#[derive(Default)]
pub(crate) struct NWBView {
Expand Down Expand Up @@ -101,16 +102,22 @@ impl eframe::App for NWBView {
mem::swap(&mut all_loaded_files, &mut self.loaded_files);

egui::ScrollArea::vertical().show(ui, |sub_ui| {
for loaded_file in &all_loaded_files {
sub_ui.collapsing(loaded_file.file.filename(), |header_ui| {
println!("The file {} is loaded", loaded_file.file.filename());
for groups in &loaded_file.tree.groups {
self.create_group_recursion(groups, header_ui, ctx);
}
for loaded_file in all_loaded_files.iter_mut() {
sub_ui.horizontal(|horizontal_ui| {
if horizontal_ui.button(RichText::new("❌")).clicked() {
loaded_file.is_opened = false; // Mark the file as closed
};
horizontal_ui.collapsing(loaded_file.file.filename(), |header_ui| {
println!("The file {} is loaded", loaded_file.file.filename());
for groups in &loaded_file.tree.groups {
self.create_group_recursion(groups, header_ui, ctx);
}
});
});
}
});

all_loaded_files.retain(|x| x.is_opened); // Remove closed files
mem::swap(&mut all_loaded_files, &mut self.loaded_files);

ui.horizontal(|ui| {
Expand Down
2 changes: 2 additions & 0 deletions src/hdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct GroupTree {
pub struct FileTree {
pub file: hdf5::File,
pub tree: GroupTree,
pub is_opened: bool,
}

pub(crate) fn build_tree(group: hdf5::Group) -> GroupTree {
Expand Down Expand Up @@ -43,6 +44,7 @@ pub(crate) fn read_nwb_file(path: &str) -> Option<FileTree> {
Ok(y) => Some(FileTree {
file: x,
tree: build_tree(y),
is_opened: true,
}),
},
}
Expand Down

0 comments on commit d65190e

Please sign in to comment.