Clean compile with redesigned element traits

This commit is contained in:
Nathan Sobo 2023-11-18 21:51:47 -07:00
parent 0673606de8
commit 33cd6f520a
35 changed files with 278 additions and 216 deletions

View file

@ -490,6 +490,7 @@ impl EditorElement {
for (ix, fold_indicator) in layout.fold_indicators.drain(..).enumerate() {
if let Some(mut fold_indicator) = fold_indicator {
let mut fold_indicator = fold_indicator.render_into_any();
let available_space = size(
AvailableSpace::MinContent,
AvailableSpace::Definite(line_height * 0.55),
@ -509,20 +510,21 @@ impl EditorElement {
}
}
if let Some(mut indicator) = layout.code_actions_indicator.take() {
if let Some(indicator) = layout.code_actions_indicator.take() {
let mut button = indicator.button.render_into_any();
let available_space = size(
AvailableSpace::MinContent,
AvailableSpace::Definite(line_height),
);
let indicator_size = indicator.element.measure(available_space, editor, cx);
let indicator_size = button.measure(available_space, editor, cx);
let mut x = Pixels::ZERO;
let mut y = indicator.row as f32 * line_height - scroll_top;
// Center indicator.
x += ((layout.gutter_padding + layout.gutter_margin) - indicator_size.width) / 2.;
y += (line_height - indicator_size.height) / 2.;
indicator
.element
.draw(bounds.origin + point(x, y), available_space, editor, cx);
button.draw(bounds.origin + point(x, y), available_space, editor, cx);
}
}
@ -1810,7 +1812,7 @@ impl EditorElement {
.render_code_actions_indicator(&style, active, cx)
.map(|element| CodeActionsIndicator {
row: newest_selection_head.row(),
element,
button: element,
});
}
}
@ -2041,14 +2043,19 @@ impl EditorElement {
// Can't use .and_then() because `.file_name()` and `.parent()` return references :(
if let Some(path) = path {
filename = path.file_name().map(|f| f.to_string_lossy().to_string());
parent_path =
path.parent().map(|p| p.to_string_lossy().to_string() + "/");
parent_path = path
.parent()
.map(|p| SharedString::from(p.to_string_lossy().to_string() + "/"));
}
h_stack()
.size_full()
.bg(gpui::red())
.child(filename.unwrap_or_else(|| "untitled".to_string()))
.child(
filename
.map(SharedString::from)
.unwrap_or_else(|| "untitled".into()),
)
.children(parent_path)
.children(jump_icon) // .p_x(gutter_padding)
} else {
@ -2059,7 +2066,7 @@ impl EditorElement {
.child("")
.children(jump_icon) // .p_x(gutter_padding)
};
element.render()
element.into_any()
}
};
@ -2391,10 +2398,6 @@ enum Invisible {
impl Element<Editor> for EditorElement {
type State = ();
fn element_id(&self) -> Option<gpui::ElementId> {
Some(self.editor_id.into())
}
fn layout(
&mut self,
editor: &mut Editor,
@ -2469,6 +2472,10 @@ impl Element<Editor> for EditorElement {
impl RenderOnce<Editor> for EditorElement {
type Element = Self;
fn element_id(&self) -> Option<gpui::ElementId> {
Some(self.editor_id.into())
}
fn render_once(self) -> Self::Element {
self
}
@ -3098,14 +3105,14 @@ pub struct LayoutState {
context_menu: Option<(DisplayPoint, AnyElement<Editor>)>,
code_actions_indicator: Option<CodeActionsIndicator>,
// hover_popovers: Option<(DisplayPoint, Vec<AnyElement<Editor>>)>,
fold_indicators: Vec<Option<AnyElement<Editor>>>,
fold_indicators: Vec<Option<IconButton<Editor>>>,
tab_invisible: ShapedLine,
space_invisible: ShapedLine,
}
struct CodeActionsIndicator {
row: u32,
element: AnyElement<Editor>,
button: IconButton<Editor>,
}
struct PositionMap {