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

Fixed examples to work with new context.

parent e9a55fc0
No related branches found
No related tags found
No related merge requests found
Showing
with 146 additions and 94 deletions
......@@ -19,7 +19,7 @@ fn startup(
) {
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
let parent_id = None;
// The rsx! macro expects a parent_id, a widget_context from the user.
......@@ -37,7 +37,7 @@ fn startup(
</KayakAppBundle>
}
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......@@ -63,9 +63,13 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
commands.spawn(UICameraBundle::new());
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
let app_entity = widget_context.spawn_widget(&mut commands, None);
// Create default app bundle
......@@ -95,9 +99,8 @@ fn startup(
// Add app widget to context.
widget_context.add_widget(None, app_entity);
// Add widget context as resource.
commands.spawn(UICameraBundle::new(widget_context));
// Spawn context as an entity.
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
App::new()
......
......@@ -115,7 +115,6 @@ fn on_color_change(
/// A system that sets up the world
fn world_setup(mut commands: Commands, active_color: Res<ActiveColor>) {
commands.spawn((Camera2dBundle::default(), WorldCamera));
commands
.spawn(SpriteBundle {
sprite: Sprite {
......@@ -172,9 +171,15 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
// The UI Camera and the world camera are the same.
// CameraUIKayak is used to tell kayak which camera should render UI.
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak, WorldCamera))
.id();
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let handle_change_color = OnEvent::new(
......@@ -255,7 +260,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn((UICameraBundle::new(widget_context), GameUI));
commands.spawn((widget_context, EventDispatcher::default(), GameUI));
}
fn main() {
......
......@@ -6,11 +6,15 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
font_mapping.set_default(asset_server.load("lato-light.kttf"));
let image = asset_server.load("panel.png");
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
......@@ -56,7 +60,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sed tellus neque.
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -109,13 +109,13 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
font_mapping.set_default(asset_server.load("lato-light.kttf"));
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
// Camera 2D forces a clear pass in bevy.
// We do this because our scene is not rendering anything else.
commands.spawn(Camera2dBundle::default());
font_mapping.set_default(asset_server.load("lato-light.kttf"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
widget_context.add_widget_data::<MyWidget, MyWidgetState>();
......@@ -130,7 +130,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -325,13 +325,13 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
// Camera 2D forces a clear pass in bevy.
// We do this because our scene is not rendering anything else.
commands.spawn(Camera2dBundle::default());
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
widget_context.add_widget_data::<ThemeDemo, EmptyState>();
widget_context.add_widget_data::<ThemeButton, EmptyState>();
......@@ -377,7 +377,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -21,7 +21,11 @@ fn my_widget_1_render(
impl Widget for MyWidget {}
fn startup(mut commands: Commands) {
let mut context = KayakRootContext::new();
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
let mut context = KayakRootContext::new(camera_entity);
context.add_plugin(KayakWidgetsContextPlugin);
context.add_widget_system(
MyWidget::default().get_name(),
......@@ -47,7 +51,7 @@ fn startup(mut commands: Commands) {
});
context.add_widget(None, app_entity);
commands.spawn(UICameraBundle::new(context));
commands.spawn((context, EventDispatcher::default()));
}
// Note this example shows prop changing not state changing which is quite different.
......
use bevy::prelude::*;
use kayak_ui::prelude::{widgets::*, *};
use kayak_ui::{
prelude::{widgets::*, *},
CameraUIKayak,
};
fn startup(
mut commands: Commands,
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
let camera_entity = commands
.spawn(Camera2dBundle::default())
.insert(CameraUIKayak)
.id();
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
// font_mapping.force_subpixel(&asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
rsx! {
......@@ -23,7 +32,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -5,8 +5,13 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
let camera_entity = commands
.spawn(Camera2dBundle::default())
.insert(CameraUIKayak)
.id();
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let app_entity = widget_context.spawn_widget(&mut commands, None);
......@@ -39,7 +44,7 @@ fn startup(
// Add widget context as resource.
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
App::new()
......
......@@ -6,11 +6,15 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let image = asset_server.load("generic-rpg-vendor.png");
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
rsx! {
......@@ -30,7 +34,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -6,13 +6,13 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
// Camera 2D forces a clear pass in bevy.
// We do this because our scene is not rendering anything else.
commands.spawn(Camera2dBundle::default());
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
......@@ -130,7 +130,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -123,9 +123,13 @@ fn startup(
asset_server: Res<AssetServer>,
mut preload_resource: ResMut<PreloadResource>,
) {
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
font_mapping.set_default(asset_server.load("lato-light.kttf"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
widget_context.add_widget_data::<MenuButton, ButtonState>();
widget_context.add_widget_system(
......@@ -218,7 +222,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -6,11 +6,15 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let image = asset_server.load("panel.png");
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
......@@ -51,7 +55,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -94,13 +94,13 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
// Camera 2D forces a clear pass in bevy.
// We do this because our scene is not rendering anything else.
commands.spawn(Camera2dBundle::default());
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
widget_context.add_widget_system(
MyQuad::default().get_name(),
......@@ -134,7 +134,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -56,7 +56,22 @@ fn startup(
let image_handle = images.add(image);
let mut widget_context = KayakRootContext::new();
let camera_entity = commands
.spawn(Camera2dBundle {
camera: Camera {
priority: -1,
target: RenderTarget::Image(image_handle.clone()),
..Camera::default()
},
camera_2d: Camera2d {
clear_color: bevy::core_pipeline::clear_color::ClearColorConfig::Default,
},
..Default::default()
})
.insert(CameraUIKayak)
.id();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
rsx! {
......@@ -81,18 +96,7 @@ fn startup(
/>
</KayakAppBundle>
};
commands.spawn(UICameraBundle {
camera: Camera {
priority: -1,
target: RenderTarget::Image(image_handle.clone()),
..Camera::default()
},
camera_ui: CameraUIKayak {
clear_color: bevy::core_pipeline::clear_color::ClearColorConfig::Default,
},
..UICameraBundle::new(widget_context)
});
commands.spawn((widget_context, EventDispatcher::default()));
// Setup 3D scene
// Light
......@@ -127,14 +131,17 @@ fn startup(
.insert(MainPassCube);
// The main pass camera.
commands.spawn(Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
.looking_at(Vec3::default(), Vec3::Y),
..default()
});
let camera_entity = commands
.spawn(Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
.looking_at(Vec3::default(), Vec3::Y),
..default()
})
.insert(CameraUIKayak)
.id();
// Spawn another UI in 2D space!
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
rsx! {
......@@ -148,7 +155,7 @@ fn startup(
/>
</KayakAppBundle>
};
commands.spawn((UICameraBundle::new(widget_context), MainUI));
commands.spawn((widget_context, EventDispatcher::default(), MainUI));
}
/// Rotates the outer cube (main pass)
......
......@@ -6,6 +6,10 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
let font_asset = asset_server.load("roboto.kayak_font");
font_mapping.set_default(font_asset.clone());
......@@ -14,11 +18,7 @@ fn startup(
// will be ignored if this setting is used.
font_mapping.force_subpixel(&font_asset);
// Camera 2D forces a clear pass in bevy.
// We do this because our scene is not rendering anything else.
commands.spawn(Camera2dBundle::default());
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
......@@ -60,7 +60,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sed tellus neque.
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -85,13 +85,13 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
font_mapping.set_default(asset_server.load("lato-light.kttf"));
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
// Camera 2D forces a clear pass in bevy.
// We do this because our scene is not rendering anything else.
commands.spawn(Camera2dBundle::default());
font_mapping.set_default(asset_server.load("lato-light.kttf"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
widget_context.add_widget_data::<CurrentCount, CurrentCountState>();
......@@ -129,7 +129,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -15,13 +15,13 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
// Camera 2D forces a clear pass in bevy.
// We do this because our scene is not rendering anything else.
commands.spawn(Camera2dBundle::default());
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
widget_context.add_widget_data::<Tab, EmptyState>();
widget_context.add_widget_data::<TabContextProvider, EmptyState>();
......@@ -87,7 +87,7 @@ fn startup(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -17,9 +17,13 @@ fn second_sys(
asset_server: Res<AssetServer>,
mut font_mapping: ResMut<FontMapping>,
) {
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
rsx! {
......@@ -34,7 +38,7 @@ fn second_sys(
</KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
......
......@@ -73,13 +73,13 @@ fn startup(
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
// Camera 2D forces a clear pass in bevy.
// We do this because our scene is not rendering anything else.
commands.spawn(Camera2dBundle::default());
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
widget_context.add_widget_data::<MyWidgetProps, EmptyState>();
......@@ -92,7 +92,7 @@ fn startup(
<KayakAppBundle><MyWidgetBundle props={MyWidgetProps { foo: 0 }} /></KayakAppBundle>
};
commands.spawn(UICameraBundle::new(widget_context));
commands.spawn((widget_context, EventDispatcher::default()));
}
fn update_resource(keyboard_input: Res<Input<KeyCode>>, mut my_resource: ResMut<MyResource>) {
......
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