Skip to content

Commit

Permalink
experiment with file name filter ux
Browse files Browse the repository at this point in the history
  • Loading branch information
B0ney committed Nov 7, 2023
1 parent 6190bc5 commit 947557b
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 39 deletions.
11 changes: 11 additions & 0 deletions data/src/config/filters/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ pub struct Name {
pub extensions: Vec<String>,
}

impl Default for Name {
fn default() -> Self {
Self {
contains: (0..30).into_iter().map(|f| format!("test{f}")).collect(),
starts_with: ["test", "test2", "test3"].into_iter().map(String::from).collect(),
ends_with: (0..50).into_iter().map(|f| f.to_string()).collect(),
extensions: (0..10).into_iter().map(|f| f.to_string()).collect(),
}
}
}

impl Filter for Name {
fn matches(&self, path: &Path) -> bool {
let filename = filename(path);
Expand Down
5 changes: 3 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl Application for XMODITS {
return sample_ripping::update(&mut self.ripping_cfg, msg).map(Message::RippingCfg)
}
Message::NamingCfg(msg) => sample_naming::update(&mut self.naming_cfg, msg),
Message::CustomFilter(msg) => custom_filters::update(&mut self.custom_filters, msg),
Message::CustomFilter(msg) => self.custom_filters.update(msg),
Message::SetTheme => todo!(),
Message::Open(link) => {
if let Err(err) = open::that_detached(link) {
Expand Down Expand Up @@ -472,7 +472,8 @@ impl Application for XMODITS {
.into()
}
View::Filters => column![
custom_filters::view(&self.custom_filters).map(Message::CustomFilter),
self.custom_filters.view_file_size().map(Message::CustomFilter),
self.custom_filters.view_file_name().map(Message::CustomFilter),
bottom_left_buttons,
]
.spacing(8)
Expand Down
56 changes: 21 additions & 35 deletions src/screen/config/custom_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ mod file_name;
mod file_size;
mod regex;

use std::path::Path;
use data::config::filters::{Filter, Name, Size};
use std::path::Path;

use iced::widget::{column, horizontal_rule, row};

Expand All @@ -31,45 +31,31 @@ impl Filters {
}
}

#[derive(Default, Debug)]
pub struct CustomFilters {
filesize: Size,
}

#[derive(Debug, Clone, Copy)]
pub enum Message {
A,
FileSize(file_size::Message)
FileSize(file_size::Message),
FileName(file_name::Message),
}

pub fn view<'a>(filters: &CustomFilters) -> Element<'a, Message> {
// let title = text_icon("Filters", icon::filter());

// let menu = |title: &'a str| {
// row![title, horizontal_rule(1)]
// .spacing(8)
// .align_items(iced::Alignment::Center)
// };

// let settings = column![
// // file_size::view().map(|_| Message::A),
// // horizontal_rule(1),
// menu("Extension"),
// // horizontal_rule(1),
// menu("Name"),
// // horizontal_rule(1),
// menu("Date"),
// ]
// .spacing(8);

// control_filled(title, settings).into()

file_size::view(&filters.filesize).map(Message::FileSize).into()
#[derive(Default, Debug)]
pub struct CustomFilters {
filesize: Size,
filename: Name,
}

pub fn update(filter: &mut CustomFilters, msg: Message) {
match msg {
Message::A => todo!(),
Message::FileSize(filesize) => file_size::update(&mut filter.filesize, filesize),
impl CustomFilters {
pub fn update(&mut self, msg: Message) {
match msg {
Message::FileSize(filesize) => file_size::update(&mut self.filesize, filesize),
Message::FileName(filename) => file_name::update(&mut self.filename, filename),
}
}
pub fn view_file_size(&self) -> Element<Message> {
file_size::view(&self.filesize).map(Message::FileSize)
}

pub fn view_file_name(&self) -> Element<Message> {
file_name::view(&self.filename).map(Message::FileName)
}
}

84 changes: 84 additions & 0 deletions src/screen/config/custom_filters/file_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use crate::theme::TextInputStyle;
use crate::widget::helpers::{text_elem, fill_container, control_filled};
use crate::widget::Element;
use crate::{theme, widget::helpers::control};
use data::config::filters::Name;
use iced::widget::{
button, checkbox, column, container, horizontal_rule, pick_list, row, scrollable, slider, text,
text_input, Space,
};
use iced::{Alignment, Length};

#[derive(Debug, Clone, Copy)]
pub enum Message {
A,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Condition {
Contains,
StartsWith,
EndsWith,
}
impl Condition {
const ALL: &[Self] = &[Self::Contains, Self::StartsWith, Self::EndsWith];
}
impl std::fmt::Display for Condition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Condition::Contains => "Contains",
Condition::StartsWith => "Starts With",
Condition::EndsWith => "Ends with",
}
)
}
}

pub fn update(filter: &mut Name, msg: Message) {}

pub fn view<'a>(filter: &'a Name) -> Element<'a, Message> {
let settings = column![
row![
column![
"Value",
text_input("Add Filter", "")
.style(theme::TextInputStyle::Inverted)
.width(Length::Fill),
]
.width(Length::Fill)
.spacing(8),
column![
"Condition",
pick_list(Condition::ALL, Some(Condition::Contains), |_| Message::A)
]
.width(Length::Fill)
.spacing(8),
]
.width(Length::Fill)
.spacing(5),
row![button("Add"), button("Add AND"), button("Add OR")]
.align_items(Alignment::Center)
.spacing(5),
fill_container(scrollable(
container(filter.contains.iter().fold(column![].spacing(4), |f, y| {
f.push(row![
checkbox("", false, |_| Message::A),
button(y.as_ref()).style(theme::Button::HyperlinkInverted)
])
})).width(Length::Fill)

))
.padding(8)
.style(theme::Container::Black),
row![
button("Remove Selected"),
Space::with_width(Length::Fill),
button("Clear")
],
]
.spacing(8);
control_filled("File Name", settings).into()
}
2 changes: 1 addition & 1 deletion src/screen/config/custom_filters/file_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum Message {
Ignore,
}

pub fn view<'a>(filter: &Size) -> Element<'a, Message> {
pub fn view(filter: &Size) -> Element<Message> {
let settings = column![
row![
"Min:",
Expand Down
6 changes: 5 additions & 1 deletion src/widget/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,9 @@ pub fn spaced_row<'a, Message: 'a>(row: Row<'a, Message>) -> Row<'a, Message> {
}

pub fn text_icon<'a, Message: 'a>(text: &'a str, icon: Text<'a>) -> Row<'a, Message> {
row![text, icon].align_items(Alignment::Center).spacing(5)
text_elem(text, icon)
}

pub fn text_elem<'a, Message: 'a>(text: &'a str, elem: impl Into<Element<'a, Message>>) -> Row<'a, Message> {
row![text].push(elem).align_items(Alignment::Center).spacing(5)
}

0 comments on commit 947557b

Please sign in to comment.