Skip to main content

gpui_types/
scene.rs

1//! GPU-facing scene primitives shared between GPUI and its platform backends.
2
3use crate::{Bounds, Corners, Hsla, Pixels, ScaledPixels};
4use core::fmt::Debug;
5
6/// The order in which a primitive is painted within a frame.
7///
8/// Primitives with a lower order are painted behind those with a higher order.
9pub type DrawOrder = u32;
10
11/// Indicates which region of the window is visible. Content falling outside of this mask will not be
12/// rendered. Currently, only rectangular content masks are supported, but we give the mask its own type
13/// to leave room to support more complex shapes in the future.
14#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
15#[repr(C)]
16pub struct ContentMask<P: Clone + Debug + Default + PartialEq> {
17    /// The bounds
18    pub bounds: Bounds<P>,
19}
20
21impl ContentMask<Pixels> {
22    /// Scale the content mask's pixel units by the given scaling factor.
23    pub fn scale(&self, factor: f32) -> ContentMask<ScaledPixels> {
24        ContentMask {
25            bounds: self.bounds.scale(factor),
26        }
27    }
28
29    /// Intersect the content mask with the given content mask.
30    pub fn intersect(&self, other: &Self) -> Self {
31        let bounds = self.bounds.intersect(&other.bounds);
32        ContentMask { bounds }
33    }
34}
35
36#[derive(Debug, Copy, Clone)]
37#[repr(C)]
38#[expect(missing_docs)]
39pub struct Shadow {
40    pub order: DrawOrder,
41    pub blur_radius: ScaledPixels,
42    pub bounds: Bounds<ScaledPixels>,
43    pub corner_radii: Corners<ScaledPixels>,
44    pub content_mask: ContentMask<ScaledPixels>,
45    pub color: Hsla,
46    pub element_bounds: Bounds<ScaledPixels>,
47    pub element_corner_radii: Corners<ScaledPixels>,
48    /// 0 = drop shadow (rendered outside the element), 1 = inset shadow (rendered inside).
49    pub inset: u32,
50    pub pad: u32, // align to 8 bytes
51}