Skip to content

Commit

Permalink
Add filter to list icons (closes #39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Sep 4, 2024
1 parent 29d44cb commit 946115e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
9 changes: 9 additions & 0 deletions src/elements/element/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ impl RenderOptions for ElementType {
}
}

impl ElementType {
pub fn render_filters(&mut self, ui: &Ui, state: &mut EditState) {
match self {
Self::IconList(list) => list.render_filters(ui, state),
Self::Group(_) | Self::Icon(_) | Self::Text(_) | Self::Bar(_) => {}
}
}
}

impl RenderDebug for ElementType {
fn render_debug(&mut self, ui: &Ui) {
match self {
Expand Down
1 change: 1 addition & 0 deletions src/elements/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl Element {

if let Some(_token) = ui.tab_item("Filter") {
self.filter.render_options(ui, state);
self.kind.render_filters(ui, state);
}

if let Some(_token) = ui.tab_item("Animation") {
Expand Down
3 changes: 2 additions & 1 deletion src/elements/list/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ impl IconAction {
Self::Paste(index) => {
if let Some(Element {
common,
filter,
kind: ElementType::Icon(element),
..
}) = state.take_clipboard()
{
children.insert(index, ListIcon::from_element(common, element));
children.insert(index, ListIcon::from_element(common, element, filter));
} else {
panic!("icon action paste without icon element");
}
Expand Down
12 changes: 8 additions & 4 deletions src/elements/list/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use crate::{
elements::{Common, Element, ElementType, Icon, IconElement, RenderState},
render::{RenderDebug, RenderOptions},
render_util::Rect,
traits::{RenderDebug, RenderOptions},
trigger::ProgressTrigger,
trigger::{FilterTrigger, ProgressTrigger, Trigger},
};
use nexus::imgui::Ui;
use serde::{Deserialize, Serialize};
Expand All @@ -20,6 +19,8 @@ pub struct ListIcon {
#[serde(alias = "progress_active")]
pub trigger: ProgressTrigger,

pub filter: FilterTrigger,

#[serde(flatten)]
pub icon: Icon,
}
Expand All @@ -28,7 +29,7 @@ impl ListIcon {
pub fn is_visible(&mut self, ctx: &Context, state: &RenderState) -> bool {
let parent = state.common.trigger.active();
self.trigger.update(ctx, state.is_edit(ctx), parent);
self.enabled && self.trigger.active().is_some()
self.enabled && self.trigger.active().is_some() && self.filter.is_active(ctx)
}

pub fn render(&mut self, ui: &Ui, ctx: &Context, state: &RenderState, size: [f32; 2]) {
Expand All @@ -52,15 +53,17 @@ impl ListIcon {
icon: self.icon,
size,
}),
filter: self.filter,
..Element::default()
}
}

pub fn from_element(common: Common, element: IconElement) -> Self {
pub fn from_element(common: Common, element: IconElement, filter: FilterTrigger) -> Self {
Self {
enabled: common.enabled,
name: common.name,
trigger: common.trigger,
filter,
icon: element.icon,
}
}
Expand Down Expand Up @@ -93,6 +96,7 @@ impl Default for ListIcon {
enabled: true,
name: "Unnamed".into(),
trigger: ProgressTrigger::effect(),
filter: FilterTrigger::default(),
icon: Icon::default(),
}
}
Expand Down
22 changes: 12 additions & 10 deletions src/elements/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,19 @@ impl RenderOptions for IconList {
}
}
}
}
}

if let Some(_token) = ui.tab_item("Filter") {
ui.spacing();
for (i, icon) in self.icons.iter_mut().enumerate() {
let _id = ui.push_id(i as i32);
let open = CollapsingHeader::new(format!("{}###icon{i}", icon.name))
.flags(TreeNodeFlags::ALLOW_ITEM_OVERLAP)
.begin(ui);
if open {
icon.filter.render_options(ui, state);
}
impl IconList {
pub fn render_filters(&mut self, ui: &Ui, state: &mut EditState) {
ui.spacing();
for (i, icon) in self.icons.iter_mut().enumerate() {
let _id = ui.push_id(i as i32);
let open = CollapsingHeader::new(format!("{}###icon{i}", icon.name))
.flags(TreeNodeFlags::ALLOW_ITEM_OVERLAP)
.begin(ui);
if open {
icon.filter.render_options(ui, state);
}
}
}
Expand Down

0 comments on commit 946115e

Please sign in to comment.