mirror of
https://github.com/zed-industries/zed.git
synced 2024-10-27 16:57:08 +00:00
Checkpoint
This commit is contained in:
parent
d995192dde
commit
7f9e3bc787
3 changed files with 50 additions and 11 deletions
|
@ -7,12 +7,12 @@ use smallvec::SmallVec;
|
|||
|
||||
// Exported to metal
|
||||
pub type PointF = Point<f32>;
|
||||
pub type StackingOrder = SmallVec<[u32; 16]>;
|
||||
pub type LayerId = SmallVec<[u32; 16]>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Scene {
|
||||
pub(crate) scale_factor: f32,
|
||||
pub(crate) layers: BTreeMap<StackingOrder, SceneLayer>,
|
||||
pub(crate) layers: BTreeMap<LayerId, SceneLayer>,
|
||||
}
|
||||
|
||||
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 primitive = primitive.into();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{
|
||||
px, AnyView, AppContext, AvailableSpace, Bounds, Context, Effect, Element, EntityId, FontId,
|
||||
GlyphId, GlyphRasterParams, Handle, Hsla, IsZero, LayoutId, MainThread, MainThreadOnly,
|
||||
MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, Reference, Scene, Size,
|
||||
StackContext, StackingOrder, Style, TaffyLayoutEngine, WeakHandle, WindowOptions,
|
||||
px, AnyView, AppContext, AvailableSpace, Bounds, Context, Corners, Effect, Element, EntityId,
|
||||
FontId, GlyphId, GlyphRasterParams, Handle, Hsla, IsZero, LayerId, LayoutId, MainThread,
|
||||
MainThreadOnly, MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, Reference,
|
||||
Scene, Size, StackContext, Style, TaffyLayoutEngine, WeakHandle, WindowOptions,
|
||||
SUBPIXEL_VARIANTS,
|
||||
};
|
||||
use anyhow::Result;
|
||||
|
@ -22,7 +22,8 @@ pub struct Window {
|
|||
layout_engine: TaffyLayoutEngine,
|
||||
pub(crate) root_view: Option<AnyView<()>>,
|
||||
mouse_position: Point<Pixels>,
|
||||
current_layer_id: StackingOrder,
|
||||
current_layer_id: LayerId,
|
||||
content_mask_stack: Vec<ContentMask>,
|
||||
pub(crate) scene: Scene,
|
||||
pub(crate) dirty: bool,
|
||||
}
|
||||
|
@ -64,12 +65,19 @@ impl Window {
|
|||
root_view: None,
|
||||
mouse_position,
|
||||
current_layer_id: SmallVec::new(),
|
||||
content_mask_stack: Vec::new(),
|
||||
scene: Scene::new(scale_factor),
|
||||
dirty: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ContentMask {
|
||||
bounds: Bounds<Pixels>,
|
||||
corner_radii: Corners<Pixels>,
|
||||
}
|
||||
|
||||
pub struct WindowContext<'a, 'w> {
|
||||
app: Reference<'a, AppContext>,
|
||||
window: Reference<'w, Window>,
|
||||
|
@ -145,10 +153,41 @@ impl<'a, 'w> WindowContext<'a, 'w> {
|
|||
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()
|
||||
}
|
||||
|
||||
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>(
|
||||
&self,
|
||||
f: impl FnOnce(&mut MainThread<WindowContext>) -> R + Send + 'static,
|
||||
|
|
|
@ -4,8 +4,8 @@ use crate::{
|
|||
themes::rose_pine_dawn,
|
||||
};
|
||||
use gpui3::{
|
||||
black, div, img, svg, view, white, Context, Element, ParentElement, RootView, StyleHelpers,
|
||||
View, ViewContext, WindowContext,
|
||||
div, img, svg, view, Context, Element, ParentElement, RootView, StyleHelpers, View,
|
||||
ViewContext, WindowContext,
|
||||
};
|
||||
|
||||
pub struct Workspace {
|
||||
|
|
Loading…
Reference in a new issue