Include drop shadows with different corner radii in the example

This commit is contained in:
Nathan Sobo 2023-08-12 11:08:27 -06:00
parent 65123e6eed
commit fa7ebd0825

View file

@ -1,4 +1,7 @@
use gpui::{color::Color, geometry::rect::RectF, AnyElement, App, Element, Entity, Quad, View}; use gpui::{
color::Color, geometry::rect::RectF, scene::Shadow, AnyElement, App, Element, Entity, Quad,
View,
};
use log::LevelFilter; use log::LevelFilter;
use pathfinder_geometry::vector::vec2f; use pathfinder_geometry::vector::vec2f;
use simplelog::SimpleLogger; use simplelog::SimpleLogger;
@ -8,29 +11,29 @@ fn main() {
App::new(()).unwrap().run(|cx| { App::new(()).unwrap().run(|cx| {
cx.platform().activate(true); cx.platform().activate(true);
cx.add_window(Default::default(), |_| QuadView); cx.add_window(Default::default(), |_| CornersView);
}); });
} }
struct QuadView; struct CornersView;
impl Entity for QuadView { impl Entity for CornersView {
type Event = (); type Event = ();
} }
impl View for QuadView { impl View for CornersView {
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
"QuadView" "CornersView"
} }
fn render(&mut self, _: &mut gpui::ViewContext<Self>) -> AnyElement<QuadView> { fn render(&mut self, _: &mut gpui::ViewContext<Self>) -> AnyElement<CornersView> {
QuadElement.into_any() CornersElement.into_any()
} }
} }
struct QuadElement; struct CornersElement;
impl<V: View> gpui::Element<V> for QuadElement { impl<V: View> gpui::Element<V> for CornersElement {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();
@ -47,12 +50,20 @@ impl<V: View> gpui::Element<V> for QuadElement {
fn paint( fn paint(
&mut self, &mut self,
scene: &mut gpui::SceneBuilder, scene: &mut gpui::SceneBuilder,
_: pathfinder_geometry::rect::RectF, bounds: pathfinder_geometry::rect::RectF,
_: pathfinder_geometry::rect::RectF, _: pathfinder_geometry::rect::RectF,
_: &mut Self::LayoutState, _: &mut Self::LayoutState,
_: &mut V, _: &mut V,
_: &mut gpui::PaintContext<V>, _: &mut gpui::PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
scene.push_quad(Quad {
bounds,
background: Some(Color::white()),
..Default::default()
});
scene.push_layer(None);
scene.push_quad(Quad { scene.push_quad(Quad {
bounds: RectF::new(vec2f(100., 100.), vec2f(100., 100.)), bounds: RectF::new(vec2f(100., 100.), vec2f(100., 100.)),
background: Some(Color::red()), background: Some(Color::red()),
@ -92,6 +103,30 @@ impl<V: View> gpui::Element<V> for QuadElement {
..Default::default() ..Default::default()
}, },
}); });
scene.push_shadow(Shadow {
bounds: RectF::new(vec2f(400., 100.), vec2f(100., 100.)),
corner_radii: gpui::scene::CornerRadii {
bottom_right: 20.,
..Default::default()
},
sigma: 20.0,
color: Color::black(),
});
scene.push_layer(None);
scene.push_quad(Quad {
bounds: RectF::new(vec2f(400., 100.), vec2f(100., 100.)),
background: Some(Color::red()),
border: Default::default(),
corner_radii: gpui::scene::CornerRadii {
bottom_right: 20.,
..Default::default()
},
});
scene.pop_layer();
scene.pop_layer();
} }
fn rect_for_text_range( fn rect_for_text_range(