Skip to content

Commit

Permalink
#51. Avoid cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Aug 19, 2023
1 parent f114631 commit 202a75c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
15 changes: 15 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,21 @@ impl Context {
}
}

pub(crate) fn set_layout_offset(&mut self, path: &IdPath, offset: LocalOffset) {
match self.layout.get_mut(path) {
Some(boxref) => boxref.offset = offset,
None => {
self.layout.insert(
path.clone(),
LayoutBox {
rect: LocalRect::default(),
offset: offset,
},
);
}
}
}

pub(crate) fn set_dirty(&mut self) {
if self.enable_dirty {
self.dirty = true
Expand Down
15 changes: 2 additions & 13 deletions src/views/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,7 @@ where
VAlignment::Middle,
);

match args.cx.layout.get_mut(path) {
Some(boxref) => boxref.offset = child_offset,
None => {
args.cx.layout.insert(
path.clone(),
LayoutBox {
rect: LocalRect::default(),
offset: child_offset,
},
);
}
}
args.cx.set_layout_offset(path, child_offset);

path.pop();

Expand Down Expand Up @@ -149,7 +138,7 @@ where
HAlignment::Center,
);

args.cx.layout.entry(path.clone()).or_default().offset = child_offset;
args.cx.set_layout_offset(path, child_offset);
path.pop();

y -= child_size.height;
Expand Down
4 changes: 2 additions & 2 deletions src/views/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<VT: ViewTuple + 'static, D: StackDirection + 'static> View for Stack<VT, D>
);

path.push(c);
args.cx.layout.entry(path.clone()).or_default().offset = child_offset;
args.cx.set_layout_offset(path, child_offset);
path.pop();
}

Expand Down Expand Up @@ -187,7 +187,7 @@ impl<VT: ViewTuple + 'static, D: StackDirection + 'static> View for Stack<VT, D>
);

path.push(c);
args.cx.layout.entry(path.clone()).or_default().offset = child_offset;
args.cx.set_layout_offset(path, child_offset);
path.pop();
}

Expand Down

0 comments on commit 202a75c

Please sign in to comment.