Skip to main content

ferroui_base/rendering/scene_graph/
custom_draw_operation.rs

1use crate::media::{Geometry, ImmediateDrawingContext, IntersectionResult};
2use crate::{Point, Rect, Ref};
3
4/// Represents a custom draw operation in the low-level scene graph.
5///
6/// An operation is created on the UI thread and rendered on the render
7/// thread, so it is `Send + Sync`: what it draws with is captured by value
8/// or in thread-safe form.
9pub trait ICustomDrawOperation: Send + Sync + 'static {
10    /// The bounds of the visible content in the node in global coordinates.
11    fn bounds(&self) -> Rect;
12
13    /// Hit tests the node against a point, in global coordinates.
14    ///
15    /// The implementation is responsible for checking transforms and
16    /// geometry clips if necessary.
17    fn hit_test(&self, p: Point) -> bool;
18
19    /// Hit tests the node against a geometry.
20    fn hit_test_geometry(&self, _geometry: &Ref<Geometry>) -> IntersectionResult {
21        IntersectionResult::Empty
22    }
23
24    /// Renders the node to a drawing context.
25    fn render(&self, context: &mut ImmediateDrawingContext<'_>);
26
27    /// Value equality between operations (C# `IEquatable<ICustomDrawOperation>`).
28    fn equals(&self, other: &dyn ICustomDrawOperation) -> bool;
29
30    /// Releases the operation's resources.
31    fn dispose(&self);
32}