Skip to content

Commit

Permalink
re #25. Add process function on ViewTuple.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Jun 29, 2022
1 parent defa09b commit 1744188
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/views/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ impl<VT: ViewTuple + 'static> View for Stack<VT> {
}

fn process(&self, event: &Event, id: ViewId, cx: &mut Context, vger: &mut Vger) {
let mut c = 0;
self.children.foreach_view(&mut |child| {
let child_id = id.child(&c);
let offset = cx.layout.entry(child_id).or_default().offset;
(*child).process(&event.offset(-offset), child_id, cx, vger);
c += 1;
})
self.children.process(event, id, cx, vger);
}

fn draw(&self, id: ViewId, cx: &mut Context, vger: &mut Vger) {
Expand Down
9 changes: 9 additions & 0 deletions src/viewtuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub trait ViewTuple {
false
} // satisfy clippy

fn process(&self, event: &Event, id: ViewId, cx: &mut Context, vger: &mut Vger);
fn draw(&self, id: ViewId, cx: &mut Context, vger: &mut Vger);
}

Expand All @@ -22,6 +23,14 @@ macro_rules! impl_view_tuple {
$n
}

fn process(&self, event: &Event, id: ViewId, cx: &mut Context, vger: &mut Vger) {
$({
let child_id = id.child(&$s);
let offset = cx.layout.entry(child_id).or_default().offset;
self.$s.process(&event.offset(-offset), child_id, cx, vger);
})*
}

fn draw(&self, id: ViewId, cx: &mut Context, vger: &mut Vger) {
$({
let child_id = id.child(&$s);
Expand Down

0 comments on commit 1744188

Please sign in to comment.