mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-18 18:08:07 +03:00
gpui: Pass Style by value to request_layout (#11597)
A minor thing I've spotted and decided to fix on the spot. It was being cloned twice within the body of that function (one of which was redundant even without this PR); now in most cases we go down from 2 clones to 0. Release Notes: - N/A
This commit is contained in:
parent
5df1481297
commit
bd6d385817
@ -3661,7 +3661,7 @@ impl Element for EditorElement {
|
||||
let mut style = Style::default();
|
||||
style.size.width = relative(1.).into();
|
||||
style.size.height = self.style.text.line_height_in_pixels(rem_size).into();
|
||||
cx.request_layout(&style, None)
|
||||
cx.request_layout(style, None)
|
||||
}
|
||||
EditorMode::AutoHeight { max_lines } => {
|
||||
let editor_handle = cx.view().clone();
|
||||
@ -3685,7 +3685,7 @@ impl Element for EditorElement {
|
||||
let mut style = Style::default();
|
||||
style.size.width = relative(1.).into();
|
||||
style.size.height = relative(1.).into();
|
||||
cx.request_layout(&style, None)
|
||||
cx.request_layout(style, None)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -603,7 +603,7 @@ impl Element for Empty {
|
||||
_id: Option<&GlobalElementId>,
|
||||
cx: &mut WindowContext,
|
||||
) -> (LayoutId, Self::RequestLayoutState) {
|
||||
(cx.request_layout(&Style::default(), None), ())
|
||||
(cx.request_layout(Style::default(), None), ())
|
||||
}
|
||||
|
||||
fn prepaint(
|
||||
|
@ -93,7 +93,7 @@ impl Element for Anchored {
|
||||
..Style::default()
|
||||
};
|
||||
|
||||
let layout_id = cx.request_layout(&anchored_style, child_layout_ids.iter().copied());
|
||||
let layout_id = cx.request_layout(anchored_style, child_layout_ids.iter().copied());
|
||||
|
||||
(layout_id, AnchoredState { child_layout_ids })
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ impl<T: 'static> Element for Canvas<T> {
|
||||
) -> (crate::LayoutId, Self::RequestLayoutState) {
|
||||
let mut style = Style::default();
|
||||
style.refine(&self.style);
|
||||
let layout_id = cx.request_layout(&style, []);
|
||||
let layout_id = cx.request_layout(style.clone(), []);
|
||||
(layout_id, style)
|
||||
}
|
||||
|
||||
|
@ -1139,7 +1139,7 @@ impl Element for Div {
|
||||
.iter_mut()
|
||||
.map(|child| child.request_layout(cx))
|
||||
.collect::<SmallVec<_>>();
|
||||
cx.request_layout(&style, child_layout_ids.iter().copied())
|
||||
cx.request_layout(style, child_layout_ids.iter().copied())
|
||||
})
|
||||
});
|
||||
(layout_id, DivFrameState { child_layout_ids })
|
||||
|
@ -262,7 +262,7 @@ impl Element for Img {
|
||||
}
|
||||
}
|
||||
|
||||
cx.request_layout(&style, [])
|
||||
cx.request_layout(style, [])
|
||||
});
|
||||
(layout_id, ())
|
||||
}
|
||||
|
@ -766,7 +766,7 @@ impl Element for List {
|
||||
let mut style = Style::default();
|
||||
style.refine(&self.style);
|
||||
cx.with_text_style(style.text_style().cloned(), |cx| {
|
||||
cx.request_layout(&style, None)
|
||||
cx.request_layout(style, None)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ impl Element for Svg {
|
||||
) -> (LayoutId, Self::RequestLayoutState) {
|
||||
let layout_id = self
|
||||
.interactivity
|
||||
.request_layout(global_id, cx, |style, cx| cx.request_layout(&style, None));
|
||||
.request_layout(global_id, cx, |style, cx| cx.request_layout(style, None));
|
||||
(layout_id, ())
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ impl TaffyLayoutEngine {
|
||||
|
||||
pub fn request_layout(
|
||||
&mut self,
|
||||
style: &Style,
|
||||
style: Style,
|
||||
rem_size: Pixels,
|
||||
children: &[LayoutId],
|
||||
) -> LayoutId {
|
||||
@ -66,12 +66,11 @@ impl TaffyLayoutEngine {
|
||||
.new_with_children(taffy_style, unsafe { std::mem::transmute(children) })
|
||||
.expect(EXPECT_MESSAGE)
|
||||
.into();
|
||||
for child_id in children {
|
||||
self.children_to_parents.insert(*child_id, parent_id);
|
||||
}
|
||||
self.children_to_parents
|
||||
.extend(children.into_iter().map(|child_id| (*child_id, parent_id)));
|
||||
parent_id
|
||||
};
|
||||
self.styles.insert(layout_id, style.clone());
|
||||
self.styles.insert(layout_id, style);
|
||||
layout_id
|
||||
}
|
||||
|
||||
@ -82,7 +81,6 @@ impl TaffyLayoutEngine {
|
||||
measure: impl FnMut(Size<Option<Pixels>>, Size<AvailableSpace>, &mut WindowContext) -> Size<Pixels>
|
||||
+ 'static,
|
||||
) -> LayoutId {
|
||||
let style = style.clone();
|
||||
let taffy_style = style.to_taffy(rem_size);
|
||||
|
||||
let layout_id = self
|
||||
@ -91,7 +89,7 @@ impl TaffyLayoutEngine {
|
||||
.expect(EXPECT_MESSAGE)
|
||||
.into();
|
||||
self.nodes_to_measure.insert(layout_id, Box::new(measure));
|
||||
self.styles.insert(layout_id, style.clone());
|
||||
self.styles.insert(layout_id, style);
|
||||
layout_id
|
||||
}
|
||||
|
||||
|
@ -296,7 +296,7 @@ impl Element for AnyView {
|
||||
if let Some(style) = self.cached_style.as_ref() {
|
||||
let mut root_style = Style::default();
|
||||
root_style.refine(style);
|
||||
let layout_id = cx.request_layout(&root_style, None);
|
||||
let layout_id = cx.request_layout(root_style, None);
|
||||
(layout_id, None)
|
||||
} else {
|
||||
let mut element = (self.render)(self, cx);
|
||||
|
@ -2503,7 +2503,7 @@ impl<'a> WindowContext<'a> {
|
||||
/// This method should only be called as part of the request_layout or prepaint phase of element drawing.
|
||||
pub fn request_layout(
|
||||
&mut self,
|
||||
style: &Style,
|
||||
style: Style,
|
||||
children: impl IntoIterator<Item = LayoutId>,
|
||||
) -> LayoutId {
|
||||
debug_assert_eq!(
|
||||
|
@ -568,7 +568,7 @@ impl Element for MarkdownElement {
|
||||
|
||||
let mut rendered_markdown = builder.build();
|
||||
let child_layout_id = rendered_markdown.element.request_layout(cx);
|
||||
let layout_id = cx.request_layout(&Style::default(), [child_layout_id]);
|
||||
let layout_id = cx.request_layout(Style::default(), [child_layout_id]);
|
||||
(layout_id, rendered_markdown)
|
||||
}
|
||||
|
||||
|
@ -559,7 +559,7 @@ impl Element for TerminalElement {
|
||||
.request_layout(global_id, cx, |mut style, cx| {
|
||||
style.size.width = relative(1.).into();
|
||||
style.size.height = relative(1.).into();
|
||||
let layout_id = cx.request_layout(&style, None);
|
||||
let layout_id = cx.request_layout(style, None);
|
||||
|
||||
layout_id
|
||||
});
|
||||
|
@ -195,7 +195,7 @@ impl<M: ManagedView> Element for PopoverMenu<M> {
|
||||
.map(|child_element| child_element.request_layout(cx));
|
||||
|
||||
let layout_id = cx.request_layout(
|
||||
&gpui::Style::default(),
|
||||
gpui::Style::default(),
|
||||
menu_layout_id.into_iter().chain(child_layout_id),
|
||||
);
|
||||
|
||||
|
@ -142,7 +142,7 @@ impl<M: ManagedView> Element for RightClickMenu<M> {
|
||||
.map(|child_element| child_element.request_layout(cx));
|
||||
|
||||
let layout_id = cx.request_layout(
|
||||
&gpui::Style::default(),
|
||||
gpui::Style::default(),
|
||||
menu_layout_id.into_iter().chain(child_layout_id),
|
||||
);
|
||||
|
||||
|
@ -810,7 +810,7 @@ mod element {
|
||||
style.flex_basis = relative(0.).into();
|
||||
style.size.width = relative(1.).into();
|
||||
style.size.height = relative(1.).into();
|
||||
(cx.request_layout(&style, None), ())
|
||||
(cx.request_layout(style, None), ())
|
||||
}
|
||||
|
||||
fn prepaint(
|
||||
|
Loading…
Reference in New Issue
Block a user