Refine naming of element-related types and traits
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
03619dfa55
commit
fe492eacbf
93 changed files with 661 additions and 656 deletions
|
@ -973,7 +973,7 @@ pub mod tests {
|
|||
position,
|
||||
height,
|
||||
disposition,
|
||||
render: Arc::new(|_| Empty::new().into_element()),
|
||||
render: Arc::new(|_| Empty::new().into_any()),
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
|
|
@ -4,7 +4,7 @@ use super::{
|
|||
};
|
||||
use crate::{Anchor, Editor, ExcerptId, ExcerptRange, ToPoint as _};
|
||||
use collections::{Bound, HashMap, HashSet};
|
||||
use gpui::{fonts::HighlightStyle, Element, ViewContext};
|
||||
use gpui::{fonts::HighlightStyle, AnyElement, ViewContext};
|
||||
use language::{BufferSnapshot, Chunk, Patch, Point};
|
||||
use parking_lot::Mutex;
|
||||
use std::{
|
||||
|
@ -50,7 +50,7 @@ struct BlockRow(u32);
|
|||
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
|
||||
struct WrapRow(u32);
|
||||
|
||||
pub type RenderBlock = Arc<dyn Fn(&mut BlockContext) -> Element<Editor>>;
|
||||
pub type RenderBlock = Arc<dyn Fn(&mut BlockContext) -> AnyElement<Editor>>;
|
||||
|
||||
pub struct Block {
|
||||
id: BlockId,
|
||||
|
@ -69,7 +69,7 @@ where
|
|||
pub position: P,
|
||||
pub height: u8,
|
||||
pub style: BlockStyle,
|
||||
pub render: Arc<dyn Fn(&mut BlockContext) -> Element<Editor>>,
|
||||
pub render: Arc<dyn Fn(&mut BlockContext) -> AnyElement<Editor>>,
|
||||
pub disposition: BlockDisposition,
|
||||
}
|
||||
|
||||
|
@ -947,7 +947,7 @@ impl DerefMut for BlockContext<'_, '_, '_, '_> {
|
|||
}
|
||||
|
||||
impl Block {
|
||||
pub fn render(&self, cx: &mut BlockContext) -> Element<Editor> {
|
||||
pub fn render(&self, cx: &mut BlockContext) -> AnyElement<Editor> {
|
||||
self.render.lock()(cx)
|
||||
}
|
||||
|
||||
|
@ -994,7 +994,7 @@ mod tests {
|
|||
use crate::display_map::suggestion_map::SuggestionMap;
|
||||
use crate::display_map::{fold_map::FoldMap, tab_map::TabMap, wrap_map::WrapMap};
|
||||
use crate::multi_buffer::MultiBuffer;
|
||||
use gpui::{elements::Empty, Drawable};
|
||||
use gpui::{elements::Empty, Element};
|
||||
use rand::prelude::*;
|
||||
use settings::Settings;
|
||||
use std::env;
|
||||
|
@ -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().into_named_element("block 1")),
|
||||
render: Arc::new(|_| Empty::new().into_any_named("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().into_named_element("block 2")),
|
||||
render: Arc::new(|_| Empty::new().into_any_named("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().into_named_element("block 3")),
|
||||
render: Arc::new(|_| Empty::new().into_any_named("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().into_named_element("block 1")),
|
||||
render: Arc::new(|_| Empty::new().into_any_named("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().into_named_element("block 2")),
|
||||
render: Arc::new(|_| Empty::new().into_any_named("block 2")),
|
||||
height: 1,
|
||||
},
|
||||
]);
|
||||
|
@ -1329,7 +1329,7 @@ mod tests {
|
|||
position,
|
||||
height,
|
||||
disposition,
|
||||
render: Arc::new(|_| Empty::new().into_element()),
|
||||
render: Arc::new(|_| Empty::new().into_any()),
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
|
|
@ -41,7 +41,7 @@ use gpui::{
|
|||
keymap_matcher::KeymapContext,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
serde_json::{self, json},
|
||||
AnyViewHandle, AppContext, AsyncAppContext, ClipboardItem, Drawable, Element, Entity,
|
||||
AnyElement, AnyViewHandle, AppContext, AsyncAppContext, ClipboardItem, Element, Entity,
|
||||
ModelHandle, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
|
||||
};
|
||||
use highlight_matching_bracket::refresh_matching_bracket_highlights;
|
||||
|
@ -725,7 +725,7 @@ impl ContextMenu {
|
|||
cursor_position: DisplayPoint,
|
||||
style: EditorStyle,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> (DisplayPoint, Element<Editor>) {
|
||||
) -> (DisplayPoint, AnyElement<Editor>) {
|
||||
match self {
|
||||
ContextMenu::Completions(menu) => (cursor_position, menu.render(style, cx)),
|
||||
ContextMenu::CodeActions(menu) => menu.render(cursor_position, style, cx),
|
||||
|
@ -777,7 +777,7 @@ impl CompletionsMenu {
|
|||
!self.matches.is_empty()
|
||||
}
|
||||
|
||||
fn render(&self, style: EditorStyle, cx: &mut ViewContext<Editor>) -> Element<Editor> {
|
||||
fn render(&self, style: EditorStyle, cx: &mut ViewContext<Editor>) -> AnyElement<Editor> {
|
||||
enum CompletionTag {}
|
||||
|
||||
let completions = self.completions.clone();
|
||||
|
@ -827,7 +827,7 @@ impl CompletionsMenu {
|
|||
item_ix: Some(item_ix),
|
||||
});
|
||||
})
|
||||
.into_element(),
|
||||
.into_any(),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
@ -847,7 +847,7 @@ impl CompletionsMenu {
|
|||
)
|
||||
.contained()
|
||||
.with_style(container_style)
|
||||
.into_element()
|
||||
.into_any()
|
||||
}
|
||||
|
||||
pub async fn filter(&mut self, query: Option<&str>, executor: Arc<executor::Background>) {
|
||||
|
@ -953,7 +953,7 @@ impl CodeActionsMenu {
|
|||
mut cursor_position: DisplayPoint,
|
||||
style: EditorStyle,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> (DisplayPoint, Element<Editor>) {
|
||||
) -> (DisplayPoint, AnyElement<Editor>) {
|
||||
enum ActionTag {}
|
||||
|
||||
let container_style = style.autocomplete.container;
|
||||
|
@ -988,7 +988,7 @@ impl CodeActionsMenu {
|
|||
item_ix: Some(item_ix),
|
||||
});
|
||||
})
|
||||
.into_element(),
|
||||
.into_any(),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
@ -1002,7 +1002,7 @@ impl CodeActionsMenu {
|
|||
)
|
||||
.contained()
|
||||
.with_style(container_style)
|
||||
.into_element();
|
||||
.into_any();
|
||||
|
||||
if self.deployed_from_indicator {
|
||||
*cursor_position.column_mut() = 0;
|
||||
|
@ -3129,7 +3129,7 @@ impl Editor {
|
|||
style: &EditorStyle,
|
||||
active: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<Element<Self>> {
|
||||
) -> Option<AnyElement<Self>> {
|
||||
if self.available_code_actions.is_some() {
|
||||
enum CodeActions {}
|
||||
Some(
|
||||
|
@ -3144,7 +3144,7 @@ impl Editor {
|
|||
deployed_from_indicator: true,
|
||||
});
|
||||
})
|
||||
.into_element(),
|
||||
.into_any(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
|
@ -3159,7 +3159,7 @@ impl Editor {
|
|||
line_height: f32,
|
||||
gutter_margin: f32,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Vec<Option<Element<Self>>> {
|
||||
) -> Vec<Option<AnyElement<Self>>> {
|
||||
enum FoldIndicators {}
|
||||
|
||||
let style = style.folds.clone();
|
||||
|
@ -3207,7 +3207,7 @@ impl Editor {
|
|||
});
|
||||
}
|
||||
})
|
||||
.into_element()
|
||||
.into_any()
|
||||
})
|
||||
})
|
||||
.flatten()
|
||||
|
@ -3226,7 +3226,7 @@ impl Editor {
|
|||
cursor_position: DisplayPoint,
|
||||
style: EditorStyle,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> Option<(DisplayPoint, Element<Editor>)> {
|
||||
) -> Option<(DisplayPoint, AnyElement<Editor>)> {
|
||||
self.context_menu
|
||||
.as_ref()
|
||||
.map(|menu| menu.render(cursor_position, style, cx))
|
||||
|
@ -5889,7 +5889,7 @@ impl Editor {
|
|||
ChildView::new(&editor, cx)
|
||||
.contained()
|
||||
.with_padding_left(cx.anchor_x)
|
||||
.into_element()
|
||||
.into_any()
|
||||
}
|
||||
}),
|
||||
disposition: BlockDisposition::Below,
|
||||
|
@ -7003,7 +7003,7 @@ impl Entity for Editor {
|
|||
}
|
||||
|
||||
impl View for Editor {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||
let style = self.style(cx);
|
||||
let font_changed = self.display_map.update(cx, |map, cx| {
|
||||
map.set_fold_ellipses_color(style.folds.ellipses.text_color);
|
||||
|
@ -7020,7 +7020,7 @@ impl View for Editor {
|
|||
Stack::new()
|
||||
.with_child(EditorElement::new(style.clone()))
|
||||
.with_child(ChildView::new(&self.mouse_context_menu, cx))
|
||||
.into_element()
|
||||
.into_any()
|
||||
}
|
||||
|
||||
fn ui_name() -> &'static str {
|
||||
|
@ -7496,7 +7496,7 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend
|
|||
}))
|
||||
.aligned()
|
||||
.left()
|
||||
.into_element()
|
||||
.into_any()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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().into_element()),
|
||||
render: Arc::new(|_| Empty::new().into_any()),
|
||||
}],
|
||||
cx,
|
||||
);
|
||||
|
|
|
@ -31,7 +31,7 @@ use gpui::{
|
|||
json::{self, ToJson},
|
||||
platform::{CursorStyle, Modifiers, MouseButton, MouseButtonEvent, MouseMovedEvent},
|
||||
text_layout::{self, Line, RunStyle, TextLayoutCache},
|
||||
Axis, Border, CursorRegion, Drawable, Element, EventContext, MouseRegion, Quad, SceneBuilder,
|
||||
AnyElement, Axis, Border, CursorRegion, Element, EventContext, MouseRegion, Quad, SceneBuilder,
|
||||
SizeConstraint, ViewContext, WindowContext,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
|
@ -1500,7 +1500,7 @@ impl EditorElement {
|
|||
.with_padding_left(gutter_padding)
|
||||
.with_padding_right(gutter_padding)
|
||||
.expanded()
|
||||
.into_named_element("path header block")
|
||||
.into_any_named("path header block")
|
||||
} else {
|
||||
let text_style = self.style.text.clone();
|
||||
Flex::row()
|
||||
|
@ -1510,7 +1510,7 @@ impl EditorElement {
|
|||
.with_padding_left(gutter_padding)
|
||||
.with_padding_right(gutter_padding)
|
||||
.expanded()
|
||||
.into_named_element("collapsed context")
|
||||
.into_any_named("collapsed context")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1563,7 +1563,7 @@ impl EditorElement {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drawable<Editor> for EditorElement {
|
||||
impl Element<Editor> for EditorElement {
|
||||
type LayoutState = LayoutState;
|
||||
type PaintState = ();
|
||||
|
||||
|
@ -2106,10 +2106,10 @@ pub struct LayoutState {
|
|||
scrollbar_row_range: Range<f32>,
|
||||
show_scrollbars: bool,
|
||||
max_row: u32,
|
||||
context_menu: Option<(DisplayPoint, Element<Editor>)>,
|
||||
code_actions_indicator: Option<(u32, Element<Editor>)>,
|
||||
hover_popovers: Option<(DisplayPoint, Vec<Element<Editor>>)>,
|
||||
fold_indicators: Vec<Option<Element<Editor>>>,
|
||||
context_menu: Option<(DisplayPoint, AnyElement<Editor>)>,
|
||||
code_actions_indicator: Option<(u32, AnyElement<Editor>)>,
|
||||
hover_popovers: Option<(DisplayPoint, Vec<AnyElement<Editor>>)>,
|
||||
fold_indicators: Vec<Option<AnyElement<Editor>>>,
|
||||
}
|
||||
|
||||
pub struct PositionMap {
|
||||
|
@ -2160,7 +2160,7 @@ impl PositionMap {
|
|||
|
||||
struct BlockLayout {
|
||||
row: u32,
|
||||
element: Element<Editor>,
|
||||
element: AnyElement<Editor>,
|
||||
style: BlockStyle,
|
||||
}
|
||||
|
||||
|
@ -2531,7 +2531,7 @@ mod tests {
|
|||
disposition: BlockDisposition::Above,
|
||||
height: 3,
|
||||
position: Anchor::min(),
|
||||
render: Arc::new(|_| Empty::new().into_element()),
|
||||
render: Arc::new(|_| Empty::new().into_any()),
|
||||
}],
|
||||
cx,
|
||||
);
|
||||
|
|
|
@ -4,7 +4,7 @@ use gpui::{
|
|||
elements::{Flex, MouseEventHandler, Padding, Text},
|
||||
impl_internal_actions,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
AppContext, Axis, Drawable, Element, ModelHandle, Task, ViewContext,
|
||||
AnyElement, AppContext, Axis, Element, ModelHandle, Task, ViewContext,
|
||||
};
|
||||
use language::{Bias, DiagnosticEntry, DiagnosticSeverity};
|
||||
use project::{HoverBlock, Project};
|
||||
|
@ -283,7 +283,7 @@ impl HoverState {
|
|||
style: &EditorStyle,
|
||||
visible_rows: Range<u32>,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> Option<(DisplayPoint, Vec<Element<Editor>>)> {
|
||||
) -> Option<(DisplayPoint, Vec<AnyElement<Editor>>)> {
|
||||
// If there is a diagnostic, position the popovers based on that.
|
||||
// Otherwise use the start of the hover range
|
||||
let anchor = self
|
||||
|
@ -323,7 +323,7 @@ pub struct InfoPopover {
|
|||
}
|
||||
|
||||
impl InfoPopover {
|
||||
pub fn render(&self, style: &EditorStyle, cx: &mut ViewContext<Editor>) -> Element<Editor> {
|
||||
pub fn render(&self, style: &EditorStyle, cx: &mut ViewContext<Editor>) -> AnyElement<Editor> {
|
||||
MouseEventHandler::<InfoPopover, _>::new(0, cx, |_, cx| {
|
||||
let mut flex = Flex::new(Axis::Vertical).scrollable::<HoverBlock>(1, None, cx);
|
||||
flex.extend(self.contents.iter().map(|content| {
|
||||
|
@ -344,7 +344,7 @@ impl InfoPopover {
|
|||
})
|
||||
.collect(),
|
||||
)
|
||||
.into_element()
|
||||
.into_any()
|
||||
} else {
|
||||
let mut text_style = style.hover_popover.prose.clone();
|
||||
text_style.font_size = style.text.font_size;
|
||||
|
@ -353,7 +353,7 @@ impl InfoPopover {
|
|||
.with_soft_wrap(true)
|
||||
.contained()
|
||||
.with_style(style.hover_popover.block_style)
|
||||
.into_element()
|
||||
.into_any()
|
||||
}
|
||||
}));
|
||||
flex.contained().with_style(style.hover_popover.container)
|
||||
|
@ -365,7 +365,7 @@ impl InfoPopover {
|
|||
top: HOVER_POPOVER_GAP,
|
||||
..Default::default()
|
||||
})
|
||||
.into_element()
|
||||
.into_any()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -376,7 +376,7 @@ pub struct DiagnosticPopover {
|
|||
}
|
||||
|
||||
impl DiagnosticPopover {
|
||||
pub fn render(&self, style: &EditorStyle, cx: &mut ViewContext<Editor>) -> Element<Editor> {
|
||||
pub fn render(&self, style: &EditorStyle, cx: &mut ViewContext<Editor>) -> AnyElement<Editor> {
|
||||
enum PrimaryDiagnostic {}
|
||||
|
||||
let mut text_style = style.hover_popover.prose.clone();
|
||||
|
@ -415,7 +415,7 @@ impl DiagnosticPopover {
|
|||
tooltip_style,
|
||||
cx,
|
||||
)
|
||||
.into_element()
|
||||
.into_any()
|
||||
}
|
||||
|
||||
pub fn activation_info(&self) -> (usize, Anchor) {
|
||||
|
|
|
@ -563,7 +563,7 @@ impl Item for Editor {
|
|||
detail: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
cx: &AppContext,
|
||||
) -> Element<T> {
|
||||
) -> AnyElement<T> {
|
||||
Flex::row()
|
||||
.with_child(Label::new(self.title(cx).to_string(), style.label.clone()).aligned())
|
||||
.with_children(detail.and_then(|detail| {
|
||||
|
@ -579,7 +579,7 @@ impl Item for Editor {
|
|||
.aligned(),
|
||||
)
|
||||
}))
|
||||
.into_element()
|
||||
.into_any()
|
||||
}
|
||||
|
||||
fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) {
|
||||
|
@ -1108,16 +1108,16 @@ impl View for CursorPosition {
|
|||
"CursorPosition"
|
||||
}
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||
if let Some(position) = self.position {
|
||||
let theme = &cx.global::<Settings>().theme.workspace.status_bar;
|
||||
let mut text = format!("{},{}", position.row + 1, position.column + 1);
|
||||
if self.selected_count > 0 {
|
||||
write!(text, " ({} selected)", self.selected_count).unwrap();
|
||||
}
|
||||
Label::new(text, theme.cursor_position.clone()).into_element()
|
||||
Label::new(text, theme.cursor_position.clone()).into_any()
|
||||
} else {
|
||||
Empty::new().into_element()
|
||||
Empty::new().into_any()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue