Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Added filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Aug 28, 2023
1 parent 8844bd1 commit 66adf7d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
64 changes: 48 additions & 16 deletions src/ui/file_view.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use directories::UserDirs;
use eframe::egui;
use egui::{Layout, ScrollArea, TextEdit, Ui};
use egui::{ScrollArea, TextEdit, Ui};
use egui_extras::{Column, TableBuilder};
use icy_engine::SauceData;

Expand Down Expand Up @@ -44,6 +44,8 @@ pub struct FileView {
scroll_pos: Option<usize>,
/// Files in directory.
pub files: Vec<FileEntry>,

pub filter: String,
}

impl FileView {
Expand Down Expand Up @@ -71,6 +73,7 @@ impl FileView {
selected_file: None,
scroll_pos: None,
files: Vec::new(),
filter: String::new(),
}
}

Expand All @@ -84,22 +87,28 @@ impl FileView {
self.refresh();
}
});
ui.with_layout(Layout::right_to_left(egui::Align::Center), |ui| {
let response = ui.button("⟲").on_hover_text("Refresh");
if response.clicked() {
self.refresh();

match self.path.to_str() {
Some(path) => {
let mut path_edit = path.to_string();
let _response =
ui.add_sized([250.0, 20.0], TextEdit::singleline(&mut path_edit));
}
match self.path.to_str() {
Some(path) => {
let mut path_edit = path.to_string();
let _response =
ui.add_sized(ui.available_size(), TextEdit::singleline(&mut path_edit));
}
None => {
ui.colored_label(ui.style().visuals.error_fg_color, "Invalid path");
}
None => {
ui.colored_label(ui.style().visuals.error_fg_color, "Invalid path");
}
});
}
let response = ui.button("⟲").on_hover_text("Refresh");
if response.clicked() {
self.refresh();
}
ui.separator();
ui.add_sized([250.0, 20.0], TextEdit::singleline(&mut self.filter).hint_text("Filter entries"));
let response = ui.button("🗙").on_hover_text("Reset filter");
if response.clicked() {
self.filter.clear();
}

});
ui.add_space(ui.spacing().item_spacing.y);

Expand Down Expand Up @@ -144,7 +153,27 @@ impl FileView {
})
.body(|mut body| {
let first = 0;
let f = self.files.clone();
let filter = self.filter.to_lowercase();
let f = self
.files
.iter()
.filter(|p| {
if filter.is_empty() {
return true;
}
if let Some(sauce) = &p.sauce {
if sauce.title.to_string().to_lowercase().contains(&filter)
|| sauce.group.to_string().to_lowercase().contains(&filter)
|| sauce.author.to_string().to_lowercase().contains(&filter)
{
return true;
}
}
p.path.to_string_lossy().to_lowercase().contains(&filter)
})
.cloned()
.collect::<Vec<_>>();

for (i, entry) in f.iter().enumerate() {
body.row(row_height, |mut row| {
row.col(|ui| {
Expand Down Expand Up @@ -231,6 +260,9 @@ impl FileView {
}

fn open(&mut self, idx: usize) {
if idx >= self.files.len() {
return;
}
let entry = &self.files[idx];
if entry.path.is_dir() {
self.set_path(entry.path.clone())
Expand Down
2 changes: 1 addition & 1 deletion src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl MainWindow {
let scale = (w / self.buffer_view.lock().buf.get_buffer_width() as f32).min(2.0);
let sp = (self.start_time.elapsed().as_millis() as f32 / 6.0).round();
let opt = icy_engine_egui::TerminalOptions {
focus_lock: true,
focus_lock: false,
stick_to_bottom: false,
scale: Some(Vec2::new(scale, scale)),
font_extension: icy_engine_egui::FontExtension::Off,
Expand Down

0 comments on commit 66adf7d

Please sign in to comment.