StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use std::collections::HashMap; |
| 2 | |
| 3 | use crate::{ |
| 4 | elements::ChildView, AppContext, Element, Entity, EntityId, TypedActionView, View, ViewContext, |
| 5 | ViewHandle, WindowId, |
| 6 | }; |
| 7 | |
| 8 | use super::view_tree_debug_view::ViewTreeDebugView; |
| 9 | |
| 10 | /// A root view for a window that provides debugging tools for the UI framework. |
| 11 | pub(crate) struct DebugRootView { |
| 12 | child: ViewHandle<ViewTreeDebugView>, |
| 13 | } |
| 14 | |
| 15 | impl TypedActionView for DebugRootView { |
| 16 | type Action = (); |
| 17 | } |
| 18 | |
| 19 | impl DebugRootView { |
| 20 | pub fn new( |
| 21 | target_window_id: WindowId, |
| 22 | view_parent_map: HashMap<EntityId, EntityId>, |
| 23 | root_view_id: EntityId, |
| 24 | ctx: &mut ViewContext<Self>, |
| 25 | ) -> Self { |
| 26 | let child = ctx.add_typed_action_view(|ctx| { |
| 27 | ViewTreeDebugView::new(target_window_id, view_parent_map, root_view_id, ctx) |
| 28 | }); |
| 29 | Self { child } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | impl Entity for DebugRootView { |
| 34 | type Event = (); |
| 35 | } |
| 36 | |
| 37 | impl View for DebugRootView { |
| 38 | fn ui_name() -> &'static str { |
| 39 | "DebugRootView" |
| 40 | } |
| 41 | |
| 42 | fn render(&self, _app: &AppContext) -> Box<dyn Element> { |
| 43 | ChildView::new(&self.child).finish() |
| 44 | } |
| 45 | } |
| 46 |