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

@ -973,7 +973,7 @@ pub mod tests {
position,
height,
disposition,
render: Arc::new(|_| Empty::new().boxed()),
render: Arc::new(|_| Empty::new().into_element()),
}
})
.collect::<Vec<_>>();

View file

@ -1045,21 +1045,21 @@ mod tests {
position: buffer_snapshot.anchor_after(Point::new(1, 0)),
height: 1,
disposition: BlockDisposition::Above,
render: Arc::new(|_| Empty::new().named("block 1")),
render: Arc::new(|_| Empty::new().into_named_element("block 1")),
},
BlockProperties {
style: BlockStyle::Fixed,
position: buffer_snapshot.anchor_after(Point::new(1, 2)),
height: 2,
disposition: BlockDisposition::Above,
render: Arc::new(|_| Empty::new().named("block 2")),
render: Arc::new(|_| Empty::new().into_named_element("block 2")),
},
BlockProperties {
style: BlockStyle::Fixed,
position: buffer_snapshot.anchor_after(Point::new(3, 3)),
height: 3,
disposition: BlockDisposition::Below,
render: Arc::new(|_| Empty::new().named("block 3")),
render: Arc::new(|_| Empty::new().into_named_element("block 3")),
},
]);
@ -1219,14 +1219,14 @@ mod tests {
style: BlockStyle::Fixed,
position: buffer_snapshot.anchor_after(Point::new(1, 12)),
disposition: BlockDisposition::Above,
render: Arc::new(|_| Empty::new().named("block 1")),
render: Arc::new(|_| Empty::new().into_named_element("block 1")),
height: 1,
},
BlockProperties {
style: BlockStyle::Fixed,
position: buffer_snapshot.anchor_after(Point::new(1, 1)),
disposition: BlockDisposition::Below,
render: Arc::new(|_| Empty::new().named("block 2")),
render: Arc::new(|_| Empty::new().into_named_element("block 2")),
height: 1,
},
]);
@ -1329,7 +1329,7 @@ mod tests {
position,
height,
disposition,
render: Arc::new(|_| Empty::new().boxed()),
render: Arc::new(|_| Empty::new().into_element()),
}
})
.collect::<Vec<_>>();

View file

@ -819,7 +819,6 @@ impl CompletionsMenu {
))
.contained()
.with_style(item_style)
.boxed()
},
)
.with_cursor_style(CursorStyle::PointingHand)
@ -828,7 +827,7 @@ impl CompletionsMenu {
item_ix: Some(item_ix),
});
})
.boxed(),
.into_element(),
);
}
},
@ -848,7 +847,7 @@ impl CompletionsMenu {
)
.contained()
.with_style(container_style)
.boxed()
.into_element()
}
pub async fn filter(&mut self, query: Option<&str>, executor: Arc<executor::Background>) {
@ -982,7 +981,6 @@ impl CodeActionsMenu {
.with_soft_wrap(false)
.contained()
.with_style(item_style)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_down(MouseButton::Left, move |_, _, cx| {
@ -990,7 +988,7 @@ impl CodeActionsMenu {
item_ix: Some(item_ix),
});
})
.boxed(),
.into_element(),
);
}
},
@ -1004,7 +1002,7 @@ impl CodeActionsMenu {
)
.contained()
.with_style(container_style)
.boxed();
.into_element();
if self.deployed_from_indicator {
*cursor_position.column_mut() = 0;
@ -3138,7 +3136,6 @@ impl Editor {
MouseEventHandler::<CodeActions, _>::new(0, cx, |state, _| {
Svg::new("icons/bolt_8.svg")
.with_color(style.code_actions.indicator.style_for(state, active).color)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.with_padding(Padding::uniform(3.))
@ -3147,7 +3144,7 @@ impl Editor {
deployed_from_indicator: true,
});
})
.boxed(),
.into_element(),
)
} else {
None
@ -3177,7 +3174,7 @@ impl Editor {
MouseEventHandler::<FoldIndicators, _>::new(
ix as usize,
cx,
|mouse_state, _| -> Element<Editor> {
|mouse_state, _| {
Svg::new(match fold_status {
FoldStatus::Folded => style.folded_icon.clone(),
FoldStatus::Foldable => style.foldable_icon.clone(),
@ -3198,7 +3195,6 @@ impl Editor {
.with_height(line_height)
.with_width(gutter_margin)
.aligned()
.boxed()
},
)
.with_cursor_style(CursorStyle::PointingHand)
@ -3211,7 +3207,7 @@ impl Editor {
});
}
})
.boxed()
.into_element()
})
})
.flatten()
@ -5893,7 +5889,7 @@ impl Editor {
ChildView::new(&editor, cx)
.contained()
.with_padding_left(cx.anchor_x)
.boxed()
.into_element()
}
}),
disposition: BlockDisposition::Below,
@ -7022,9 +7018,9 @@ impl View for Editor {
}
Stack::new()
.with_child(EditorElement::new(style.clone()).boxed())
.with_child(ChildView::new(&self.mouse_context_menu, cx).boxed())
.boxed()
.with_child(EditorElement::new(style.clone()))
.with_child(ChildView::new(&self.mouse_context_menu, cx))
.into_element()
}
fn ui_name() -> &'static str {
@ -7497,11 +7493,10 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend
.with_highlights(highlights.clone())
.contained()
.with_margin_left(cx.anchor_x)
.boxed()
}))
.aligned()
.left()
.boxed()
.into_element()
})
}

View file

@ -2299,7 +2299,7 @@ fn test_move_line_up_down_with_blocks(cx: &mut TestAppContext) {
position: snapshot.anchor_after(Point::new(2, 0)),
disposition: BlockDisposition::Below,
height: 1,
render: Arc::new(|_| Empty::new().boxed()),
render: Arc::new(|_| Empty::new().into_element()),
}],
cx,
);
@ -4411,7 +4411,7 @@ async fn test_strip_whitespace_and_format_via_lsp(cx: &mut gpui::TestAppContext)
cx.set_state(
&[
"one ", //
"twoˇ", //
"twoˇ", //
"three ", //
"four", //
]
@ -4486,7 +4486,7 @@ async fn test_strip_whitespace_and_format_via_lsp(cx: &mut gpui::TestAppContext)
&[
"one", //
"", //
"twoˇ", //
"twoˇ", //
"", //
"three", //
"four", //
@ -4501,7 +4501,7 @@ async fn test_strip_whitespace_and_format_via_lsp(cx: &mut gpui::TestAppContext)
cx.assert_editor_state(
&[
"one ", //
"twoˇ", //
"twoˇ", //
"three ", //
"four", //
]

View file

@ -1447,7 +1447,6 @@ impl EditorElement {
.constrained()
.with_width(style.button_width)
.with_height(style.button_width)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
@ -1462,7 +1461,6 @@ impl EditorElement {
)
.aligned()
.flex_float()
.boxed()
});
if *starts_new_buffer {
@ -1488,15 +1486,13 @@ impl EditorElement {
)
.contained()
.with_style(style.filename.container)
.aligned()
.boxed(),
.aligned(),
)
.with_children(parent_path.map(|path| {
Label::new(path, style.path.text.clone().with_font_size(font_size))
.contained()
.with_style(style.path.container)
.aligned()
.boxed()
}))
.with_children(jump_icon)
.contained()
@ -1504,17 +1500,17 @@ impl EditorElement {
.with_padding_left(gutter_padding)
.with_padding_right(gutter_padding)
.expanded()
.named("path header block")
.into_named_element("path header block")
} else {
let text_style = self.style.text.clone();
Flex::row()
.with_child(Label::new("", text_style).boxed())
.with_child(Label::new("", text_style))
.with_children(jump_icon)
.contained()
.with_padding_left(gutter_padding)
.with_padding_right(gutter_padding)
.expanded()
.named("collapsed context")
.into_named_element("collapsed context")
}
}
};
@ -2535,7 +2531,7 @@ mod tests {
disposition: BlockDisposition::Above,
height: 3,
position: Anchor::min(),
render: Arc::new(|_| Empty::new().boxed()),
render: Arc::new(|_| Empty::new().into_element()),
}],
cx,
);

View file

@ -344,7 +344,7 @@ impl InfoPopover {
})
.collect(),
)
.boxed()
.into_element()
} else {
let mut text_style = style.hover_popover.prose.clone();
text_style.font_size = style.text.font_size;
@ -353,12 +353,10 @@ impl InfoPopover {
.with_soft_wrap(true)
.contained()
.with_style(style.hover_popover.block_style)
.boxed()
.into_element()
}
}));
flex.contained()
.with_style(style.hover_popover.container)
.boxed()
flex.contained().with_style(style.hover_popover.container)
})
.on_move(|_, _, _| {}) // Consume move events so they don't reach regions underneath.
.with_cursor_style(CursorStyle::Arrow)
@ -367,7 +365,7 @@ impl InfoPopover {
top: HOVER_POPOVER_GAP,
..Default::default()
})
.boxed()
.into_element()
}
}
@ -399,7 +397,6 @@ impl DiagnosticPopover {
.with_soft_wrap(true)
.contained()
.with_style(container_style)
.boxed()
})
.with_padding(Padding {
top: HOVER_POPOVER_GAP,
@ -418,7 +415,7 @@ impl DiagnosticPopover {
tooltip_style,
cx,
)
.boxed()
.into_element()
}
pub fn activation_info(&self) -> (usize, Anchor) {

View file

@ -565,11 +565,7 @@ impl Item for Editor {
cx: &AppContext,
) -> Element<T> {
Flex::row()
.with_child(
Label::new(self.title(cx).to_string(), style.label.clone())
.aligned()
.boxed(),
)
.with_child(Label::new(self.title(cx).to_string(), style.label.clone()).aligned())
.with_children(detail.and_then(|detail| {
let path = path_for_buffer(&self.buffer, detail, false, cx)?;
let description = path.to_string_lossy();
@ -580,11 +576,10 @@ impl Item for Editor {
)
.contained()
.with_style(style.description.container)
.aligned()
.boxed(),
.aligned(),
)
}))
.boxed()
.into_element()
}
fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) {
@ -1120,9 +1115,9 @@ impl View for CursorPosition {
if self.selected_count > 0 {
write!(text, " ({} selected)", self.selected_count).unwrap();
}
Label::new(text, theme.cursor_position.clone()).boxed()
Label::new(text, theme.cursor_position.clone()).into_element()
} else {
Empty::new().boxed()
Empty::new().into_element()
}
}
}