Skip to content

Commit

Permalink
Adjust copy to all (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Jan 5, 2025
1 parent 1f711d4 commit 36e1cf0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
13 changes: 12 additions & 1 deletion reffect/src/action/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,23 @@ impl<T> DynAction<T> {
self.0.is_some()
}

pub fn perform(&mut self, value: &mut T) {
pub fn apply(&mut self, value: &mut T) {
if let Some(action) = self.0.as_mut() {
action(value)
}
}

pub fn apply_to_all<'a>(&mut self, iter: impl IntoIterator<Item = &'a mut T>)
where
T: 'static,
{
if let Some(action) = self.0.as_mut() {
for item in iter.into_iter() {
action(item);
}
}
}

pub fn set(&mut self, action: impl FnMut(&mut T) + 'static) {
*self = Self::new(action);
}
Expand Down
2 changes: 1 addition & 1 deletion reffect/src/elements/icon/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ impl RenderOptions<DynAction<IconProps>> for IconProps {
render_copy_field!(action, ui, *tint);

input_percent_inverse("Zoom", zoom);
helper(ui, || ui.text("Icon zoom in percent"));
render_copy_field!(action, ui, *zoom);
helper(ui, || ui.text("Icon zoom in percent"));

slider_percent_capped(ui, "Round", round, 50.0);
render_copy_field!(action, ui, *round);
Expand Down
12 changes: 6 additions & 6 deletions reffect/src/elements/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ impl RenderOptions for IconList {
});

action.perform(&mut self.icons, self.size, &ctx.edit);
for icon in &mut self.icons {
copy_action.perform(icon);
}
copy_action.apply_to_all(&mut self.icons);
}

fn render_tabs(&mut self, ui: &Ui, ctx: &Context) {
Expand All @@ -205,9 +203,11 @@ impl RenderOptions for IconList {
}
}

for list_icon in &mut self.icons {
action.perform(&mut list_icon.icon.props);
}
action.apply_to_all(
self.icons
.iter_mut()
.map(|list_icon| &mut list_icon.icon.props),
);
}
}
}
Expand Down

0 comments on commit 36e1cf0

Please sign in to comment.