Checkpoint

This commit is contained in:
Nathan Sobo 2023-10-03 17:58:11 -06:00
parent d995192dde
commit 7f9e3bc787
3 changed files with 50 additions and 11 deletions

View file

@ -7,12 +7,12 @@ use smallvec::SmallVec;
// Exported to metal // Exported to metal
pub type PointF = Point<f32>; pub type PointF = Point<f32>;
pub type StackingOrder = SmallVec<[u32; 16]>; pub type LayerId = SmallVec<[u32; 16]>;
#[derive(Debug)] #[derive(Debug)]
pub struct Scene { pub struct Scene {
pub(crate) scale_factor: f32, pub(crate) scale_factor: f32,
pub(crate) layers: BTreeMap<StackingOrder, SceneLayer>, pub(crate) layers: BTreeMap<LayerId, SceneLayer>,
} }
impl Scene { impl Scene {
@ -30,7 +30,7 @@ impl Scene {
} }
} }
pub fn insert(&mut self, stacking_order: StackingOrder, primitive: impl Into<Primitive>) { pub fn insert(&mut self, stacking_order: LayerId, primitive: impl Into<Primitive>) {
let layer = self.layers.entry(stacking_order).or_default(); let layer = self.layers.entry(stacking_order).or_default();
let primitive = primitive.into(); let primitive = primitive.into();

View file

@ -1,8 +1,8 @@
use crate::{ use crate::{
px, AnyView, AppContext, AvailableSpace, Bounds, Context, Effect, Element, EntityId, FontId, px, AnyView, AppContext, AvailableSpace, Bounds, Context, Corners, Effect, Element, EntityId,
GlyphId, GlyphRasterParams, Handle, Hsla, IsZero, LayoutId, MainThread, MainThreadOnly, FontId, GlyphId, GlyphRasterParams, Handle, Hsla, IsZero, LayerId, LayoutId, MainThread,
MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, Reference, Scene, Size, MainThreadOnly, MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, Reference,
StackContext, StackingOrder, Style, TaffyLayoutEngine, WeakHandle, WindowOptions, Scene, Size, StackContext, Style, TaffyLayoutEngine, WeakHandle, WindowOptions,
SUBPIXEL_VARIANTS, SUBPIXEL_VARIANTS,
}; };
use anyhow::Result; use anyhow::Result;
@ -22,7 +22,8 @@ pub struct Window {
layout_engine: TaffyLayoutEngine, layout_engine: TaffyLayoutEngine,
pub(crate) root_view: Option<AnyView<()>>, pub(crate) root_view: Option<AnyView<()>>,
mouse_position: Point<Pixels>, mouse_position: Point<Pixels>,
current_layer_id: StackingOrder, current_layer_id: LayerId,
content_mask_stack: Vec<ContentMask>,
pub(crate) scene: Scene, pub(crate) scene: Scene,
pub(crate) dirty: bool, pub(crate) dirty: bool,
} }
@ -64,12 +65,19 @@ impl Window {
root_view: None, root_view: None,
mouse_position, mouse_position,
current_layer_id: SmallVec::new(), current_layer_id: SmallVec::new(),
content_mask_stack: Vec::new(),
scene: Scene::new(scale_factor), scene: Scene::new(scale_factor),
dirty: true, dirty: true,
} }
} }
} }
#[derive(Clone, Debug)]
pub struct ContentMask {
bounds: Bounds<Pixels>,
corner_radii: Corners<Pixels>,
}
pub struct WindowContext<'a, 'w> { pub struct WindowContext<'a, 'w> {
app: Reference<'a, AppContext>, app: Reference<'a, AppContext>,
window: Reference<'w, Window>, window: Reference<'w, Window>,
@ -145,10 +153,41 @@ impl<'a, 'w> WindowContext<'a, 'w> {
result result
} }
pub fn current_layer_id(&self) -> StackingOrder { pub fn clip<F, R>(
&mut self,
bounds: Bounds<Pixels>,
corner_radii: Corners<Pixels>,
f: impl FnOnce(&mut Self) -> R,
) -> R {
let clip_mask = ContentMask {
bounds,
corner_radii,
};
self.window.content_mask_stack.push(clip_mask);
let result = f(self);
self.window.content_mask_stack.pop();
result
}
pub fn current_layer_id(&self) -> LayerId {
self.window.current_layer_id.clone() self.window.current_layer_id.clone()
} }
pub fn current_clipping_mask(&self) -> ContentMask {
self.window
.content_mask_stack
.last()
.cloned()
.unwrap_or_else(|| ContentMask {
bounds: Bounds {
origin: Point::default(),
size: self.window.content_size,
},
corner_radii: Default::default(),
})
}
pub fn run_on_main<R>( pub fn run_on_main<R>(
&self, &self,
f: impl FnOnce(&mut MainThread<WindowContext>) -> R + Send + 'static, f: impl FnOnce(&mut MainThread<WindowContext>) -> R + Send + 'static,

View file

@ -4,8 +4,8 @@ use crate::{
themes::rose_pine_dawn, themes::rose_pine_dawn,
}; };
use gpui3::{ use gpui3::{
black, div, img, svg, view, white, Context, Element, ParentElement, RootView, StyleHelpers, div, img, svg, view, Context, Element, ParentElement, RootView, StyleHelpers, View,
View, ViewContext, WindowContext, ViewContext, WindowContext,
}; };
pub struct Workspace { pub struct Workspace {