Reorganize element-related traits
This commit is contained in:
parent
ca1d9dd0e5
commit
c23f17ee0b
42 changed files with 190 additions and 265 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
use gpui::{img, Img, RenderOnce};
|
||||
use gpui::{img, Img, IntoElement};
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Clone)]
|
||||
pub enum Shape {
|
||||
|
@ -8,13 +8,13 @@ pub enum Shape {
|
|||
RoundedRectangle,
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct Avatar {
|
||||
src: SharedString,
|
||||
shape: Shape,
|
||||
}
|
||||
|
||||
impl Component for Avatar {
|
||||
impl RenderOnce for Avatar {
|
||||
type Rendered = Img;
|
||||
|
||||
fn render(self, _: &mut WindowContext) -> Self::Rendered {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
DefiniteLength, Div, Hsla, MouseButton, MouseDownEvent, RenderOnce, StatefulInteractiveElement,
|
||||
WindowContext,
|
||||
DefiniteLength, Div, Hsla, IntoElement, MouseButton, MouseDownEvent,
|
||||
StatefulInteractiveElement, WindowContext,
|
||||
};
|
||||
|
||||
use crate::prelude::*;
|
||||
|
@ -64,7 +64,7 @@ impl ButtonVariant {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct Button {
|
||||
disabled: bool,
|
||||
click_handler: Option<Rc<dyn Fn(&MouseDownEvent, &mut WindowContext)>>,
|
||||
|
@ -76,7 +76,7 @@ pub struct Button {
|
|||
color: Option<Color>,
|
||||
}
|
||||
|
||||
impl Component for Button {
|
||||
impl RenderOnce for Button {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
@ -207,12 +207,12 @@ impl Button {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct ButtonGroup {
|
||||
buttons: Vec<Button>,
|
||||
}
|
||||
|
||||
impl Component for ButtonGroup {
|
||||
impl RenderOnce for ButtonGroup {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use gpui::{div, prelude::*, Div, Element, ElementId, RenderOnce, Styled, WindowContext};
|
||||
use gpui::{div, prelude::*, Div, Element, ElementId, IntoElement, Styled, WindowContext};
|
||||
|
||||
use theme2::ActiveTheme;
|
||||
|
||||
|
@ -11,7 +11,7 @@ pub type CheckHandler = Box<dyn Fn(&Selection, &mut WindowContext) + 'static>;
|
|||
/// Checkboxes are used for multiple choices, not for mutually exclusive choices.
|
||||
/// Each checkbox works independently from other checkboxes in the list,
|
||||
/// therefore checking an additional box does not affect any other selections.
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct Checkbox {
|
||||
id: ElementId,
|
||||
checked: Selection,
|
||||
|
@ -19,7 +19,7 @@ pub struct Checkbox {
|
|||
on_click: Option<CheckHandler>,
|
||||
}
|
||||
|
||||
impl Component for Checkbox {
|
||||
impl RenderOnce for Checkbox {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
|
|
@ -5,8 +5,8 @@ use crate::{prelude::*, v_stack, List};
|
|||
use crate::{ListItem, ListSeparator, ListSubHeader};
|
||||
use gpui::{
|
||||
overlay, px, Action, AnchorCorner, AnyElement, AppContext, Bounds, ClickEvent, DispatchPhase,
|
||||
Div, EventEmitter, FocusHandle, FocusableView, LayoutId, ManagedView, Manager, MouseButton,
|
||||
MouseDownEvent, Pixels, Point, Render, RenderOnce, View, VisualContext,
|
||||
Div, EventEmitter, FocusHandle, FocusableView, IntoElement, LayoutId, ManagedView, Manager,
|
||||
MouseButton, MouseDownEvent, Pixels, Point, Render, View, VisualContext,
|
||||
};
|
||||
|
||||
pub enum ContextMenuItem {
|
||||
|
@ -105,9 +105,9 @@ impl Render for ContextMenu {
|
|||
.child(
|
||||
List::new().children(self.items.iter().map(|item| match item {
|
||||
ContextMenuItem::Separator(separator) => {
|
||||
separator.clone().render_into_any()
|
||||
separator.clone().into_any_element()
|
||||
}
|
||||
ContextMenuItem::Header(header) => header.clone().render_into_any(),
|
||||
ContextMenuItem::Header(header) => header.clone().into_any_element(),
|
||||
ContextMenuItem::Entry(entry, callback) => {
|
||||
let callback = callback.clone();
|
||||
let dismiss = cx.listener(|_, _, cx| cx.emit(Manager::Dismiss));
|
||||
|
@ -118,7 +118,7 @@ impl Render for ContextMenu {
|
|||
callback(event, cx);
|
||||
dismiss(event, cx)
|
||||
})
|
||||
.render_into_any()
|
||||
.into_any_element()
|
||||
}
|
||||
})),
|
||||
),
|
||||
|
@ -140,8 +140,8 @@ impl<M: ManagedView> MenuHandle<M> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn child<R: RenderOnce>(mut self, f: impl FnOnce(bool) -> R + 'static) -> Self {
|
||||
self.child_builder = Some(Box::new(|b| f(b).render_once().into_any()));
|
||||
pub fn child<R: IntoElement>(mut self, f: impl FnOnce(bool) -> R + 'static) -> Self {
|
||||
self.child_builder = Some(Box::new(|b| f(b).into_element().into_any()));
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -286,14 +286,14 @@ impl<M: ManagedView> Element for MenuHandle<M> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<M: ManagedView> RenderOnce for MenuHandle<M> {
|
||||
impl<M: ManagedView> IntoElement for MenuHandle<M> {
|
||||
type Element = Self;
|
||||
|
||||
fn element_id(&self) -> Option<gpui::ElementId> {
|
||||
Some(self.id.clone())
|
||||
}
|
||||
|
||||
fn render_once(self) -> Self::Element {
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use gpui::{Div, RenderOnce};
|
||||
use gpui::{Div, IntoElement};
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -7,13 +7,13 @@ enum DividerDirection {
|
|||
Vertical,
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct Divider {
|
||||
direction: DividerDirection,
|
||||
inset: bool,
|
||||
}
|
||||
|
||||
impl Component for Divider {
|
||||
impl RenderOnce for Divider {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use gpui::{rems, svg, RenderOnce, Svg};
|
||||
use gpui::{rems, svg, IntoElement, Svg};
|
||||
use strum::EnumIter;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
@ -133,14 +133,14 @@ impl Icon {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct IconElement {
|
||||
path: SharedString,
|
||||
color: Color,
|
||||
size: IconSize,
|
||||
}
|
||||
|
||||
impl Component for IconElement {
|
||||
impl RenderOnce for IconElement {
|
||||
type Rendered = Svg;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{h_stack, prelude::*, Icon, IconElement};
|
||||
use gpui::{prelude::*, Action, AnyView, Div, MouseButton, MouseDownEvent, Stateful};
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct IconButton {
|
||||
id: ElementId,
|
||||
icon: Icon,
|
||||
|
@ -13,7 +13,7 @@ pub struct IconButton {
|
|||
on_mouse_down: Option<Box<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
||||
}
|
||||
|
||||
impl Component for IconButton {
|
||||
impl RenderOnce for IconButton {
|
||||
type Rendered = Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{prelude::*, Label};
|
||||
use gpui::{prelude::*, Div, RenderOnce, Stateful};
|
||||
use gpui::{prelude::*, Div, IntoElement, Stateful};
|
||||
|
||||
#[derive(Default, PartialEq)]
|
||||
pub enum InputVariant {
|
||||
|
@ -8,7 +8,7 @@ pub enum InputVariant {
|
|||
Filled,
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct Input {
|
||||
placeholder: SharedString,
|
||||
value: String,
|
||||
|
@ -18,7 +18,7 @@ pub struct Input {
|
|||
is_active: bool,
|
||||
}
|
||||
|
||||
impl Component for Input {
|
||||
impl RenderOnce for Input {
|
||||
type Rendered = Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::prelude::*;
|
||||
use gpui::{Action, Div, RenderOnce};
|
||||
use gpui::{Action, Div, IntoElement};
|
||||
|
||||
#[derive(RenderOnce, Clone)]
|
||||
#[derive(IntoElement, Clone)]
|
||||
pub struct KeyBinding {
|
||||
/// A keybinding consists of a key and a set of modifier keys.
|
||||
/// More then one keybinding produces a chord.
|
||||
|
@ -10,7 +10,7 @@ pub struct KeyBinding {
|
|||
key_binding: gpui::KeyBinding,
|
||||
}
|
||||
|
||||
impl Component for KeyBinding {
|
||||
impl RenderOnce for KeyBinding {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
@ -44,12 +44,12 @@ impl KeyBinding {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct Key {
|
||||
key: SharedString,
|
||||
}
|
||||
|
||||
impl Component for Key {
|
||||
impl RenderOnce for Key {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
use crate::styled_ext::StyledExt;
|
||||
use gpui::{relative, Div, Hsla, RenderOnce, StyledText, TextRun, WindowContext};
|
||||
use gpui::{relative, Div, Hsla, IntoElement, StyledText, TextRun, WindowContext};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
|
||||
pub enum LabelSize {
|
||||
|
@ -17,7 +17,7 @@ pub enum LineHeightStyle {
|
|||
UILabel,
|
||||
}
|
||||
|
||||
#[derive(Clone, RenderOnce)]
|
||||
#[derive(IntoElement, Clone)]
|
||||
pub struct Label {
|
||||
label: SharedString,
|
||||
size: LabelSize,
|
||||
|
@ -26,7 +26,7 @@ pub struct Label {
|
|||
strikethrough: bool,
|
||||
}
|
||||
|
||||
impl Component for Label {
|
||||
impl RenderOnce for Label {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
@ -85,7 +85,7 @@ impl Label {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct HighlightedLabel {
|
||||
label: SharedString,
|
||||
size: LabelSize,
|
||||
|
@ -94,7 +94,7 @@ pub struct HighlightedLabel {
|
|||
strikethrough: bool,
|
||||
}
|
||||
|
||||
impl Component for HighlightedLabel {
|
||||
impl RenderOnce for HighlightedLabel {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use gpui::{
|
||||
div, px, AnyElement, ClickEvent, Div, RenderOnce, Stateful, StatefulInteractiveElement,
|
||||
div, px, AnyElement, ClickEvent, Div, IntoElement, Stateful, StatefulInteractiveElement,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use std::rc::Rc;
|
||||
|
@ -25,7 +25,7 @@ pub enum ListHeaderMeta {
|
|||
Text(Label),
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct ListHeader {
|
||||
label: SharedString,
|
||||
left_icon: Option<Icon>,
|
||||
|
@ -34,7 +34,7 @@ pub struct ListHeader {
|
|||
toggle: Toggle,
|
||||
}
|
||||
|
||||
impl Component for ListHeader {
|
||||
impl RenderOnce for ListHeader {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
@ -179,7 +179,7 @@ impl ListHeader {
|
|||
// }
|
||||
}
|
||||
|
||||
#[derive(RenderOnce, Clone)]
|
||||
#[derive(IntoElement, Clone)]
|
||||
pub struct ListSubHeader {
|
||||
label: SharedString,
|
||||
left_icon: Option<Icon>,
|
||||
|
@ -201,7 +201,7 @@ impl ListSubHeader {
|
|||
}
|
||||
}
|
||||
|
||||
impl Component for ListSubHeader {
|
||||
impl RenderOnce for ListSubHeader {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
@ -238,7 +238,7 @@ pub enum ListEntrySize {
|
|||
Medium,
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct ListItem {
|
||||
id: ElementId,
|
||||
disabled: bool,
|
||||
|
@ -328,7 +328,7 @@ impl ListItem {
|
|||
}
|
||||
}
|
||||
|
||||
impl Component for ListItem {
|
||||
impl RenderOnce for ListItem {
|
||||
type Rendered = Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
@ -399,7 +399,7 @@ impl Component for ListItem {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce, Clone)]
|
||||
#[derive(IntoElement, Clone)]
|
||||
pub struct ListSeparator;
|
||||
|
||||
impl ListSeparator {
|
||||
|
@ -408,7 +408,7 @@ impl ListSeparator {
|
|||
}
|
||||
}
|
||||
|
||||
impl Component for ListSeparator {
|
||||
impl RenderOnce for ListSeparator {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
@ -416,7 +416,7 @@ impl Component for ListSeparator {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct List {
|
||||
/// Message to display when the list is empty
|
||||
/// Defaults to "No items"
|
||||
|
@ -426,7 +426,7 @@ pub struct List {
|
|||
children: SmallVec<[AnyElement; 2]>,
|
||||
}
|
||||
|
||||
impl Component for List {
|
||||
impl RenderOnce for List {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use gpui::{
|
||||
AnyElement, Component, Div, Element, ElementId, ParentElement, RenderOnce, Styled,
|
||||
AnyElement, Div, Element, ElementId, IntoElement, ParentElement, RenderOnce, Styled,
|
||||
WindowContext,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
|
@ -33,13 +33,13 @@ use crate::{v_stack, StyledExt};
|
|||
///
|
||||
/// Example: A theme select control. Displays "One Dark", clicking it opens a list of themes.
|
||||
/// When one is selected, the theme select control displays the selected theme.
|
||||
#[derive(RenderOnce)]
|
||||
#[derive(IntoElement)]
|
||||
pub struct Popover {
|
||||
children: SmallVec<[AnyElement; 2]>,
|
||||
aside: Option<AnyElement>,
|
||||
}
|
||||
|
||||
impl Component for Popover {
|
||||
impl RenderOnce for Popover {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
|
@ -73,11 +73,11 @@ impl Popover {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn aside(mut self, aside: impl RenderOnce) -> Self
|
||||
pub fn aside(mut self, aside: impl IntoElement) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.aside = Some(aside.render_once().into_any());
|
||||
self.aside = Some(aside.into_element().into_any());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use gpui::{overlay, Action, AnyView, Overlay, Render, RenderOnce, VisualContext};
|
||||
use gpui::{overlay, Action, AnyView, IntoElement, Overlay, Render, VisualContext};
|
||||
use settings2::Settings;
|
||||
use theme2::{ActiveTheme, ThemeSettings};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub use gpui::{
|
||||
div, Component, Element, ElementId, InteractiveElement, ParentElement, SharedString, Styled,
|
||||
div, Element, ElementId, InteractiveElement, ParentElement, RenderOnce, SharedString, Styled,
|
||||
ViewContext, WindowContext,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue