Skip to content
Snippets Groups Projects
Commit 329213aa authored by John Mitchell's avatar John Mitchell
Browse files

Make sure shaders with opacity.

parent f69ff657
No related branches found
No related tags found
No related merge requests found
...@@ -28,40 +28,24 @@ fn startup( ...@@ -28,40 +28,24 @@ fn startup(
let my_material = MyUIMaterial {}; let my_material = MyUIMaterial {};
let my_material_handle = materials.add(my_material); 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); let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin); widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None; let parent_id = None;
rsx! { rsx! {
<KayakAppBundle> <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 <TextWidgetBundle
styles={KStyle { styles={KStyle {
position_type: KPositionType::SelfDirected.into(), position_type: KPositionType::SelfDirected.into(),
left: Units::Pixels(20.0).into(), left: Units::Pixels(20.0).into(),
top: Units::Pixels(5.0).into(), top: Units::Pixels(5.0).into(),
material: MaterialHandle::new(move |commands, entity| { 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(), }).into(),
..Default::default() ..Default::default()
}} }}
text={TextProps { text={TextProps {
content: "Hello World!".into(), content: "Hello Shader!".into(),
size: 20.0, size: 20.0,
..Default::default() ..Default::default()
}} }}
......
use bevy::prelude::*; use bevy::{prelude::*, reflect::TypeUuid, render::render_resource::AsBindGroup};
use kayak_ui::prelude::{widgets::*, *}; 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)] #[derive(Component, Default, PartialEq, Clone)]
struct MyWidget; struct MyWidget;
...@@ -33,9 +42,12 @@ fn my_widget_render( ...@@ -33,9 +42,12 @@ fn my_widget_render(
widget_context: Res<KayakWidgetContext>, widget_context: Res<KayakWidgetContext>,
mut commands: Commands, mut commands: Commands,
query: Query<&MyWidgetState>, query: Query<&MyWidgetState>,
mut materials: ResMut<Assets<MyUIMaterial>>,
) -> bool { ) -> bool {
let state_entity = widget_context.use_state(&mut commands, entity, MyWidgetState::default()); let state_entity = widget_context.use_state(&mut commands, entity, MyWidgetState::default());
if let Ok(state) = query.get(state_entity) { 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); let parent_id = Some(entity);
rsx! { rsx! {
<ElementBundle> <ElementBundle>
...@@ -76,8 +88,21 @@ fn my_widget_render( ...@@ -76,8 +88,21 @@ fn my_widget_render(
..Default::default() ..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 <KButtonBundle
button={KButton { text: "Hide Window".into() }} button={KButton { text: "Hide Modal".into() }}
on_event={OnEvent::new( on_event={OnEvent::new(
move |In(_entity): In<Entity>, move |In(_entity): In<Entity>,
mut event: ResMut<KEvent>, mut event: ResMut<KEvent>,
...@@ -135,6 +160,7 @@ fn main() { ...@@ -135,6 +160,7 @@ fn main() {
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
.add_plugin(MaterialUIPlugin::<MyUIMaterial>::default())
.add_startup_system(startup) .add_startup_system(startup)
.run() .run()
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment