oxygengine_user_interface/
lib.rs1extern crate oxygengine_core as core;
2extern crate oxygengine_input as input;
3
4pub mod component;
5pub mod resource;
6pub mod system;
7pub mod ui_theme_asset_protocol;
8
9pub use raui_core::{
11 post_hooks, pre_hooks,
12 prelude::{MessageData, Prefab, PropsData},
13 unpack_named_slots, widget,
14};
15
16pub mod prelude {
17 pub use crate::{component::*, resource::*, system::*, ui_theme_asset_protocol::*};
18}
19pub mod raui {
20 pub mod core {
21 pub use raui_core::*;
22 }
23 pub mod material {
24 pub use raui_material::*;
25 }
26}
27
28use crate::{
29 component::UserInterfaceView,
30 raui::core::application::ProcessContext,
31 resource::UserInterface,
32 system::{user_interface_system, UserInterfaceSystemCache, UserInterfaceSystemResources},
33};
34use core::{
35 app::AppBuilder,
36 assets::database::AssetsDatabase,
37 ecs::{
38 pipeline::{PipelineBuilder, PipelineBuilderError},
39 AccessType, ResQuery, ResQueryItem, ResRead, ResWrite,
40 },
41 prefab::PrefabManager,
42};
43
44pub fn bundle_installer<PB, Q>(
45 builder: &mut AppBuilder<PB>,
46 user_interface: UserInterface,
47) -> Result<(), PipelineBuilderError>
48where
49 PB: PipelineBuilder,
50 Q: AccessType + ResQuery + 'static,
51 ResQueryItem<Q>: FeedProcessContext,
52{
53 builder.install_resource(user_interface);
54 builder.install_resource(UserInterfaceSystemCache::default());
55 builder.install_system::<UserInterfaceSystemResources<Q>>(
56 "user-interface",
57 user_interface_system::<Q>,
58 &[],
59 )?;
60 Ok(())
61}
62
63pub fn prefabs_installer(prefabs: &mut PrefabManager) {
64 prefabs.register_component_factory::<UserInterfaceView>("UserInterfaceView");
65}
66
67pub fn protocols_installer(database: &mut AssetsDatabase) {
68 database.register(ui_theme_asset_protocol::UiThemeAssetProtocol);
69}
70
71pub trait FeedProcessContext
72where
73 Self: Sized,
74{
75 fn feed_process_context(self, _context: &mut ProcessContext) {}
76}
77
78impl FeedProcessContext for () {}
79
80impl<T> FeedProcessContext for ResRead<T>
81where
82 T: 'static,
83{
84 fn feed_process_context(self, context: &mut ProcessContext) {
85 context.insert_owned(self);
86 }
87}
88
89impl<T> FeedProcessContext for ResWrite<T>
90where
91 T: 'static,
92{
93 fn feed_process_context(self, context: &mut ProcessContext) {
94 context.insert_owned(self);
95 }
96}
97
98impl<T> FeedProcessContext for Option<ResRead<T>>
99where
100 T: 'static,
101{
102 fn feed_process_context(self, context: &mut ProcessContext) {
103 if let Some(resource) = self {
104 context.insert_owned(resource);
105 }
106 }
107}
108
109impl<T> FeedProcessContext for Option<ResWrite<T>>
110where
111 T: 'static,
112{
113 fn feed_process_context(self, context: &mut ProcessContext) {
114 if let Some(resource) = self {
115 context.insert_owned(resource);
116 }
117 }
118}
119
120macro_rules! impl_feed_process_context {
121 ( $( $ty:ident ),+ ) => {
122 impl<$( $ty ),+> FeedProcessContext for ( $( $ty, )+ ) where $( $ty: FeedProcessContext ),+ {
123 fn feed_process_context(self, context: &mut ProcessContext) {
124 #[allow(non_snake_case)]
125 let ( $( $ty, )+ ) = self;
126 $( $ty.feed_process_context(context) );+
127 }
128 }
129 }
130}
131
132impl_feed_process_context!(A);
133impl_feed_process_context!(A, B);
134impl_feed_process_context!(A, B, C);
135impl_feed_process_context!(A, B, C, D);
136impl_feed_process_context!(A, B, C, D, E);
137impl_feed_process_context!(A, B, C, D, E, F);
138impl_feed_process_context!(A, B, C, D, E, F, G);
139impl_feed_process_context!(A, B, C, D, E, F, G, H);
140impl_feed_process_context!(A, B, C, D, E, F, G, H, I);
141impl_feed_process_context!(A, B, C, D, E, F, G, H, I, J);
142impl_feed_process_context!(A, B, C, D, E, F, G, H, I, J, K);
143impl_feed_process_context!(A, B, C, D, E, F, G, H, I, J, K, L);
144impl_feed_process_context!(A, B, C, D, E, F, G, H, I, J, K, L, M);
145impl_feed_process_context!(A, B, C, D, E, F, G, H, I, J, K, L, M, N);
146impl_feed_process_context!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O);