Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader with opacity #246

Merged
merged 2 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}