StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use crate::{ |
| 2 | elements::Point, event::DispatchedEvent, geometry::vector::Vector2F, AfterLayoutContext, |
| 3 | AppContext, ClipBounds, Element, EventContext, LayoutContext, PaintContext, SizeConstraint, |
| 4 | }; |
| 5 | |
| 6 | /// Internal elements used to support the `add_overlay_child` and `add_positioned_overlay_child` |
| 7 | /// APIs within the `Stack`. It is a thin wrapper around the child, creating a new Overlay layer |
| 8 | /// and painting the child within that layer, so that it is drawn above the normal UI elements. |
| 9 | pub(super) struct Overlay { |
| 10 | child: Box<dyn Element>, |
| 11 | } |
| 12 | |
| 13 | impl Overlay { |
| 14 | pub fn new(child: Box<dyn Element>) -> Self { |
| 15 | Self { child } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | impl Element for Overlay { |
| 20 | fn layout( |
| 21 | &mut self, |
| 22 | constraint: SizeConstraint, |
| 23 | ctx: &mut LayoutContext, |
| 24 | app: &AppContext, |
| 25 | ) -> Vector2F { |
| 26 | self.child.layout(constraint, ctx, app) |
| 27 | } |
| 28 | |
| 29 | fn after_layout(&mut self, ctx: &mut AfterLayoutContext, app: &AppContext) { |
| 30 | self.child.after_layout(ctx, app) |
| 31 | } |
| 32 | |
| 33 | fn paint(&mut self, origin: Vector2F, ctx: &mut PaintContext, app: &AppContext) { |
| 34 | ctx.scene.start_overlay_layer(ClipBounds::None); |
| 35 | self.child.paint(origin, ctx, app); |
| 36 | ctx.scene.stop_layer(); |
| 37 | } |
| 38 | |
| 39 | fn dispatch_event( |
| 40 | &mut self, |
| 41 | event: &DispatchedEvent, |
| 42 | ctx: &mut EventContext, |
| 43 | app: &AppContext, |
| 44 | ) -> bool { |
| 45 | self.child.dispatch_event(event, ctx, app) |
| 46 | } |
| 47 | |
| 48 | fn size(&self) -> Option<Vector2F> { |
| 49 | self.child.size() |
| 50 | } |
| 51 | |
| 52 | fn origin(&self) -> Option<Point> { |
| 53 | self.child.origin() |
| 54 | } |
| 55 | } |
| 56 |