Skip to content

Commit

Permalink
Migrate to bevy 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
NiseVoid committed Mar 8, 2024
1 parent 88dd319 commit 8bd598e
Show file tree
Hide file tree
Showing 28 changed files with 146 additions and 134 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ svg = [] #["dep:bevy_svg"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.12", default-features = false, features = ["bevy_render", "bevy_asset", "bevy_winit", "bevy_core_pipeline"] }
bevy = { version = "0.13", default-features = false, features = ["bevy_render", "bevy_asset", "bevy_core_pipeline"] }
# bevy_svg = { version="0.12", default-features = false, optional = true }
bitflags = "1.3.2"
bytemuck = "1.12"
Expand All @@ -36,11 +36,12 @@ reorder = "2.1"
resources = "1.1"
usvg = "0.27"
uuid = { version = "1.3", features = ["v4"] }
smol_str = {version = "0.2", default-features = false}

[dev-dependencies]
fastrand = "1.8"
bevy-inspector-egui = "0.21"
bevy = { version = "0.12", default-features = true }
bevy-inspector-egui = "0.23"
bevy = { version = "0.13", default-features = true }

[[example]]
name = "tabs"
Expand Down
5 changes: 4 additions & 1 deletion examples/avsb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ fn startup(
commands.spawn((widget_context, EventDispatcher::default()));
}

fn swap(input: Res<Input<KeyCode>>, mut query: Query<&mut AvsBState, Without<PreviousWidget>>) {
fn swap(
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut AvsBState, Without<PreviousWidget>>,
) {
if input.just_pressed(KeyCode::Space) {
for mut avsb in query.iter_mut() {
avsb.is_a = !avsb.is_a;
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct WorldCamera;
/// to filter out clicks that occur over the UI
fn set_active_tile_target(
mut tile: Query<&mut ActiveTile>,
cursor: Res<Input<MouseButton>>,
cursor: Res<ButtonInput<MouseButton>>,
event_context: Query<&EventDispatcher, With<GameUI>>,
camera_transform: Query<&GlobalTransform, With<WorldCamera>>,
window: Query<&Window, With<PrimaryWindow>>,
Expand Down
2 changes: 1 addition & 1 deletion examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn startup(mut commands: Commands) {
// Note this example shows prop changing not state changing which is quite different.
// For state changes please see simple_state example.
fn update_resource(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut MyWidget, Without<PreviousWidget>>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
Expand Down
2 changes: 1 addition & 1 deletion examples/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Default for MenuButtonBundle {
button: Default::default(),
styles: KStyle {
bottom: Units::Pixels(20.0).into(),
cursor: KCursorIcon(CursorIcon::Hand).into(),
cursor: KCursorIcon(CursorIcon::Pointer).into(),
..Default::default()
},
on_event: OnEvent::default(),
Expand Down
9 changes: 4 additions & 5 deletions examples/render_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ fn startup(
camera: Camera {
order: -1,
target: RenderTarget::Image(image_handle.clone()),
clear_color: ClearColorConfig::None,
..Camera::default()
},
camera_2d: Camera2d {
clear_color: bevy::core_pipeline::clear_color::ClearColorConfig::Default,
},
camera_2d: Camera2d,
..Default::default()
})
.insert(CameraUIKayak)
Expand Down Expand Up @@ -107,7 +106,7 @@ fn startup(
});

let cube_size = 4.0;
let cube_handle = meshes.add(Mesh::from(shape::Box::new(cube_size, cube_size, cube_size)));
let cube_handle = meshes.add(Mesh::from(Cuboid::from_size(Vec3::splat(cube_size))));

// This material has the texture that has been rendered.
let material_handle = materials.add(StandardMaterial {
Expand Down Expand Up @@ -169,7 +168,7 @@ fn cube_rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<Ma

fn depsawn_ui(
mut commands: Commands,
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
ui_query: Query<(Entity, &KayakRootContext), With<MainUI>>,
) {
if keyboard_input.pressed(KeyCode::Escape) {
Expand Down
2 changes: 1 addition & 1 deletion examples/test_no_startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins((KayakContextPlugin, KayakWidgets))
.add_state::<GameState>()
.init_state::<GameState>()
.add_systems(OnEnter(GameState::First), first_sys)
.add_systems(OnEnter(GameState::Second), second_sys)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn startup(
commands.spawn((widget_context, EventDispatcher::default()));
}

fn update_resource(keyboard_input: Res<Input<KeyCode>>, mut my_resource: ResMut<MyResource>) {
fn update_resource(keyboard_input: Res<ButtonInput<KeyCode>>, mut my_resource: ResMut<MyResource>) {
if keyboard_input.just_pressed(KeyCode::Space) {
my_resource.0 += 1;
}
Expand Down
3 changes: 1 addition & 2 deletions examples/texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ fn startup(
let tile_size = 16;
let columns = 272 / tile_size;
let rows = 128 / tile_size;
let atlas = bevy::sprite::TextureAtlas::from_grid(
image_handle.clone(),
let atlas = bevy::sprite::TextureAtlasLayout::from_grid(
bevy::prelude::Vec2::splat(tile_size as f32),
columns,
rows,
Expand Down
4 changes: 2 additions & 2 deletions kayak_font/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ image = "0.24"
# Provides UAX #14 line break segmentation
xi-unicode = "0.3"

bevy = { version = "0.12", optional = true, default-features = false, features = ["bevy_asset", "bevy_render", "bevy_core_pipeline"] }
bevy = { version = "0.13", optional = true, default-features = false, features = ["bevy_asset", "bevy_render", "bevy_core_pipeline"] }

[dev-dependencies]
bevy = { version = "0.12" }
bevy = { version = "0.13", default-features = false }
bytemuck = "1.12.0"

[package.metadata.docs.rs]
Expand Down
1 change: 1 addition & 0 deletions kayak_font/src/bevy/renderer/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(crate) fn extract_fonts(
let id = asset_server.get_id_handle(*id).unwrap();
changed_assets.insert(id.clone_weak());
}
AssetEvent::Unused { id: _ } => {}
}
}

Expand Down
6 changes: 5 additions & 1 deletion kayak_font/src/ttf/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use bevy::{
io::{AssetSourceBuilders, Reader},
AssetLoader, AssetServer, AsyncReadExt, LoadContext,
},
render::render_resource::{Extent3d, TextureFormat},
render::{
render_asset::RenderAssetUsages,
render_resource::{Extent3d, TextureFormat},
},
utils::{BoxedFuture, HashMap},
};

Expand Down Expand Up @@ -263,6 +266,7 @@ impl AssetLoader for TTFLoader {
bevy::render::render_resource::TextureDimension::D2,
image_bytes,
TextureFormat::Rgba8Unorm,
RenderAssetUsages::all(),
);
image.reinterpret_stacked_2d_as_array(char_count);
let labeled_asset = load_context.begin_labeled_asset();
Expand Down
6 changes: 3 additions & 3 deletions src/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use bevy::{
#[derive(Component, Default, Debug, Clone, Copy)]
pub struct CameraUIKayak;
impl ExtractComponent for CameraUIKayak {
type Query = &'static Self;
type Filter = With<Camera>;
type QueryData = &'static Self;
type QueryFilter = With<Camera>;
type Out = CameraUIKayak;

fn extract_component(item: QueryItem<Self::Query>) -> Option<Self::Out> {
fn extract_component(item: QueryItem<Self::QueryData>) -> Option<Self::Out> {
Some(*item)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ impl KEvent {
Self {
target,
current_target: target,
event_type,
should_propagate: event_type.propagates(),
event_type,
default_prevented: false,
on_change_systems: Vec::new(),
}
Expand Down Expand Up @@ -108,7 +108,7 @@ impl KEvent {
/// __Note:__ This type implements `PartialEq` and `Hash` in a way that only considers the variant itself,
/// not the underlying data. If full comparisons are needed, they should be done with the inner data or
/// with a custom wrapper.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone)]
pub enum EventType {
/// An event that occurs when the user clicks a widget
Click(CursorEvent),
Expand All @@ -129,7 +129,7 @@ pub enum EventType {
/// An event that occurs when a widget loses focus
Blur,
/// An event that occurs when the user types in a character within a _focused_ widget
CharInput { c: char },
CharInput { c: smol_str::SmolStr },
/// An event that occurs when the user releases a key within a _focused_ widget
KeyUp(KeyboardEvent),
/// An event that occurs when the user presses a key down within a _focused_ widget
Expand Down
11 changes: 6 additions & 5 deletions src/event_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl EventDispatcher {
};

// --- Update State --- //
Self::insert_event(&mut next_events, &index, node_event.event_type);
Self::insert_event(&mut next_events, &index, node_event.event_type.clone());

// --- Call Event --- //
if let Some(mut entity) = world.get_entity_mut(index.0) {
Expand Down Expand Up @@ -450,7 +450,7 @@ impl EventDispatcher {
// These events are ones that require a specific target and need the tree to be evaluated before selecting the best match
for (event_type, state) in states {
if let Some(node) = state.best_match {
event_stream.push(KEvent::new(node.0, event_type));
event_stream.push(KEvent::new(node.0, event_type.clone()));

match event_type {
EventType::Focus => {
Expand Down Expand Up @@ -692,9 +692,10 @@ impl EventDispatcher {
let mut event_stream = Vec::new();
if let Some(current_focus) = focus_tree.current() {
match input_event {
InputEvent::CharEvent { c } => {
event_stream.push(KEvent::new(current_focus, EventType::CharInput { c: *c }))
}
InputEvent::CharEvent { c } => event_stream.push(KEvent::new(
current_focus,
EventType::CharInput { c: c.clone() },
)),
InputEvent::Keyboard { key, is_pressed } => {
// === Modifers === //
match key {
Expand Down
14 changes: 7 additions & 7 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ pub(crate) fn process_events(world: &mut World) {
}

for event in custom_event_char_input.0.read(&char_input_events) {
input_events.push(InputEvent::CharEvent { c: event.char });
input_events.push(InputEvent::CharEvent {
c: event.char.clone(),
});
}

for event in custom_event_keyboard.0.read(&keyboard_input_events) {
if let Some(key_code) = event.key_code {
input_events.push(InputEvent::Keyboard {
key: key_code,
is_pressed: matches!(event.state, ButtonState::Pressed),
});
}
input_events.push(InputEvent::Keyboard {
key: event.key_code,
is_pressed: matches!(event.state, ButtonState::Pressed),
});
}
},
world,
Expand Down
2 changes: 1 addition & 1 deletion src/input_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum InputEvent {
/// An event that occurs when the user scrolls
Scroll { dx: f32, dy: f32, is_line: bool },
/// An event that occurs when the user types in a character
CharEvent { c: char },
CharEvent { c: smol_str::SmolStr },
/// An event that occurs when the user presses or releases a key
Keyboard { key: KeyCode, is_pressed: bool },
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub mod prelude {
pub use crate::on_change::OnChange;
pub use crate::on_event::OnEvent;
pub use crate::on_layout::OnLayout;
pub use crate::render::draw_ui_graph;
pub use crate::render::font::FontMapping;
pub use crate::render::{DrawUiGraph, KayakUiPass};
pub use crate::styles::*;
pub use crate::tree::*;
pub use crate::widget::*;
Expand Down
2 changes: 1 addition & 1 deletion src/render/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub fn prepare_view_uniforms(
let frustum = [Vec4::ZERO; 6];

let view_uniforms = UIViewUniformOffset {
offset: view_uniforms.uniforms.push(UIViewUniform {
offset: view_uniforms.uniforms.push(&UIViewUniform {
view_proj: camera
.view_projection
.unwrap_or_else(|| projection * inverse_view),
Expand Down
10 changes: 7 additions & 3 deletions src/render/material/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub fn extract_materials_ui<M: MaterialUI>(
changed_assets.remove(id);
removed.push(*id);
}
AssetEvent::Unused { id: _ } => {}
}
}

Expand Down Expand Up @@ -286,17 +287,20 @@ pub type DrawMaterialUITransparent<M> = (
pub struct SetMaterialBindGroup<M: MaterialUI, const I: usize>(PhantomData<M>);
impl<P: PhaseItem, M: MaterialUI, const I: usize> RenderCommand<P> for SetMaterialBindGroup<M, I> {
type Param = SRes<RenderMaterialsUI<M>>;
type ViewWorldQuery = ();
type ItemWorldQuery = Read<Handle<M>>;
type ViewQuery = ();
type ItemQuery = Read<Handle<M>>;

#[inline]
fn render<'w>(
_item: &P,
_view: (),
material2d_handle: ROQueryItem<'_, Self::ItemWorldQuery>,
material2d_handle: Option<ROQueryItem<'_, Self::ItemQuery>>,
materials: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let Some(material2d_handle) = material2d_handle else {
return RenderCommandResult::Failure;
};
let asset_id: AssetId<M> = material2d_handle.clone_weak().into();
let material2d = materials.into_inner().get(&asset_id).unwrap();
pass.set_bind_group(I, &material2d.bind_group, &[]);
Expand Down
Loading

0 comments on commit 8bd598e

Please sign in to comment.