Rename Drawable::boxed to into_element and make containers generic

Multi-element are now generic over any drawable child, which can be converted
into an element.

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Antonio Scandurra 2023-04-21 18:36:21 +02:00 committed by Nathan Sobo
parent 4d433663bd
commit 03619dfa55
80 changed files with 1132 additions and 1434 deletions

View file

@ -96,9 +96,9 @@ impl View for ProjectDiagnosticsEditor {
.aligned()
.contained()
.with_style(theme.container)
.boxed()
.into_element()
} else {
ChildView::new(&self.editor, cx).boxed()
ChildView::new(&self.editor, cx).into_element()
}
}
@ -694,8 +694,7 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
icon.constrained()
.with_width(icon_width)
.aligned()
.contained()
.boxed(),
.contained(),
)
.with_child(
Label::new(
@ -706,22 +705,20 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
.contained()
.with_style(style.message.container)
.with_margin_left(cx.gutter_padding)
.aligned()
.boxed(),
.aligned(),
)
.with_children(diagnostic.code.clone().map(|code| {
Label::new(code, style.code.text.clone().with_font_size(font_size))
.contained()
.with_style(style.code.container)
.aligned()
.boxed()
}))
.contained()
.with_style(style.container)
.with_padding_left(cx.gutter_padding)
.with_padding_right(cx.gutter_padding)
.expanded()
.named("diagnostic header")
.into_named_element("diagnostic header")
})
}
@ -731,21 +728,22 @@ pub(crate) fn render_summary<T: View>(
theme: &theme::ProjectDiagnostics,
) -> Element<T> {
if summary.error_count == 0 && summary.warning_count == 0 {
Label::new("No problems", text_style.clone()).boxed()
Label::new("No problems", text_style.clone()).into_element()
} else {
let icon_width = theme.tab_icon_width;
let icon_spacing = theme.tab_icon_spacing;
let summary_spacing = theme.tab_summary_spacing;
Flex::row()
.with_children([
.with_child(
Svg::new("icons/circle_x_mark_12.svg")
.with_color(text_style.color)
.constrained()
.with_width(icon_width)
.aligned()
.contained()
.with_margin_right(icon_spacing)
.named("no-icon"),
.with_margin_right(icon_spacing),
)
.with_child(
Label::new(
summary.error_count.to_string(),
LabelStyle {
@ -753,8 +751,9 @@ pub(crate) fn render_summary<T: View>(
highlight_text: None,
},
)
.aligned()
.boxed(),
.aligned(),
)
.with_child(
Svg::new("icons/triangle_exclamation_12.svg")
.with_color(text_style.color)
.constrained()
@ -762,8 +761,9 @@ pub(crate) fn render_summary<T: View>(
.aligned()
.contained()
.with_margin_left(summary_spacing)
.with_margin_right(icon_spacing)
.named("warn-icon"),
.with_margin_right(icon_spacing),
)
.with_child(
Label::new(
summary.warning_count.to_string(),
LabelStyle {
@ -771,10 +771,9 @@ pub(crate) fn render_summary<T: View>(
highlight_text: None,
},
)
.aligned()
.boxed(),
])
.boxed()
.aligned(),
)
.into_element()
}
}