Skip to content
Snippets Groups Projects
Unverified Commit 7e9d4562 authored by Jacob LeCoq's avatar Jacob LeCoq
Browse files

Fix app not updating if camera width/height changes

parent 54dbd6f0
No related branches found
No related tags found
No related merge requests found
use bevy::prelude::*;
use kayak_ui::prelude::{widgets::*, *};
#[derive(Default, Clone, Copy, PartialEq, Hash, Eq, Debug)]
pub enum GameState {
#[default]
First,
Second,
}
fn first_sys(mut state: ResMut<State<GameState>>) {
state.overwrite_replace(GameState::Second).unwrap();
}
fn second_sys(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut font_mapping: ResMut<FontMapping>,
) {
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let mut widget_context = KayakRootContext::new();
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
rsx! {
<KayakAppBundle>
<TextWidgetBundle
text={TextProps {
content: "Hello World".into(),
size: 20.0,
..Default::default()
}}
/>
</KayakAppBundle>
}
commands.spawn(UICameraBundle::new(widget_context));
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets)
.add_state(GameState::First)
.add_system_set(SystemSet::on_enter(GameState::First).with_system(first_sys))
.add_system_set(SystemSet::on_enter(GameState::Second).with_system(second_sys))
.run()
}
......@@ -41,18 +41,22 @@ impl Default for KayakAppBundle {
pub fn app_update(
In((widget_context, entity, previous_props_entity)): In<(KayakWidgetContext, Entity, Entity)>,
windows: Res<Windows>,
widget_param: WidgetParam<KayakApp, EmptyState>,
camera: Query<&Camera, With<CameraUIKayak>>,
) -> bool {
let primary_window = windows.get_primary().unwrap();
let mut window_change = false;
if let Ok(app_style) = widget_param.style_query.get(entity) {
if app_style.width != StyleProp::Value(Units::Pixels(primary_window.width())) {
window_change = true;
}
if app_style.height != StyleProp::Value(Units::Pixels(primary_window.height())) {
window_change = true;
if let Some(camera_entity) = widget_context.camera_entity {
if let Ok(camera) = camera.get(camera_entity) {
if let Some(size) = camera.logical_viewport_size() {
if app_style.width != StyleProp::Value(Units::Pixels(size.x)) {
window_change = true;
}
if app_style.height != StyleProp::Value(Units::Pixels(size.y)) {
window_change = true;
}
}
}
}
}
......
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