Merge branch 'gpui2' into marshall/gpui2-playground

This commit is contained in:
Marshall Bowers
2023-10-06 13:45:11 -04:00
34 changed files with 2709 additions and 619 deletions
+10 -17
View File
@@ -1,6 +1,6 @@
use crate::{
AnyElement, Bounds, Element, Layout, LayoutId, Overflow, ParentElement, Pixels, Point,
Refineable, RefinementCascade, Result, Style, StyleHelpers, Styled, ViewContext,
AnyElement, Bounds, Element, LayoutId, Overflow, ParentElement, Pixels, Point, Refineable,
RefinementCascade, Result, Style, StyleHelpers, Styled, ViewContext,
};
use parking_lot::Mutex;
use smallvec::SmallVec;
@@ -40,34 +40,28 @@ impl<S: 'static + Send + Sync> Element for Div<S> {
fn paint(
&mut self,
layout: Layout,
bounds: Bounds<Pixels>,
state: &mut S,
child_layouts: &mut Self::FrameState,
cx: &mut ViewContext<S>,
) -> Result<()> {
let Layout { order, bounds } = layout;
let style = self.computed_style();
style.paint(order, bounds, cx);
cx.stack(0, |cx| style.paint(bounds, cx));
// // todo!("support only one dimension being hidden")
let overflow = &style.overflow;
// if style.overflow.y != Overflow::Visible || style.overflow.x != Overflow::Visible {
// cx.clip(layout.bounds, style.corner_radii, || )
// }
style.apply_text_style(cx, |cx| {
style.apply_overflow(layout.bounds, cx, |cx| {
self.paint_children(overflow, state, cx)
cx.stack(1, |cx| {
style.apply_overflow(bounds, cx, |cx| self.paint_children(overflow, state, cx))
})
})?;
self.handle_scroll(order, bounds, style.overflow.clone(), child_layouts, cx);
self.handle_scroll(bounds, style.overflow.clone(), child_layouts, cx);
// todo!("enable inspector")
// if cx.is_inspector_enabled() {
// self.paint_inspector(parent_origin, layout, cx);
// }
//
Ok(())
}
}
@@ -142,7 +136,6 @@ impl<S: 'static> Div<S> {
fn handle_scroll(
&mut self,
_order: u32,
bounds: Bounds<Pixels>,
overflow: Point<Overflow>,
child_layout_ids: &[LayoutId],
@@ -151,8 +144,8 @@ impl<S: 'static> Div<S> {
if overflow.y == Overflow::Scroll || overflow.x == Overflow::Scroll {
let mut scroll_max = Point::default();
for child_layout_id in child_layout_ids {
if let Some(child_layout) = cx.layout(*child_layout_id).log_err() {
scroll_max = scroll_max.max(&child_layout.bounds.lower_right());
if let Some(child_bounds) = cx.layout_bounds(*child_layout_id).log_err() {
scroll_max = scroll_max.max(&child_bounds.lower_right());
}
}
scroll_max -= bounds.size;
+10 -13
View File
@@ -1,6 +1,6 @@
use crate::{
BorrowWindow, Element, Layout, LayoutId, Result, SharedString, Style, StyleHelpers, Styled,
ViewContext,
BorrowWindow, Bounds, Element, LayoutId, Pixels, Result, SharedString, Style, StyleHelpers,
Styled, ViewContext,
};
use futures::FutureExt;
use refineable::RefinementCascade;
@@ -54,16 +54,14 @@ impl<S: Send + Sync + 'static> Element for Img<S> {
fn paint(
&mut self,
layout: Layout,
bounds: Bounds<Pixels>,
_: &mut Self::State,
_: &mut Self::FrameState,
cx: &mut ViewContext<Self::State>,
) -> Result<()> {
let style = self.computed_style();
let order = layout.order;
let bounds = layout.bounds;
style.paint(order, bounds, cx);
style.paint(bounds, cx);
if let Some(uri) = self.uri.clone() {
let image_future = cx.image_cache.get(uri);
@@ -72,15 +70,14 @@ impl<S: Send + Sync + 'static> Element for Img<S> {
.now_or_never()
.and_then(ResultExt::log_err)
{
let corner_radii = style.corner_radii.to_pixels(bounds, cx.rem_size());
cx.paint_image(bounds, corner_radii, order, data, self.grayscale)?;
let corner_radii = style.corner_radii.to_pixels(bounds.size, cx.rem_size());
cx.stack(1, |cx| {
cx.paint_image(bounds, corner_radii, data, self.grayscale)
})?;
} else {
cx.spawn(|view, mut cx| async move {
cx.spawn(|_, mut cx| async move {
if image_future.await.log_err().is_some() {
view.update(&mut cx, |_, cx| {
cx.notify();
})
.ok();
cx.on_next_frame(|cx| cx.notify());
}
})
.detach()
+3 -3
View File
@@ -1,4 +1,4 @@
use crate::Element;
use crate::{Bounds, Element, Pixels};
use std::marker::PhantomData;
pub struct Stateless<E: Element<State = ()>, S> {
@@ -20,11 +20,11 @@ impl<E: Element<State = ()>, S: Send + Sync + 'static> Element for Stateless<E,
fn paint(
&mut self,
layout: crate::Layout,
bounds: Bounds<Pixels>,
_: &mut Self::State,
frame_state: &mut Self::FrameState,
cx: &mut crate::ViewContext<Self::State>,
) -> anyhow::Result<()> {
cx.erase_state(|cx| self.element.paint(layout, &mut (), frame_state, cx))
cx.erase_state(|cx| self.element.paint(bounds, &mut (), frame_state, cx))
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
use crate::{Element, Layout, LayoutId, Result, SharedString, Style, StyleHelpers, Styled};
use crate::{Bounds, Element, LayoutId, Pixels, Result, SharedString, Style, StyleHelpers, Styled};
use refineable::RefinementCascade;
use std::marker::PhantomData;
@@ -41,7 +41,7 @@ impl<S: 'static> Element for Svg<S> {
fn paint(
&mut self,
layout: Layout,
bounds: Bounds<Pixels>,
_: &mut Self::State,
_: &mut Self::FrameState,
cx: &mut crate::ViewContext<S>,
@@ -51,7 +51,7 @@ impl<S: 'static> Element for Svg<S> {
{
let fill_color = self.computed_style().fill.and_then(|fill| fill.color());
if let Some((path, fill_color)) = self.path.as_ref().zip(fill_color) {
cx.paint_svg(layout.bounds, layout.order, path.clone(), fill_color)?;
cx.paint_svg(bounds, path.clone(), fill_color)?;
}
Ok(())
}
+3 -4
View File
@@ -1,5 +1,5 @@
use crate::{
AnyElement, Element, IntoAnyElement, Layout, LayoutId, Line, Pixels, Result, Size, ViewContext,
AnyElement, Bounds, Element, IntoAnyElement, LayoutId, Line, Pixels, Result, Size, ViewContext,
};
use parking_lot::Mutex;
use std::{marker::PhantomData, sync::Arc};
@@ -94,7 +94,7 @@ impl<S: 'static> Element for Text<S> {
fn paint<'a>(
&mut self,
layout: Layout,
bounds: Bounds<Pixels>,
_: &mut Self::State,
frame_state: &mut Self::FrameState,
cx: &mut ViewContext<S>,
@@ -111,8 +111,7 @@ impl<S: 'static> Element for Text<S> {
}
// todo!("We haven't added visible bounds to the new element system yet, so this is a placeholder.");
let visible_bounds = layout.bounds;
line.paint(&layout, visible_bounds, line_height, cx)?;
line.paint(bounds, bounds, line_height, cx)?;
Ok(())
}