Checkpoint

This commit is contained in:
Nathan Sobo 2023-08-30 14:40:43 -06:00
parent 1d491fcd78
commit 746f77bf7c
14 changed files with 226 additions and 250 deletions

24
Cargo.lock generated
View file

@ -3163,6 +3163,19 @@ dependencies = [
"waker-fn", "waker-fn",
] ]
[[package]]
name = "gpui2"
version = "0.1.0"
[[package]]
name = "gpui2_macros"
version = "0.1.0"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "gpui_macros" name = "gpui_macros"
version = "0.1.0" version = "0.1.0"
@ -5172,9 +5185,9 @@ dependencies = [
"anyhow", "anyhow",
"derive_more", "derive_more",
"gpui", "gpui",
"gpui2_macros",
"log", "log",
"parking_lot 0.11.2", "parking_lot 0.11.2",
"playground_macros",
"refineable", "refineable",
"rust-embed", "rust-embed",
"serde", "serde",
@ -5185,15 +5198,6 @@ dependencies = [
"util", "util",
] ]
[[package]]
name = "playground_macros"
version = "0.1.0"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "plist" name = "plist"
version = "1.5.0" version = "1.5.0"

View file

@ -33,8 +33,9 @@ members = [
"crates/go_to_line", "crates/go_to_line",
"crates/gpui", "crates/gpui",
"crates/gpui/playground", "crates/gpui/playground",
"crates/gpui/playground_macros",
"crates/gpui_macros", "crates/gpui_macros",
"crates/gpui2",
"crates/gpui2_macros",
"crates/install_cli", "crates/install_cli",
"crates/journal", "crates/journal",
"crates/language", "crates/language",

View file

@ -13,7 +13,7 @@ anyhow.workspace = true
derive_more.workspace = true derive_more.workspace = true
gpui = { path = ".." } gpui = { path = ".." }
log.workspace = true log.workspace = true
playground_macros = { path = "../playground_macros" } gpui2_macros = { path = "../../gpui2_macros" }
parking_lot.workspace = true parking_lot.workspace = true
refineable.workspace = true refineable.workspace = true
rust-embed.workspace = true rust-embed.workspace = true

View file

@ -7,7 +7,7 @@ use crate::{
// themes::Theme, // themes::Theme,
}; };
use gpui::{platform::MouseButton, ViewContext}; use gpui::{platform::MouseButton, ViewContext};
use playground_macros::Element; use gpui2_macros::Element;
use std::{marker::PhantomData, rc::Rc}; use std::{marker::PhantomData, rc::Rc};
struct ButtonHandlers<V, D> { struct ButtonHandlers<V, D> {

View file

@ -16,7 +16,7 @@ use gpui::{
}, },
taffy, taffy,
}; };
use playground_macros::styleable_helpers; use gpui2_macros::styleable_helpers;
use refineable::{Refineable, RefinementCascade}; use refineable::{Refineable, RefinementCascade};
#[derive(Clone, Refineable)] #[derive(Clone, Refineable)]

View file

@ -5,7 +5,7 @@ use crate::{
themes::theme, themes::theme,
}; };
use gpui::{geometry::pixels, ViewContext}; use gpui::{geometry::pixels, ViewContext};
use playground_macros::Element; use gpui2_macros::Element;
use crate as playground; use crate as playground;
#[derive(Element)] #[derive(Element)]

9
crates/gpui2/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "gpui2"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

14
crates/gpui2/src/lib.rs Normal file
View file

@ -0,0 +1,14 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

View file

@ -1,11 +1,11 @@
[package] [package]
name = "playground_macros" name = "gpui2_macros"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
publish = false publish = false
[lib] [lib]
path = "src/playground_macros.rs" path = "src/gpui2_macros.rs"
proc-macro = true proc-macro = true
[dependencies] [dependencies]

414
test.rs
View file

@ -17,10 +17,10 @@ use simplelog::SimpleLogger;
use themes::{rose_pine, ThemeColors}; use themes::{rose_pine, ThemeColors};
use view::view; use view::view;
mod adapter { mod adapter {
use crate::element::AnyElement;
use crate::element::{LayoutContext, PaintContext}; use crate::element::{LayoutContext, PaintContext};
use gpui::{geometry::rect::RectF, LayoutEngine}; use gpui::{geometry::rect::RectF, LayoutEngine};
use util::ResultExt; use util::ResultExt;
use crate::element::AnyElement;
pub struct Adapter<V>(pub(crate) AnyElement<V>); pub struct Adapter<V>(pub(crate) AnyElement<V>);
impl<V: 'static> gpui::Element<V> for Adapter<V> { impl<V: 'static> gpui::Element<V> for Adapter<V> {
type LayoutState = Option<LayoutEngine>; type LayoutState = Option<LayoutEngine>;
@ -90,8 +90,8 @@ mod adapter {
} }
mod color { mod color {
#![allow(dead_code)] #![allow(dead_code)]
use std::{num::ParseIntError, ops::Range};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{num::ParseIntError, ops::Range};
pub fn rgb<C: From<Rgba>>(hex: u32) -> C { pub fn rgb<C: From<Rgba>>(hex: u32) -> C {
let r = ((hex >> 16) & 0xFF) as f32 / 255.0; let r = ((hex >> 16) & 0xFF) as f32 / 255.0;
let g = ((hex >> 8) & 0xFF) as f32 / 255.0; let g = ((hex >> 8) & 0xFF) as f32 / 255.0;
@ -130,16 +130,7 @@ mod color {
impl ::core::fmt::Debug for Rgba { impl ::core::fmt::Debug for Rgba {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish( ::core::fmt::Formatter::debug_struct_field4_finish(
f, f, "Rgba", "r", &self.r, "g", &self.g, "b", &self.b, "a", &&self.a,
"Rgba",
"r",
&self.r,
"g",
&self.g,
"b",
&self.b,
"a",
&&self.a,
) )
} }
} }
@ -185,7 +176,12 @@ mod color {
4 => (xm, m, cm), 4 => (xm, m, cm),
_ => (cm, m, xm), _ => (cm, m, xm),
}; };
Rgba { r, g, b, a: color.a } Rgba {
r,
g,
b,
a: color.a,
}
} }
} }
impl TryFrom<&'_ str> for Rgba { impl TryFrom<&'_ str> for Rgba {
@ -239,16 +235,7 @@ mod color {
impl ::core::fmt::Debug for Hsla { impl ::core::fmt::Debug for Hsla {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish( ::core::fmt::Formatter::debug_struct_field4_finish(
f, f, "Hsla", "h", &self.h, "s", &self.s, "l", &self.l, "a", &&self.a,
"Hsla",
"h",
&self.h,
"s",
&self.s,
"l",
&self.l,
"a",
&&self.a,
) )
} }
} }
@ -258,8 +245,7 @@ mod color {
impl ::core::cmp::PartialEq for Hsla { impl ::core::cmp::PartialEq for Hsla {
#[inline] #[inline]
fn eq(&self, other: &Hsla) -> bool { fn eq(&self, other: &Hsla) -> bool {
self.h == other.h && self.s == other.s && self.l == other.l self.h == other.h && self.s == other.s && self.l == other.l && self.a == other.a
&& self.a == other.a
} }
} }
pub fn hsla(h: f32, s: f32, l: f32, a: f32) -> Hsla { pub fn hsla(h: f32, s: f32, l: f32, a: f32) -> Hsla {
@ -271,7 +257,12 @@ mod color {
} }
} }
pub fn black() -> Hsla { pub fn black() -> Hsla {
Hsla { h: 0., s: 0., l: 0., a: 1. } Hsla {
h: 0.,
s: 0.,
l: 0.,
a: 1.,
}
} }
impl From<Rgba> for Hsla { impl From<Rgba> for Hsla {
fn from(color: Rgba) -> Self { fn from(color: Rgba) -> Self {
@ -298,7 +289,12 @@ mod color {
} else { } else {
((r - g) / delta + 4.0) / 6.0 ((r - g) / delta + 4.0) / 6.0
}; };
Hsla { h, s, l, a: color.a } Hsla {
h,
s,
l,
a: color.a,
}
} }
} }
impl Hsla { impl Hsla {
@ -364,8 +360,7 @@ mod color {
positions: SmallVec::new(), positions: SmallVec::new(),
}; };
let num_colors: f32 = scale.colors.len() as f32 - 1.0; let num_colors: f32 = scale.colors.len() as f32 - 1.0;
scale scale.positions = (0..scale.colors.len())
.positions = (0..scale.colors.len())
.map(|i| i as f32 / num_colors) .map(|i| i as f32 / num_colors)
.collect(); .collect();
scale scale
@ -375,12 +370,10 @@ mod color {
if true { if true {
if !(0.0 <= t && t <= 1.0) { if !(0.0 <= t && t <= 1.0) {
{ {
::core::panicking::panic_fmt( ::core::panicking::panic_fmt(format_args!(
format_args!( "t value {0} is out of range. Expected value in range 0.0 to 1.0",
"t value {0} is out of range. Expected value in range 0.0 to 1.0", t,
t, ));
),
);
} }
} }
} }
@ -412,10 +405,12 @@ mod color {
mod components { mod components {
use crate::{ use crate::{
element::{Element, ElementMetadata}, element::{Element, ElementMetadata},
frame, text::ArcCow, themes::rose_pine, frame,
text::ArcCow,
themes::rose_pine,
}; };
use gpui::{platform::MouseButton, ViewContext}; use gpui::{platform::MouseButton, ViewContext};
use playground_macros::Element; use gpui2_macros::Element;
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 ViewContext<V>)>>,
@ -498,18 +493,11 @@ mod components {
self.icon = Some(icon.into()); self.icon = Some(icon.into());
self self
} }
pub fn click( pub fn click(self, handler: impl Fn(&mut V, &D, &mut ViewContext<V>) + 'static) -> Self {
self,
handler: impl Fn(&mut V, &D, &mut ViewContext<V>) + 'static,
) -> Self {
let data = self.data.clone(); let data = self.data.clone();
Element::click( Element::click(self, MouseButton::Left, move |view, _, cx| {
self, handler(view, data.as_ref(), cx);
MouseButton::Left, })
move |view, _, cx| {
handler(view, data.as_ref(), cx);
},
)
} }
} }
pub fn button<V>() -> Button<V, ()> { pub fn button<V>() -> Button<V, ()> {
@ -523,11 +511,9 @@ mod components {
.children(self.label.clone()); .children(self.label.clone());
if let Some(handler) = self.handlers.click.clone() { if let Some(handler) = self.handlers.click.clone() {
let data = self.data.clone(); let data = self.data.clone();
button button.mouse_down(MouseButton::Left, move |view, event, cx| {
.mouse_down( handler(view, data.as_ref(), cx)
MouseButton::Left, })
move |view, event, cx| { handler(view, data.as_ref(), cx) },
)
} else { } else {
button button
} }
@ -535,8 +521,11 @@ mod components {
} }
} }
mod element { mod element {
pub use crate::paint_context::PaintContext;
use crate::{ use crate::{
adapter::Adapter, color::Hsla, hoverable::Hoverable, adapter::Adapter,
color::Hsla,
hoverable::Hoverable,
style::{Display, Fill, OptionalStyle, Overflow, Position}, style::{Display, Fill, OptionalStyle, Overflow, Position},
}; };
use anyhow::Result; use anyhow::Result;
@ -546,12 +535,12 @@ mod element {
platform::{MouseButton, MouseButtonEvent}, platform::{MouseButton, MouseButtonEvent},
EngineLayout, EventContext, RenderContext, ViewContext, EngineLayout, EventContext, RenderContext, ViewContext,
}; };
use playground_macros::tailwind_lengths; use gpui2_macros::tailwind_lengths;
use std::{ use std::{
any::{Any, TypeId}, any::{Any, TypeId},
cell::Cell, rc::Rc, cell::Cell,
rc::Rc,
}; };
pub use crate::paint_context::PaintContext;
pub use taffy::tree::NodeId; pub use taffy::tree::NodeId;
pub struct Layout<'a, E: ?Sized> { pub struct Layout<'a, E: ?Sized> {
pub from_engine: EngineLayout, pub from_engine: EngineLayout,
@ -627,33 +616,24 @@ mod element {
Self: Sized, Self: Sized,
{ {
let pressed: Rc<Cell<bool>> = Default::default(); let pressed: Rc<Cell<bool>> = Default::default();
self.mouse_down( self.mouse_down(button, {
button, let pressed = pressed.clone();
{ move |_, _, _| {
let pressed = pressed.clone(); pressed.set(true);
move |_, _, _| { }
pressed.set(true); })
} .mouse_up_outside(button, {
}, let pressed = pressed.clone();
) move |_, _, _| {
.mouse_up_outside( pressed.set(false);
button, }
{ })
let pressed = pressed.clone(); .mouse_up(button, move |view, event, event_cx| {
move |_, _, _| { if pressed.get() {
pressed.set(false); pressed.set(false);
} handler(view, event, event_cx);
}, }
) })
.mouse_up(
button,
move |view, event, event_cx| {
if pressed.get() {
pressed.set(false);
handler(view, event, event_cx);
}
},
)
} }
fn mouse_down( fn mouse_down(
mut self, mut self,
@ -663,17 +643,16 @@ mod element {
where where
Self: Sized, Self: Sized,
{ {
self.handlers_mut() self.handlers_mut().push(EventHandler {
.push(EventHandler { handler: Rc::new(move |view, event, event_cx| {
handler: Rc::new(move |view, event, event_cx| { let event = event.downcast_ref::<MouseButtonEvent>().unwrap();
let event = event.downcast_ref::<MouseButtonEvent>().unwrap(); if event.button == button && event.is_down {
if event.button == button && event.is_down { handler(view, event, event_cx);
handler(view, event, event_cx); }
} }),
}), event_type: TypeId::of::<MouseButtonEvent>(),
event_type: TypeId::of::<MouseButtonEvent>(), outside_bounds: false,
outside_bounds: false, });
});
self self
} }
fn mouse_down_outside( fn mouse_down_outside(
@ -684,17 +663,16 @@ mod element {
where where
Self: Sized, Self: Sized,
{ {
self.handlers_mut() self.handlers_mut().push(EventHandler {
.push(EventHandler { handler: Rc::new(move |view, event, event_cx| {
handler: Rc::new(move |view, event, event_cx| { let event = event.downcast_ref::<MouseButtonEvent>().unwrap();
let event = event.downcast_ref::<MouseButtonEvent>().unwrap(); if event.button == button && event.is_down {
if event.button == button && event.is_down { handler(view, event, event_cx);
handler(view, event, event_cx); }
} }),
}), event_type: TypeId::of::<MouseButtonEvent>(),
event_type: TypeId::of::<MouseButtonEvent>(), outside_bounds: true,
outside_bounds: true, });
});
self self
} }
fn mouse_up( fn mouse_up(
@ -705,17 +683,16 @@ mod element {
where where
Self: Sized, Self: Sized,
{ {
self.handlers_mut() self.handlers_mut().push(EventHandler {
.push(EventHandler { handler: Rc::new(move |view, event, event_cx| {
handler: Rc::new(move |view, event, event_cx| { let event = event.downcast_ref::<MouseButtonEvent>().unwrap();
let event = event.downcast_ref::<MouseButtonEvent>().unwrap(); if event.button == button && !event.is_down {
if event.button == button && !event.is_down { handler(view, event, event_cx);
handler(view, event, event_cx); }
} }),
}), event_type: TypeId::of::<MouseButtonEvent>(),
event_type: TypeId::of::<MouseButtonEvent>(), outside_bounds: false,
outside_bounds: false, });
});
self self
} }
fn mouse_up_outside( fn mouse_up_outside(
@ -726,17 +703,16 @@ mod element {
where where
Self: Sized, Self: Sized,
{ {
self.handlers_mut() self.handlers_mut().push(EventHandler {
.push(EventHandler { handler: Rc::new(move |view, event, event_cx| {
handler: Rc::new(move |view, event, event_cx| { let event = event.downcast_ref::<MouseButtonEvent>().unwrap();
let event = event.downcast_ref::<MouseButtonEvent>().unwrap(); if event.button == button && !event.is_down {
if event.button == button && !event.is_down { handler(view, event, event_cx);
handler(view, event, event_cx); }
} }),
}), event_type: TypeId::of::<MouseButtonEvent>(),
event_type: TypeId::of::<MouseButtonEvent>(), outside_bounds: true,
outside_bounds: true, });
});
self self
} }
fn block(mut self) -> Self fn block(mut self) -> Self
@ -764,9 +740,7 @@ mod element {
where where
Self: Sized, Self: Sized,
{ {
self self.declared_style().overflow = OptionalPoint {
.declared_style()
.overflow = OptionalPoint {
x: Some(Overflow::Visible), x: Some(Overflow::Visible),
y: Some(Overflow::Visible), y: Some(Overflow::Visible),
}; };
@ -776,9 +750,7 @@ mod element {
where where
Self: Sized, Self: Sized,
{ {
self self.declared_style().overflow = OptionalPoint {
.declared_style()
.overflow = OptionalPoint {
x: Some(Overflow::Hidden), x: Some(Overflow::Hidden),
y: Some(Overflow::Hidden), y: Some(Overflow::Hidden),
}; };
@ -788,9 +760,7 @@ mod element {
where where
Self: Sized, Self: Sized,
{ {
self self.declared_style().overflow = OptionalPoint {
.declared_style()
.overflow = OptionalPoint {
x: Some(Overflow::Scroll), x: Some(Overflow::Scroll),
y: Some(Overflow::Scroll), y: Some(Overflow::Scroll),
}; };
@ -4485,11 +4455,7 @@ mod element {
layout: Option<(NodeId, Box<dyn Any>)>, layout: Option<(NodeId, Box<dyn Any>)>,
} }
impl<V: 'static> AnyElement<V> { impl<V: 'static> AnyElement<V> {
pub fn layout( pub fn layout(&mut self, view: &mut V, cx: &mut LayoutContext<V>) -> Result<NodeId> {
&mut self,
view: &mut V,
cx: &mut LayoutContext<V>,
) -> Result<NodeId> {
let pushed_text_style = self.push_text_style(cx); let pushed_text_style = self.push_text_style(cx);
let (node_id, layout) = self.element.layout(view, cx)?; let (node_id, layout) = self.element.layout(view, cx)?;
self.layout = Some((node_id, layout)); self.layout = Some((node_id, layout));
@ -4511,30 +4477,25 @@ mod element {
} }
pub fn paint(&mut self, view: &mut V, cx: &mut PaintContext<V>) -> Result<()> { pub fn paint(&mut self, view: &mut V, cx: &mut PaintContext<V>) -> Result<()> {
let pushed_text_style = self.push_text_style(cx); let pushed_text_style = self.push_text_style(cx);
let (layout_node_id, element_layout) = self let (layout_node_id, element_layout) =
.layout self.layout.as_mut().expect("paint called before layout");
.as_mut()
.expect("paint called before layout");
let layout = Layout { let layout = Layout {
from_engine: cx from_engine: cx
.layout_engine() .layout_engine()
.unwrap() .unwrap()
.computed_layout(*layout_node_id) .computed_layout(*layout_node_id)
.expect( .expect("you can currently only use playground elements within an adapter"),
"you can currently only use playground elements within an adapter",
),
from_element: element_layout.as_mut(), from_element: element_layout.as_mut(),
}; };
let style = self.element.style(); let style = self.element.style();
let fill_color = style.fill.flatten().and_then(|fill| fill.color()); let fill_color = style.fill.flatten().and_then(|fill| fill.color());
if let Some(fill_color) = fill_color { if let Some(fill_color) = fill_color {
cx.scene cx.scene.push_quad(gpui::scene::Quad {
.push_quad(gpui::scene::Quad { bounds: layout.from_engine.bounds,
bounds: layout.from_engine.bounds, background: Some(fill_color.into()),
background: Some(fill_color.into()), border: Default::default(),
border: Default::default(), corner_radii: Default::default(),
corner_radii: Default::default(), });
});
} }
for event_handler in self.element.handlers_mut().iter().cloned() { for event_handler in self.element.handlers_mut().iter().cloned() {
let EngineLayout { order, bounds } = layout.from_engine; let EngineLayout { order, bounds } = layout.from_engine;
@ -4547,10 +4508,7 @@ mod element {
bounds, bounds,
outside_bounds: event_handler.outside_bounds, outside_bounds: event_handler.outside_bounds,
event_handler: Rc::new(move |view, event, window_cx, view_id| { event_handler: Rc::new(move |view, event, window_cx, view_id| {
let mut view_context = ViewContext::mutable( let mut view_context = ViewContext::mutable(window_cx, view_id);
window_cx,
view_id,
);
let mut event_context = EventContext::new(&mut view_context); let mut event_context = EventContext::new(&mut view_context);
view_event_handler( view_event_handler(
view.downcast_mut().unwrap(), view.downcast_mut().unwrap(),
@ -4607,14 +4565,14 @@ mod element {
mod frame { mod frame {
use crate::{ use crate::{
element::{ element::{
AnyElement, Element, EventHandler, IntoElement, Layout, LayoutContext, AnyElement, Element, EventHandler, IntoElement, Layout, LayoutContext, NodeId,
NodeId, PaintContext, PaintContext,
}, },
style::{OptionalStyle, Style}, style::{OptionalStyle, Style},
}; };
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use gpui::LayoutNodeId; use gpui::LayoutNodeId;
use playground_macros::IntoElement; use gpui2_macros::IntoElement;
#[element_crate = "crate"] #[element_crate = "crate"]
pub struct Frame<V: 'static> { pub struct Frame<V: 'static> {
style: OptionalStyle, style: OptionalStyle,
@ -4656,12 +4614,13 @@ mod frame {
let style: Style = self.style.into(); let style: Style = self.style.into();
let node_id = cx let node_id = cx
.layout_engine() .layout_engine()
.ok_or_else(|| ::anyhow::__private::must_use({ .ok_or_else(|| {
let error = ::anyhow::__private::format_err( ::anyhow::__private::must_use({
format_args!("no layout engine"), let error =
); ::anyhow::__private::format_err(format_args!("no layout engine"));
error error
}))? })
})?
.add_node(style.to_taffy(rem_size), child_layout_node_ids)?; .add_node(style.to_taffy(rem_size), child_layout_node_ids)?;
Ok((node_id, ())) Ok((node_id, ()))
} }
@ -4687,18 +4646,23 @@ mod frame {
I: IntoIterator<Item = E>, I: IntoIterator<Item = E>,
E: IntoElement<V>, E: IntoElement<V>,
{ {
self.children.extend(children.into_iter().map(|e| e.into_any_element())); self.children
.extend(children.into_iter().map(|e| e.into_any_element()));
self self
} }
} }
} }
mod hoverable { mod hoverable {
use std::{cell::Cell, marker::PhantomData, rc::Rc}; use crate::{
element::Element,
style::{OptionalStyle, Style},
};
use gpui::{ use gpui::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
scene::MouseMove, EngineLayout, scene::MouseMove,
EngineLayout,
}; };
use crate::{element::Element, style::{OptionalStyle, Style}}; use std::{cell::Cell, marker::PhantomData, rc::Rc};
pub struct Hoverable<V, E> { pub struct Hoverable<V, E> {
hover_style: OptionalStyle, hover_style: OptionalStyle,
computed_style: Option<Style>, computed_style: Option<Style>,
@ -4760,10 +4724,10 @@ mod hoverable {
} }
} }
mod paint_context { mod paint_context {
use std::{any::TypeId, rc::Rc};
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
use gpui::{geometry::rect::RectF, EventContext, RenderContext, ViewContext}; use gpui::{geometry::rect::RectF, EventContext, RenderContext, ViewContext};
pub use gpui::{LayoutContext, PaintContext as LegacyPaintContext}; pub use gpui::{LayoutContext, PaintContext as LegacyPaintContext};
use std::{any::TypeId, rc::Rc};
pub use taffy::tree::NodeId; pub use taffy::tree::NodeId;
pub struct PaintContext<'a, 'b, 'c, 'd, V> { pub struct PaintContext<'a, 'b, 'c, 'd, V> {
#[deref] #[deref]
@ -4833,13 +4797,12 @@ mod paint_context {
mod style { mod style {
use crate::color::Hsla; use crate::color::Hsla;
use gpui::geometry::{ use gpui::geometry::{
DefinedLength, Edges, Length, OptionalEdges, OptionalPoint, OptionalSize, Point, DefinedLength, Edges, Length, OptionalEdges, OptionalPoint, OptionalSize, Point, Size,
Size,
}; };
use optional::Optional; use optional::Optional;
pub use taffy::style::{ pub use taffy::style::{
AlignContent, AlignItems, AlignSelf, Display, FlexDirection, FlexWrap, AlignContent, AlignItems, AlignSelf, Display, FlexDirection, FlexWrap, JustifyContent,
JustifyContent, Overflow, Position, Overflow, Position,
}; };
pub struct Style { pub struct Style {
/// What layout strategy should be used? /// What layout strategy should be used?
@ -5194,9 +5157,7 @@ mod style {
#[inline] #[inline]
fn clone(&self) -> Fill { fn clone(&self) -> Fill {
match self { match self {
Fill::Color(__self_0) => { Fill::Color(__self_0) => Fill::Color(::core::clone::Clone::clone(__self_0)),
Fill::Color(::core::clone::Clone::clone(__self_0))
}
} }
} }
} }
@ -5257,32 +5218,25 @@ mod text {
let text = self.text.clone(); let text = self.text.clone();
let layout = Arc::new(Mutex::new(None)); let layout = Arc::new(Mutex::new(None));
let style: Style = self.metadata.style.into(); let style: Style = self.metadata.style.into();
let node_id = layout_engine let node_id = layout_engine.add_measured_node(style.to_taffy(rem_size), {
.add_measured_node( let layout = layout.clone();
style.to_taffy(rem_size), move |params| {
{ let line_layout = fonts.layout_line(
let layout = layout.clone(); text.as_ref(),
move |params| { text_style.font_size,
let line_layout = fonts &[(text.len(), text_style.to_run())],
.layout_line( );
text.as_ref(), let size = Size {
text_style.font_size, width: line_layout.width,
&[(text.len(), text_style.to_run())], height: line_height,
); };
let size = Size { layout.lock().replace(TextLayout {
width: line_layout.width, line_layout: Arc::new(line_layout),
height: line_height, line_height,
}; });
layout size
.lock() }
.replace(TextLayout { })?;
line_layout: Arc::new(line_layout),
line_height,
});
size
}
},
)?;
Ok((node_id, layout)) Ok((node_id, layout))
} }
fn paint<'a>( fn paint<'a>(
@ -5369,11 +5323,11 @@ mod themes {
use crate::color::{Hsla, Lerp}; use crate::color::{Hsla, Lerp};
use std::ops::Range; use std::ops::Range;
pub mod rose_pine { pub mod rose_pine {
use std::ops::Range;
use crate::{ use crate::{
color::{hsla, rgb, Hsla}, color::{hsla, rgb, Hsla},
ThemeColors, ThemeColors,
}; };
use std::ops::Range;
pub struct RosePineThemes { pub struct RosePineThemes {
pub default: RosePinePalette, pub default: RosePinePalette,
pub dawn: RosePinePalette, pub dawn: RosePinePalette,
@ -5426,7 +5380,7 @@ mod themes {
"highlight_med", "highlight_med",
"highlight_high", "highlight_high",
]; ];
let values: &[&dyn ::core::fmt::Debug] = &[ let values: &[&dyn::core::fmt::Debug] = &[
&self.base, &self.base,
&self.surface, &self.surface,
&self.overlay, &self.overlay,
@ -5636,23 +5590,21 @@ mod view {
} }
} }
fn main() { fn main() {
SimpleLogger::init(LevelFilter::Info, Default::default()) SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
.expect("could not initialize logger"); gpui::App::new(()).unwrap().run(|cx| {
gpui::App::new(()) cx.add_window(
.unwrap() WindowOptions {
.run(|cx| { bounds: gpui::platform::WindowBounds::Fixed(RectF::new(
cx.add_window( vec2f(0., 0.),
WindowOptions { vec2f(400., 300.),
bounds: gpui::platform::WindowBounds::Fixed( )),
RectF::new(vec2f(0., 0.), vec2f(400., 300.)), center: true,
), ..Default::default()
center: true, },
..Default::default() |_| view(|_| playground(&rose_pine::moon())),
}, );
|_| view(|_| playground(&rose_pine::moon())), cx.platform().activate(true);
); });
cx.platform().activate(true);
});
} }
fn playground<V: 'static>(theme: &ThemeColors) -> impl Element<V> { fn playground<V: 'static>(theme: &ThemeColors) -> impl Element<V> {
frame() frame()
@ -5660,11 +5612,7 @@ fn playground<V: 'static>(theme: &ThemeColors) -> impl Element<V> {
.h_full() .h_full()
.w_half() .w_half()
.fill(theme.success(0.5)) .fill(theme.success(0.5))
.child( .child(button().label("Hello").click(|_, _, _| {
button() ::std::io::_print(format_args!("click!\n"));
.label("Hello") }))
.click(|_, _, _| {
::std::io::_print(format_args!("click!\n"));
}),
)
} }