Skip to content

Commit

Permalink
Merge pull request #246 from StarArawn/shader-with-opacity
Browse files Browse the repository at this point in the history
Shader with opacity
  • Loading branch information
StarArawn authored Apr 30, 2023
2 parents 48a90ff + fd2bf51 commit 4bc6834
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
20 changes: 2 additions & 18 deletions examples/custom_shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}}
Expand Down
30 changes: 28 additions & 2 deletions examples/modal.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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()
}

0 comments on commit 4bc6834

Please sign in to comment.