diff --git a/examples/custom_shader.rs b/examples/custom_shader.rs index c2f68a924512ca5417f68dcd2c5bf8bd780ab768..288c09d0710b9a663720a560122eef630202f27b 100644 --- a/examples/custom_shader.rs +++ b/examples/custom_shader.rs @@ -28,40 +28,24 @@ fn startup( let my_material = MyUIMaterial {}; let my_material_handle = materials.add(my_material); - let my_material_handle1 = my_material_handle.clone(); - let my_material_handle2 = my_material_handle.clone(); let mut widget_context = KayakRootContext::new(camera_entity); widget_context.add_plugin(KayakWidgetsContextPlugin); let parent_id = None; rsx! { <KayakAppBundle> - <TextWidgetBundle - styles={KStyle { - position_type: KPositionType::SelfDirected.into(), - material: MaterialHandle::new(move |commands, entity| { - commands.entity(entity).insert(my_material_handle1.clone_weak()); - }).into(), - ..Default::default() - }} - text={TextProps { - content: "Hello Shader!".into(), - size: 20.0, - ..Default::default() - }} - /> <TextWidgetBundle styles={KStyle { position_type: KPositionType::SelfDirected.into(), left: Units::Pixels(20.0).into(), top: Units::Pixels(5.0).into(), material: MaterialHandle::new(move |commands, entity| { - commands.entity(entity).insert(my_material_handle2.clone_weak()); + commands.entity(entity).insert(my_material_handle.clone_weak()); }).into(), ..Default::default() }} text={TextProps { - content: "Hello World!".into(), + content: "Hello Shader!".into(), size: 20.0, ..Default::default() }} diff --git a/examples/modal.rs b/examples/modal.rs index 877e2bfb94bb12779d32f7e916f9013d094af0c5..5d621de0886176e5fa1a7d2ff6debe9f7217d1fa 100644 --- a/examples/modal.rs +++ b/examples/modal.rs @@ -1,6 +1,15 @@ -use bevy::prelude::*; +use bevy::{prelude::*, reflect::TypeUuid, render::render_resource::AsBindGroup}; use kayak_ui::prelude::{widgets::*, *}; +#[derive(AsBindGroup, TypeUuid, Debug, Clone)] +#[uuid = "94c4e6f9-6f10-422c-85ec-6d582d471afc"] +pub struct MyUIMaterial {} +impl MaterialUI for MyUIMaterial { + fn fragment_shader() -> bevy::render::render_resource::ShaderRef { + "rainbow_shader.wgsl".into() + } +} + #[derive(Component, Default, PartialEq, Clone)] struct MyWidget; @@ -33,9 +42,12 @@ fn my_widget_render( widget_context: Res<KayakWidgetContext>, mut commands: Commands, query: Query<&MyWidgetState>, + mut materials: ResMut<Assets<MyUIMaterial>>, ) -> bool { let state_entity = widget_context.use_state(&mut commands, entity, MyWidgetState::default()); if let Ok(state) = query.get(state_entity) { + let my_material = MyUIMaterial {}; + let my_material_handle = materials.add(my_material); let parent_id = Some(entity); rsx! { <ElementBundle> @@ -76,8 +88,21 @@ fn my_widget_render( ..Default::default() }} > + <TextWidgetBundle + styles={KStyle { + material: MaterialHandle::new(move |commands, entity| { + commands.entity(entity).insert(my_material_handle.clone_weak()); + }).into(), + ..Default::default() + }} + text={TextProps { + content: "Hello Modal!".into(), + size: 20.0, + ..Default::default() + }} + /> <KButtonBundle - button={KButton { text: "Hide Window".into() }} + button={KButton { text: "Hide Modal".into() }} on_event={OnEvent::new( move |In(_entity): In<Entity>, mut event: ResMut<KEvent>, @@ -135,6 +160,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(KayakContextPlugin) .add_plugin(KayakWidgets) + .add_plugin(MaterialUIPlugin::<MyUIMaterial>::default()) .add_startup_system(startup) .run() }