-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
6,822 additions
and
6,781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,68 @@ | ||
use bevy::{ | ||
prelude::*, | ||
reflect::TypePath, | ||
render::render_resource::AsBindGroup, | ||
}; | ||
use kayak_ui::{ | ||
prelude::{widgets::*, *}, | ||
CameraUIKayak, | ||
}; | ||
|
||
#[derive(AsBindGroup, Asset, TypePath, Debug, Clone)] | ||
pub struct MyUIMaterial {} | ||
impl MaterialUI for MyUIMaterial { | ||
fn fragment_shader() -> bevy::render::render_resource::ShaderRef { | ||
"rainbow_shader.wgsl".into() | ||
} | ||
} | ||
|
||
fn startup( | ||
mut commands: Commands, | ||
mut font_mapping: ResMut<FontMapping>, | ||
asset_server: Res<AssetServer>, | ||
mut materials: ResMut<Assets<MyUIMaterial>>, | ||
) { | ||
let camera_entity = commands | ||
.spawn(Camera2dBundle::default()) | ||
.insert(CameraUIKayak) | ||
.id(); | ||
|
||
font_mapping.set_default(asset_server.load("roboto.kayak_font")); | ||
|
||
let my_material = MyUIMaterial {}; | ||
let my_material_handle = materials.add(my_material); | ||
|
||
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(), | ||
left: Units::Pixels(20.0).into(), | ||
top: Units::Pixels(5.0).into(), | ||
material: MaterialHandle::new(move |commands, entity| { | ||
commands.entity(entity).insert(my_material_handle.clone_weak()); | ||
}).into(), | ||
..Default::default() | ||
}} | ||
text={TextProps { | ||
content: "Hello Shader!".into(), | ||
size: 20.0, | ||
..Default::default() | ||
}} | ||
/> | ||
</KayakAppBundle> | ||
}; | ||
|
||
commands.spawn((widget_context, EventDispatcher::default())); | ||
} | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
.add_plugins(( | ||
KayakContextPlugin, | ||
KayakWidgets, | ||
MaterialUIPlugin::<MyUIMaterial>::default(), | ||
)) | ||
.add_systems(Startup, startup) | ||
.run() | ||
} | ||
use bevy::{prelude::*, reflect::TypePath, render::render_resource::AsBindGroup}; | ||
use kayak_ui::{ | ||
prelude::{widgets::*, *}, | ||
CameraUIKayak, | ||
}; | ||
|
||
#[derive(AsBindGroup, Asset, TypePath, Debug, Clone)] | ||
pub struct MyUIMaterial {} | ||
impl MaterialUI for MyUIMaterial { | ||
fn fragment_shader() -> bevy::render::render_resource::ShaderRef { | ||
"rainbow_shader.wgsl".into() | ||
} | ||
} | ||
|
||
fn startup( | ||
mut commands: Commands, | ||
mut font_mapping: ResMut<FontMapping>, | ||
asset_server: Res<AssetServer>, | ||
mut materials: ResMut<Assets<MyUIMaterial>>, | ||
) { | ||
let camera_entity = commands | ||
.spawn(Camera2dBundle::default()) | ||
.insert(CameraUIKayak) | ||
.id(); | ||
|
||
font_mapping.set_default(asset_server.load("roboto.kayak_font")); | ||
|
||
let my_material = MyUIMaterial {}; | ||
let my_material_handle = materials.add(my_material); | ||
|
||
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(), | ||
left: Units::Pixels(20.0).into(), | ||
top: Units::Pixels(5.0).into(), | ||
material: MaterialHandle::new(move |commands, entity| { | ||
commands.entity(entity).insert(my_material_handle.clone_weak()); | ||
}).into(), | ||
..Default::default() | ||
}} | ||
text={TextProps { | ||
content: "Hello Shader!".into(), | ||
size: 20.0, | ||
..Default::default() | ||
}} | ||
/> | ||
</KayakAppBundle> | ||
}; | ||
|
||
commands.spawn((widget_context, EventDispatcher::default())); | ||
} | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
.add_plugins(( | ||
KayakContextPlugin, | ||
KayakWidgets, | ||
MaterialUIPlugin::<MyUIMaterial>::default(), | ||
)) | ||
.add_systems(Startup, startup) | ||
.run() | ||
} |
Oops, something went wrong.