Checkpoint
This commit is contained in:
parent
14fc386dc8
commit
c3b1264c05
14 changed files with 38 additions and 35 deletions
|
@ -1,4 +1,4 @@
|
||||||
use crate::{layout_context::LayoutContext, paint_context::PaintContext};
|
use crate::{paint_context::PaintContext, ViewContext};
|
||||||
use gpui::{geometry::rect::RectF, LayoutEngine, LayoutId};
|
use gpui::{geometry::rect::RectF, LayoutEngine, LayoutId};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ impl<V: 'static> gpui::Element<V> for AdapterElement<V> {
|
||||||
) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
|
) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
|
||||||
cx.push_layout_engine(LayoutEngine::new());
|
cx.push_layout_engine(LayoutEngine::new());
|
||||||
|
|
||||||
let mut cx = LayoutContext::new(cx);
|
let mut cx = ViewContext::new(cx);
|
||||||
let layout_id = self.0.layout(view, &mut cx).log_err();
|
let layout_id = self.0.layout(view, &mut cx).log_err();
|
||||||
if let Some(layout_id) = layout_id {
|
if let Some(layout_id) = layout_id {
|
||||||
cx.layout_engine()
|
cx.layout_engine()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
pub use crate::layout_context::LayoutContext;
|
|
||||||
pub use crate::paint_context::PaintContext;
|
pub use crate::paint_context::PaintContext;
|
||||||
|
pub use crate::ViewContext;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gpui::geometry::vector::Vector2F;
|
use gpui::geometry::vector::Vector2F;
|
||||||
pub use gpui::{Layout, LayoutId};
|
pub use gpui::{Layout, LayoutId};
|
||||||
|
@ -11,7 +11,7 @@ pub trait Element<V: 'static>: 'static + IntoElement<V> {
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
cx: &mut LayoutContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> Result<(LayoutId, Self::PaintState)>
|
) -> Result<(LayoutId, Self::PaintState)>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
|
@ -39,7 +39,7 @@ pub trait Element<V: 'static>: 'static + IntoElement<V> {
|
||||||
|
|
||||||
/// Used to make ElementState<V, E> into a trait object, so we can wrap it in AnyElement<V>.
|
/// Used to make ElementState<V, E> into a trait object, so we can wrap it in AnyElement<V>.
|
||||||
trait AnyStatefulElement<V> {
|
trait AnyStatefulElement<V> {
|
||||||
fn layout(&mut self, view: &mut V, cx: &mut LayoutContext<V>) -> Result<LayoutId>;
|
fn layout(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> Result<LayoutId>;
|
||||||
fn paint(&mut self, view: &mut V, parent_origin: Vector2F, cx: &mut PaintContext<V>);
|
fn paint(&mut self, view: &mut V, parent_origin: Vector2F, cx: &mut PaintContext<V>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ impl<V: 'static, E: Element<V>> Default for ElementPhase<V, E> {
|
||||||
|
|
||||||
/// We blanket-implement the object-safe ElementStateObject interface to make ElementStates into trait objects
|
/// We blanket-implement the object-safe ElementStateObject interface to make ElementStates into trait objects
|
||||||
impl<V, E: Element<V>> AnyStatefulElement<V> for StatefulElement<V, E> {
|
impl<V, E: Element<V>> AnyStatefulElement<V> for StatefulElement<V, E> {
|
||||||
fn layout(&mut self, view: &mut V, cx: &mut LayoutContext<V>) -> Result<LayoutId> {
|
fn layout(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> Result<LayoutId> {
|
||||||
let result;
|
let result;
|
||||||
self.phase = match self.element.layout(view, cx) {
|
self.phase = match self.element.layout(view, cx) {
|
||||||
Ok((layout_id, paint_state)) => {
|
Ok((layout_id, paint_state)) => {
|
||||||
|
@ -145,7 +145,7 @@ impl<V, E: Element<V>> AnyStatefulElement<V> for StatefulElement<V, E> {
|
||||||
pub struct AnyElement<V>(Box<dyn AnyStatefulElement<V>>);
|
pub struct AnyElement<V>(Box<dyn AnyStatefulElement<V>>);
|
||||||
|
|
||||||
impl<V> AnyElement<V> {
|
impl<V> AnyElement<V> {
|
||||||
pub fn layout(&mut self, view: &mut V, cx: &mut LayoutContext<V>) -> Result<LayoutId> {
|
pub fn layout(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> Result<LayoutId> {
|
||||||
self.0.layout(view, cx)
|
self.0.layout(view, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,9 @@ use std::{cell::Cell, rc::Rc};
|
||||||
use crate::{
|
use crate::{
|
||||||
element::{AnyElement, Element, IntoElement, Layout, ParentElement},
|
element::{AnyElement, Element, IntoElement, Layout, ParentElement},
|
||||||
hsla,
|
hsla,
|
||||||
layout_context::LayoutContext,
|
|
||||||
paint_context::PaintContext,
|
paint_context::PaintContext,
|
||||||
style::{CornerRadii, Overflow, Style, StyleHelpers, Styleable},
|
style::{CornerRadii, Overflow, Style, StyleHelpers, Styleable},
|
||||||
InteractionHandlers, Interactive,
|
InteractionHandlers, Interactive, ViewContext,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
|
@ -41,7 +40,7 @@ impl<V: 'static> Element<V> for Div<V> {
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
cx: &mut LayoutContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> Result<(LayoutId, Self::PaintState)>
|
) -> Result<(LayoutId, Self::PaintState)>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
element::{AnyElement, Element, IntoElement, Layout, ParentElement},
|
element::{AnyElement, Element, IntoElement, Layout, ParentElement},
|
||||||
interactive::{InteractionHandlers, Interactive},
|
interactive::{InteractionHandlers, Interactive},
|
||||||
layout_context::LayoutContext,
|
|
||||||
paint_context::PaintContext,
|
paint_context::PaintContext,
|
||||||
style::{Style, StyleHelpers, Styleable},
|
style::{Style, StyleHelpers, Styleable},
|
||||||
|
ViewContext,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gpui::{geometry::vector::Vector2F, platform::MouseMovedEvent, LayoutId};
|
use gpui::{geometry::vector::Vector2F, platform::MouseMovedEvent, LayoutId};
|
||||||
|
@ -45,7 +45,7 @@ impl<V: 'static, E: Element<V> + Styleable> Element<V> for Hoverable<E> {
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
cx: &mut LayoutContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> Result<(LayoutId, Self::PaintState)>
|
) -> Result<(LayoutId, Self::PaintState)>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use crate as gpui2;
|
use crate as gpui2;
|
||||||
use crate::style::{StyleHelpers, Styleable};
|
use crate::{
|
||||||
use crate::{style::Style, Element};
|
style::{Style, StyleHelpers, Styleable},
|
||||||
|
Element,
|
||||||
|
};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use gpui::geometry::vector::Vector2F;
|
use gpui::geometry::vector::Vector2F;
|
||||||
use gpui::scene;
|
use gpui::scene;
|
||||||
|
@ -35,7 +37,7 @@ impl<V: 'static> Element<V> for Img {
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: &mut V,
|
_: &mut V,
|
||||||
cx: &mut crate::LayoutContext<V>,
|
cx: &mut crate::ViewContext<V>,
|
||||||
) -> anyhow::Result<(gpui::LayoutId, Self::PaintState)>
|
) -> anyhow::Result<(gpui::LayoutId, Self::PaintState)>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
element::{AnyElement, Element, IntoElement, Layout, ParentElement},
|
element::{AnyElement, Element, IntoElement, Layout, ParentElement},
|
||||||
interactive::{InteractionHandlers, Interactive},
|
interactive::{InteractionHandlers, Interactive},
|
||||||
layout_context::LayoutContext,
|
|
||||||
paint_context::PaintContext,
|
paint_context::PaintContext,
|
||||||
style::{Style, StyleHelpers, Styleable},
|
style::{Style, StyleHelpers, Styleable},
|
||||||
|
ViewContext,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gpui::{geometry::vector::Vector2F, platform::MouseButtonEvent, LayoutId};
|
use gpui::{geometry::vector::Vector2F, platform::MouseButtonEvent, LayoutId};
|
||||||
|
@ -45,7 +45,7 @@ impl<V: 'static, E: Element<V> + Styleable> Element<V> for Pressable<E> {
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
cx: &mut LayoutContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> Result<(LayoutId, Self::PaintState)>
|
) -> Result<(LayoutId, Self::PaintState)>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
|
@ -34,7 +34,7 @@ impl<V: 'static> Element<V> for Svg {
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: &mut V,
|
_: &mut V,
|
||||||
cx: &mut crate::LayoutContext<V>,
|
cx: &mut crate::ViewContext<V>,
|
||||||
) -> anyhow::Result<(LayoutId, Self::PaintState)>
|
) -> anyhow::Result<(LayoutId, Self::PaintState)>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
element::{Element, IntoElement, Layout},
|
element::{Element, IntoElement, Layout},
|
||||||
layout_context::LayoutContext,
|
|
||||||
paint_context::PaintContext,
|
paint_context::PaintContext,
|
||||||
|
ViewContext,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
|
@ -31,7 +31,7 @@ impl<V: 'static> Element<V> for Text {
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
_view: &mut V,
|
_view: &mut V,
|
||||||
cx: &mut LayoutContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> Result<(LayoutId, Self::PaintState)> {
|
) -> Result<(LayoutId, Self::PaintState)> {
|
||||||
let fonts = cx.platform().fonts();
|
let fonts = cx.platform().fonts();
|
||||||
let text_style = cx.text_style();
|
let text_style = cx.text_style();
|
||||||
|
|
|
@ -3,10 +3,10 @@ pub mod color;
|
||||||
pub mod element;
|
pub mod element;
|
||||||
pub mod elements;
|
pub mod elements;
|
||||||
pub mod interactive;
|
pub mod interactive;
|
||||||
pub mod layout_context;
|
|
||||||
pub mod paint_context;
|
pub mod paint_context;
|
||||||
pub mod style;
|
pub mod style;
|
||||||
pub mod view;
|
pub mod view;
|
||||||
|
pub mod view_context;
|
||||||
|
|
||||||
pub use color::*;
|
pub use color::*;
|
||||||
pub use element::{AnyElement, Element, IntoElement, Layout, ParentElement};
|
pub use element::{AnyElement, Element, IntoElement, Layout, ParentElement};
|
||||||
|
@ -17,7 +17,7 @@ pub use geometry::{
|
||||||
pub use gpui::*;
|
pub use gpui::*;
|
||||||
pub use gpui2_macros::{Element, *};
|
pub use gpui2_macros::{Element, *};
|
||||||
pub use interactive::*;
|
pub use interactive::*;
|
||||||
pub use layout_context::LayoutContext;
|
|
||||||
pub use platform::{Platform, WindowBounds, WindowOptions};
|
pub use platform::{Platform, WindowBounds, WindowOptions};
|
||||||
pub use util::arc_cow::ArcCow;
|
pub use util::arc_cow::ArcCow;
|
||||||
pub use view::*;
|
pub use view::*;
|
||||||
|
pub use view_context::ViewContext;
|
||||||
|
|
|
@ -2,17 +2,17 @@ use crate::{element::LayoutId, style::Style};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use gpui::{geometry::Size, MeasureParams};
|
use gpui::{geometry::Size, MeasureParams};
|
||||||
pub use gpui::{taffy::tree::NodeId, LayoutContext as LegacyLayoutContext};
|
pub use gpui::{taffy::tree::NodeId, ViewContext as LegacyViewContext};
|
||||||
|
|
||||||
#[derive(Deref, DerefMut)]
|
#[derive(Deref, DerefMut)]
|
||||||
pub struct LayoutContext<'a, 'b, 'c, 'd, V> {
|
pub struct ViewContext<'a, 'b, 'c, V> {
|
||||||
#[deref]
|
#[deref]
|
||||||
#[deref_mut]
|
#[deref_mut]
|
||||||
pub(crate) legacy_cx: &'d mut LegacyLayoutContext<'a, 'b, 'c, V>,
|
pub(crate) legacy_cx: &'c mut LegacyViewContext<'a, 'b, V>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'c, 'd, V: 'static> LayoutContext<'a, 'b, 'c, 'd, V> {
|
impl<'a, 'b, 'c, V: 'static> ViewContext<'a, 'b, 'c, V> {
|
||||||
pub fn new(legacy_cx: &'d mut LegacyLayoutContext<'a, 'b, 'c, V>) -> Self {
|
pub fn new(legacy_cx: &'c mut LegacyViewContext<'a, 'b, V>) -> Self {
|
||||||
Self { legacy_cx }
|
Self { legacy_cx }
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ pub fn derive_element(input: TokenStream) -> TokenStream {
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
cx: &mut gpui2::element::LayoutContext<V>,
|
cx: &mut gpui2::ViewContext<V>,
|
||||||
) -> anyhow::Result<(gpui2::element::LayoutId, Self::PaintState)> {
|
) -> anyhow::Result<(gpui2::element::LayoutId, Self::PaintState)> {
|
||||||
let mut rendered_element = self.render(view, cx).into_element().into_any();
|
let mut rendered_element = self.render(view, cx).into_element().into_any();
|
||||||
let layout_id = rendered_element.layout(view, cx)?;
|
let layout_id = rendered_element.layout(view, cx)?;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use gpui2::{
|
use gpui2::{
|
||||||
elements::div, interactive::Interactive, platform::MouseButton, style::StyleHelpers, ArcCow,
|
elements::div, interactive::Interactive, platform::MouseButton, style::StyleHelpers, ArcCow,
|
||||||
Element, IntoElement, ParentElement, ViewContext,
|
Element, EventContext, IntoElement, ParentElement, ViewContext,
|
||||||
};
|
};
|
||||||
use std::{marker::PhantomData, rc::Rc};
|
use std::{marker::PhantomData, rc::Rc};
|
||||||
|
|
||||||
struct ButtonHandlers<V, D> {
|
struct ButtonHandlers<V, D> {
|
||||||
click: Option<Rc<dyn Fn(&mut V, &D, &mut ViewContext<V>)>>,
|
click: Option<Rc<dyn Fn(&mut V, &D, &mut EventContext<V>)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V, D> Default for ButtonHandlers<V, D> {
|
impl<V, D> Default for ButtonHandlers<V, D> {
|
||||||
|
@ -59,7 +59,10 @@ impl<V: 'static, D: 'static> Button<V, D> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_click(mut self, handler: impl Fn(&mut V, &D, &mut ViewContext<V>) + 'static) -> Self {
|
pub fn on_click(
|
||||||
|
mut self,
|
||||||
|
handler: impl Fn(&mut V, &D, &mut EventContext<V>) + 'static,
|
||||||
|
) -> Self {
|
||||||
self.handlers.click = Some(Rc::new(handler));
|
self.handlers.click = Some(Rc::new(handler));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ fn main() {
|
||||||
|cx| {
|
|cx| {
|
||||||
view(|cx| {
|
view(|cx| {
|
||||||
cx.enable_inspector();
|
cx.enable_inspector();
|
||||||
storybook(cx)
|
storybook(&mut ViewContext::new(cx))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use gpui2::{
|
use gpui2::{
|
||||||
color::Hsla,
|
color::Hsla,
|
||||||
element::{Element, PaintContext},
|
element::{Element, PaintContext},
|
||||||
layout_context::LayoutContext,
|
serde_json, AppContext, IntoElement, Vector2F, ViewContext, WindowContext,
|
||||||
serde_json, AppContext, IntoElement, Vector2F, WindowContext,
|
|
||||||
};
|
};
|
||||||
use serde::{de::Visitor, Deserialize, Deserializer};
|
use serde::{de::Visitor, Deserialize, Deserializer};
|
||||||
use std::{collections::HashMap, fmt, marker::PhantomData};
|
use std::{collections::HashMap, fmt, marker::PhantomData};
|
||||||
|
@ -146,7 +145,7 @@ impl<V: 'static, E: Element<V>> Element<V> for Themed<V, E> {
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
cx: &mut LayoutContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> anyhow::Result<(gpui2::LayoutId, Self::PaintState)>
|
) -> anyhow::Result<(gpui2::LayoutId, Self::PaintState)>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue