Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
crates/strato-ui-core/src/debug/root_view.rs
StratoSDK / crates / strato-ui-core / src / debug / root_view.rs
1use std::collections::HashMap;
2 
3use crate::{
4 elements::ChildView, AppContext, Element, Entity, EntityId, TypedActionView, View, ViewContext,
5 ViewHandle, WindowId,
6};
7 
8use super::view_tree_debug_view::ViewTreeDebugView;
9 
10/// A root view for a window that provides debugging tools for the UI framework.
11pub(crate) struct DebugRootView {
12 child: ViewHandle<ViewTreeDebugView>,
13}
14 
15impl TypedActionView for DebugRootView {
16 type Action = ();
17}
18 
19impl 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 
33impl Entity for DebugRootView {
34 type Event = ();
35}
36 
37impl 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