From 4cf544de417923ea097b975b4a4e87aa5c0da287 Mon Sep 17 00:00:00 2001 From: ycysdf Date: Mon, 19 Feb 2024 23:50:56 +0800 Subject: [PATCH 1/4] dev: bevy 0.13 --- Cargo.toml | 36 +++++++++---------- README-zh-Hans.md | 2 +- README.md | 2 +- crates/rxy_bevy/src/event.rs | 12 +++---- crates/rxy_bevy/src/navigation/mod.rs | 20 +++++------ crates/rxy_bevy/src/renderer/attrs.rs | 4 +-- .../rxy_bevy/src/renderer/style/attr_iter.rs | 8 ++--- .../src/renderer/style/interaction_style.rs | 5 ++- .../rxy_bevy/src/renderer/tailwind_attrs.rs | 8 ++--- crates/rxy_bevy/src/view_member/event.rs | 4 +-- crates/rxy_core/src/renderers/bevy.rs | 2 +- crates/xy_reactive/Cargo.toml | 2 +- 12 files changed, 52 insertions(+), 53 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fca865d..ea29957 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ xy_reactive = { path = "crates/xy_reactive", default-features = false } rxy_web_dom = { path = "crates/rxy_web_dom", default-features = false } async-channel = { version = "2.1" } -glam = "0.24" +glam = "0.25" hashbrown = "0.14" indexmap = "2.1" once_cell = { version = "1.19", default-features = false } @@ -68,22 +68,22 @@ thiserror = "1.0" smallvec = "1.13" slotmap = "1" -bevy_app = "0.12" -bevy_asset = { version = "0.12", optional = false } -bevy_core = "0.12" -bevy_derive = "0.12" -bevy_ecs = "0.12" -bevy_hierarchy = "0.12" -bevy_reflect = { version = "0.12" } -bevy_render = "0.12" -bevy_sprite = "0.12" -bevy_tasks = { version = "0.12", features = ["multi-threaded"], optional = false } -bevy_text = { version = "0.12", optional = false } -bevy_transform = { version = "0.12", optional = false } -bevy_ui = { version = "0.12", features = ["bevy_text"] } -bevy_utils = "0.12" -bevy_a11y = "0.12" -bevy_input = "0.12" +bevy_app = "0.13" +bevy_asset = { version = "0.13", optional = false } +bevy_core = "0.13" +bevy_derive = "0.13" +bevy_ecs = "0.13" +bevy_hierarchy = "0.13" +bevy_reflect = { version = "0.13" } +bevy_render = "0.13" +bevy_sprite = "0.13" +bevy_tasks = { version = "0.13", features = ["multi-threaded"], optional = false } +bevy_text = { version = "0.13", optional = false } +bevy_transform = { version = "0.13", optional = false } +bevy_ui = { version = "0.13", features = ["bevy_text"] } +bevy_utils = "0.13" +bevy_a11y = "0.13" +bevy_input = "0.13" count-macro = "0.2.2" paste = "1" @@ -217,7 +217,7 @@ web-sys = { version = "0.3", features = [ ] } [dev-dependencies] -bevy = { version = "0.12.1", features = [ +bevy = { version = "0.13", features = [ "animation", "bevy_asset", # "bevy_audio", # "bevy_gilrs", "bevy_scene", diff --git a/README-zh-Hans.md b/README-zh-Hans.md index 4840413..cedec33 100644 --- a/README-zh-Hans.md +++ b/README-zh-Hans.md @@ -52,7 +52,7 @@ MIT License ([LICENSE-MIT](https://github.com/ycysdf/rxy_ui/blob/main/LICENSE-MI ```toml [dependencies] rxy_ui = {git = "https://github.com/ycysdf/rxy_ui", features = ["bevy"]} -bevy = {version = "0.12"} +bevy = {version = "0.13"} ``` ## 示例 diff --git a/README.md b/README.md index 8ba31f6..81d92b1 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ But you can specify git repository dependencies ```toml [dependencies] rxy_ui = {git = "https://github.com/ycysdf/rxy_ui", features = ["bevy"]} -bevy = {version = "0.12"} +bevy = {version = "0.13"} ``` ## Examples diff --git a/crates/rxy_bevy/src/event.rs b/crates/rxy_bevy/src/event.rs index fea48b2..8587fd4 100644 --- a/crates/rxy_bevy/src/event.rs +++ b/crates/rxy_bevy/src/event.rs @@ -11,13 +11,12 @@ use bevy_ecs::{ prelude::{Commands, Entity, Res, Resource, World}, system::SystemId, }; -use bevy_input::{ - gamepad::GamepadButton, keyboard::KeyCode, mouse::MouseButton, Input, InputSystem, -}; +use bevy_ecs::entity::EntityHashMap; +use bevy_input::{gamepad::GamepadButton, keyboard::KeyCode, mouse::MouseButton, InputSystem, ButtonInput}; use bevy_mod_picking::prelude::*; use bevy_reflect::Reflect; use bevy_utils::tracing::error; -use bevy_utils::{all_tuples, EntityHashMap, HashMap}; +use bevy_utils::{all_tuples, HashMap}; use rxy_core::{NodeTree, RendererNodeId, RendererWorld}; @@ -439,6 +438,7 @@ pub enum FocusInputEvent { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect)] +#[reflect(no_field_bounds)] pub enum BubblePointerEvent { Over, Out, @@ -473,7 +473,7 @@ pub enum FocusInputTriggerWay { type EntityFocusInputEvents = HashMap<(T, FocusInputTriggerWay), smallvec::SmallVec<[SystemId; 1]>>; -type FocusInputEventsInner = EntityHashMap>; +type FocusInputEventsInner = EntityHashMap>; #[derive(Resource)] pub struct FocusInputEvents { @@ -505,7 +505,7 @@ where pub fn system_handle( registers: Res>, - event_reader: Res>, + event_reader: Res>, focus: Res, mut commands: Commands, ) { diff --git a/crates/rxy_bevy/src/navigation/mod.rs b/crates/rxy_bevy/src/navigation/mod.rs index f79f0ec..bbc8327 100644 --- a/crates/rxy_bevy/src/navigation/mod.rs +++ b/crates/rxy_bevy/src/navigation/mod.rs @@ -3,8 +3,8 @@ use bevy_ecs::query::With; use bevy_ecs::schedule::IntoSystemConfigs; use bevy_ecs::system::{Query, Res, ResMut}; use bevy_ecs::{change_detection::DetectChangesMut, entity::Entity, prelude::Resource}; -use bevy_input::InputSystem; -use bevy_input::{prelude::KeyCode, Input}; +use bevy_input::{ButtonInput, InputSystem}; +use bevy_input::prelude::KeyCode; use bevy_render::view::ViewVisibility; use bevy_ui::{Interaction, UiStack, UiSystem}; @@ -54,7 +54,7 @@ impl Default for KeyboardNavigationInput { /// Should the [`keyboard_navigation_system`] run? pub(crate) fn tab_pressed( - keyboard_input: Res>, + keyboard_input: Res>, keyboard_navigation: Res, ) -> bool { keyboard_navigation.enabled && keyboard_input.just_pressed(KeyCode::Tab) @@ -67,7 +67,7 @@ pub(crate) fn keyboard_navigation_system( mut focus: ResMut, mut interactions: Query<&mut Interaction>, focusables: Query<&ViewVisibility, With>, - keyboard_input: Res>, + keyboard_input: Res>, ui_stack: Res, ) { let reverse_order = @@ -124,8 +124,8 @@ pub(crate) fn keyboard_navigation_system( } /// Should the [`keyboard_click`] system run? -pub(crate) fn trigger_click(keyboard_input: Res>) -> bool { - keyboard_input.just_pressed(KeyCode::Space) || keyboard_input.just_pressed(KeyCode::Return) +pub(crate) fn trigger_click(keyboard_input: Res>) -> bool { + keyboard_input.just_pressed(KeyCode::Space) || keyboard_input.just_pressed(KeyCode::Enter) } /// Trigger the [`Focus`] entity to be clicked. @@ -136,8 +136,8 @@ pub(crate) fn keyboard_click(mut interactions: Query<&mut Interaction>, focus: R } /// Should the [`end_keyboard_click`] system run? -pub(crate) fn trigger_click_end(keyboard_input: Res>) -> bool { - keyboard_input.just_released(KeyCode::Space) || keyboard_input.just_released(KeyCode::Return) +pub(crate) fn trigger_click_end(keyboard_input: Res>) -> bool { + keyboard_input.just_released(KeyCode::Space) || keyboard_input.just_released(KeyCode::Enter) } /// Reset the clicked state. @@ -176,7 +176,7 @@ mod test { let mut commands = Commands::new(&mut queue, &world); commands.init_resource::(); - commands.init_resource::>(); + commands.init_resource::>(); commands.init_resource::(); let mut children = Vec::new(); @@ -207,7 +207,7 @@ mod test { // Simulate pressing shift let mut keyboard_input = - world.get_resource_mut::>().expect("keyboard input resource"); + world.get_resource_mut::>().expect("keyboard input resource"); keyboard_input.press(KeyCode::ShiftLeft); schedule.run(&mut world); diff --git a/crates/rxy_bevy/src/renderer/attrs.rs b/crates/rxy_bevy/src/renderer/attrs.rs index f444a4b..3330fe4 100644 --- a/crates/rxy_bevy/src/renderer/attrs.rs +++ b/crates/rxy_bevy/src/renderer/attrs.rs @@ -8,7 +8,7 @@ use crate::{all_attrs, BevyRenderer, ElementStyleEntityExt, TextStyledElementEnt use bevy_render::color::Color; use bevy_render::render_resource::encase::private::RuntimeSizedArray; use bevy_render::view::Visibility; -use bevy_text::{BreakLineOn, Font, TextAlignment}; +use bevy_text::{BreakLineOn, Font, JustifyText}; use bevy_transform::components::Transform; use bevy_ui::{ AlignContent, AlignItems, AlignSelf, BackgroundColor, BorderColor, Direction, FlexDirection, @@ -1267,7 +1267,7 @@ impl ElementAttrType for text_linebreak { pub struct text_align; impl ElementAttrType for text_align { - type Value = TextAlignment; + type Value = JustifyText; const NAME: &'static str = stringify!(text_align); fn update_value( diff --git a/crates/rxy_bevy/src/renderer/style/attr_iter.rs b/crates/rxy_bevy/src/renderer/style/attr_iter.rs index d1512a9..578f646 100644 --- a/crates/rxy_bevy/src/renderer/style/attr_iter.rs +++ b/crates/rxy_bevy/src/renderer/style/attr_iter.rs @@ -5,9 +5,9 @@ use super::node_style_state::NodeStyleSheetsState; use super::{interaction_to_style_interaction, EntityAttrSyncer, StyleEntityRefExt, StyleError}; use super::{EntityWorldRef, Result}; use bevy_ecs::prelude::{Entity, Query}; -use bevy_ecs::query::ReadOnlyWorldQuery; use bevy_ecs::world::{EntityRef, EntityWorldMut, World}; use bevy_ui::Interaction; +use bevy_ecs::query::QueryFilter; use super::rxy_bevy_crate::{ AttrSetBits, ElementEntityExtraData, ElementEntityWorldMutExt, FocusedEntity, RendererState, }; @@ -132,12 +132,12 @@ impl<'a> StateOwnerWithNodeId<'a, '_> for EntityWorldRef<'a> { } } -pub struct EntityStyleWorldQuery<'a, 'world, 'state, F: ReadOnlyWorldQuery> { +pub struct EntityStyleWorldQuery<'a, 'world, 'state, F: QueryFilter> { pub query: Query<'world, 'state, &'a RendererState, F>, pub current_entity: Entity, } -impl<'a, 'world, 'state, F: ReadOnlyWorldQuery> StateOwner<'a, 'a> +impl<'a, 'world, 'state, F: QueryFilter> StateOwner<'a, 'a> for EntityStyleWorldQuery<'world, 'state, 'a, F> { fn get_style_sheets_state(&'a self, entity: Entity) -> Result<&'a NodeStyleSheetsState> { @@ -148,7 +148,7 @@ impl<'a, 'world, 'state, F: ReadOnlyWorldQuery> StateOwner<'a, 'a> } } -impl<'a, 'world, 'state, F: ReadOnlyWorldQuery> StateOwnerWithNodeId<'a, 'a> +impl<'a, 'world, 'state, F: QueryFilter> StateOwnerWithNodeId<'a, 'a> for EntityStyleWorldQuery<'world, 'state, 'a, F> { fn get_current_entity(&self) -> Entity { diff --git a/crates/rxy_bevy/src/renderer/style/interaction_style.rs b/crates/rxy_bevy/src/renderer/style/interaction_style.rs index 7ed320f..1f19e10 100644 --- a/crates/rxy_bevy/src/renderer/style/interaction_style.rs +++ b/crates/rxy_bevy/src/renderer/style/interaction_style.rs @@ -2,11 +2,10 @@ use bevy_derive::{Deref, DerefMut}; use super::attr_iter::{EntityStyleWorldQuery, StateOwnerWithNodeId}; use super::node_style_state::NodeStyleSheetsState; use super::{Previous}; -use bevy_ecs::entity::Entity; +use bevy_ecs::entity::{Entity, EntityHashMap}; use bevy_ecs::prelude::{Changed, Commands, Query, With, World}; use bevy_ecs::system::{Command, ResMut}; use bevy_ui::Interaction; -use bevy_utils::EntityHashMap; use super::rxy_bevy_crate::{ AttrSetBits, ElementEntityExtraData, FocusedEntity, RendererState, }; @@ -15,7 +14,7 @@ use rxy_core::style::{NodeInterStyleAttrInfos, NodeStyleAttrInfos, StyleAttrValu use crate::attrs::get_attr_by_index; #[derive(Default, DerefMut, Deref, Debug)] -pub struct SetAttrValuesCommand(EntityHashMap)>>); +pub struct SetAttrValuesCommand(EntityHashMap)>>); impl SetAttrValuesCommand { pub fn add( diff --git a/crates/rxy_bevy/src/renderer/tailwind_attrs.rs b/crates/rxy_bevy/src/renderer/tailwind_attrs.rs index 654d64e..8a545bf 100644 --- a/crates/rxy_bevy/src/renderer/tailwind_attrs.rs +++ b/crates/rxy_bevy/src/renderer/tailwind_attrs.rs @@ -1,5 +1,5 @@ use bevy_render::prelude::Visibility; -use bevy_text::{BreakLineOn, TextAlignment}; +use bevy_text::{BreakLineOn, JustifyText}; use bevy_ui::{AlignItems, Display, FlexDirection, FlexWrap, JustifyContent, PositionType, Val}; use crate::all_attrs::{ align_items, column_gap, display, flex_direction, flex_grow, flex_shrink, flex_wrap, height, @@ -226,13 +226,13 @@ pub trait TailwindAttrs: MemberOwner + Sized { self.member(ElementAttr::new(BreakLineOn::NoWrap.into())) } fn text_left(self) -> Self::AddMember> { - self.member(ElementAttr::new(TextAlignment::Left.into())) + self.member(ElementAttr::new(JustifyText::Left.into())) } fn text_center(self) -> Self::AddMember> { - self.member(ElementAttr::new(TextAlignment::Center.into())) + self.member(ElementAttr::new(JustifyText::Center.into())) } fn text_right(self) -> Self::AddMember> { - self.member(ElementAttr::new(TextAlignment::Right.into())) + self.member(ElementAttr::new(JustifyText::Right.into())) } fn size( diff --git a/crates/rxy_bevy/src/view_member/event.rs b/crates/rxy_bevy/src/view_member/event.rs index 26eb6d9..ad20fa0 100644 --- a/crates/rxy_bevy/src/view_member/event.rs +++ b/crates/rxy_bevy/src/view_member/event.rs @@ -111,7 +111,7 @@ pub trait ElementKeyboardEvents: MemberOwner + Sized { self.on(x_pressed(events), system) } - fn on_return( + fn on_enter( self, system: S, ) -> Self::AddMember> @@ -119,7 +119,7 @@ pub trait ElementKeyboardEvents: MemberOwner + Sized { S: IntoSystem<(), (), Marker> + Send + 'static, Marker: Send + 'static, { - self.on_just_pressed(KeyCode::Return, system) + self.on_just_pressed(KeyCode::Enter, system) } fn on_esc( diff --git a/crates/rxy_core/src/renderers/bevy.rs b/crates/rxy_core/src/renderers/bevy.rs index f0717f1..41deb06 100644 --- a/crates/rxy_core/src/renderers/bevy.rs +++ b/crates/rxy_core/src/renderers/bevy.rs @@ -6,7 +6,7 @@ use bevy_render::prelude::Color; impl_attr_value_and_wrapper! { Color => Color::rgba_u8(0, 0, 0, 0), bevy_text::BreakLineOn => bevy_text::BreakLineOn::WordBoundary, - bevy_text::TextAlignment => bevy_text::TextAlignment::Left, + bevy_text::JustifyText => bevy_text::JustifyText::Left, bevy_ui::Val, bevy_ui::Display, bevy_ui::PositionType, diff --git a/crates/xy_reactive/Cargo.toml b/crates/xy_reactive/Cargo.toml index 882e3c3..30ec3d0 100644 --- a/crates/xy_reactive/Cargo.toml +++ b/crates/xy_reactive/Cargo.toml @@ -14,7 +14,7 @@ serde_json = "1" slotmap = "1" smallvec = "1" thiserror = "1" -bevy_tasks = { version = "0.12", features = ["multi-threaded"], optional = true } +bevy_tasks = { version = "0.13", features = ["multi-threaded"], optional = true } serde = { version = "1", features = ["derive"], optional = false } glib = { version = "0.18", optional = true } wasm-bindgen-futures = { version = "0.4", optional = true } From d1d49a12e3f2d12541acc4165244d75acc5fa851 Mon Sep 17 00:00:00 2001 From: ycysdf Date: Sun, 10 Mar 2024 10:10:22 +0800 Subject: [PATCH 2/4] fix: update to bevy 0.13 --- Cargo.toml | 6 ++---- crates/rxy_bevy/src/focusable.rs | 2 +- crates/rxy_bevy/src/renderer/elements/span.rs | 2 +- crates/rxy_core/src/diff.rs | 3 --- crates/rxy_web_dom/src/lib.rs | 1 + 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ea29957..e1ff8fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,7 @@ rxy_web_dom = { workspace = true, optional = true } [features] default = ["std", "x_iter_source", "signal"] -#web = ["std", "rxy_web_dom", "tailwind_aliases", "xy_reactive?/web"] -#web = ["std", "tailwind_aliases", "xy_reactive?/web", "rxy_web_dom"] -web = ["std", "rxy_web_dom"] +#web = ["std", "rxy_web_dom"] std = ["rxy_core/async-channel"] hooked_collection = ["dep:hooked_collection"] @@ -58,7 +56,7 @@ serde = { version = "1", features = ["derive"] } ahash = { version = "0.8", default-features = false } # bevy-inspector-egui = "0.21" -bevy_mod_picking = { version = "0.17", default-features = false, features = ["backend_bevy_ui"] } +bevy_mod_picking = { version = "0.18", default-features = false, features = ["backend_bevy_ui"] } derive_more = "0.99" drain_filter_polyfill = "0.1" futures-lite = "1.13" diff --git a/crates/rxy_bevy/src/focusable.rs b/crates/rxy_bevy/src/focusable.rs index aed2b54..bbbdc6b 100644 --- a/crates/rxy_bevy/src/focusable.rs +++ b/crates/rxy_bevy/src/focusable.rs @@ -23,7 +23,7 @@ impl Plugin for FocusablePlugin { FocusableSystemParam::update_focused_state // .in_set(UiSystem::Interactions) .after(UiSystem::Focus) - .run_if(resource_changed::()), + .run_if(resource_changed::), ) .add_systems( PostUpdate, diff --git a/crates/rxy_bevy/src/renderer/elements/span.rs b/crates/rxy_bevy/src/renderer/elements/span.rs index dcad2f7..8ef2555 100644 --- a/crates/rxy_bevy/src/renderer/elements/span.rs +++ b/crates/rxy_bevy/src/renderer/elements/span.rs @@ -96,7 +96,7 @@ impl TextStyledElementType for element_span { let Some(mut t) = entity_ref.get_mut::() else { return; }; - t.alignment = value; + t.justify = value; } } diff --git a/crates/rxy_core/src/diff.rs b/crates/rxy_core/src/diff.rs index d28aee8..46651b1 100644 --- a/crates/rxy_core/src/diff.rs +++ b/crates/rxy_core/src/diff.rs @@ -7,9 +7,6 @@ use core::clone::Clone; use core::cmp::Eq; use core::default::Default; use core::fmt::Debug; -use core::iter::Iterator; -use core::option::Option; -use core::option::Option::Some; use core::{ hash::{BuildHasherDefault, Hash}, }; diff --git a/crates/rxy_web_dom/src/lib.rs b/crates/rxy_web_dom/src/lib.rs index c88bdc6..a238f4d 100644 --- a/crates/rxy_web_dom/src/lib.rs +++ b/crates/rxy_web_dom/src/lib.rs @@ -1,6 +1,7 @@ mod renderer; pub use renderer::*; + pub mod prelude { pub use super::attrs::CommonAttrsViewBuilder; pub use crate::build_on_body; From 34331ec590e16284cdca22caa446ad0ce4d8b5c0 Mon Sep 17 00:00:00 2001 From: ycysdf Date: Sun, 10 Mar 2024 10:16:01 +0800 Subject: [PATCH 3/4] fix: update to bevy 0.13 --- crates/rxy_bevy/src/event.rs | 2 +- crates/rxy_bevy/src/navigation/mod.rs | 2 +- crates/rxy_bevy/src/renderer/elements/span.rs | 1 - crates/rxy_bevy/src/view_member/event.rs | 1 - examples/game_ui_challenges/game_menu.rs | 4 ++-- examples/playground.rs | 4 ++-- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/rxy_bevy/src/event.rs b/crates/rxy_bevy/src/event.rs index 8587fd4..0ed3de8 100644 --- a/crates/rxy_bevy/src/event.rs +++ b/crates/rxy_bevy/src/event.rs @@ -8,7 +8,7 @@ use std::iter::once; use bevy_app::PreUpdate; use bevy_ecs::{ - prelude::{Commands, Entity, Res, Resource, World}, + prelude::{Commands, Res, Resource, World}, system::SystemId, }; use bevy_ecs::entity::EntityHashMap; diff --git a/crates/rxy_bevy/src/navigation/mod.rs b/crates/rxy_bevy/src/navigation/mod.rs index bbc8327..e45cd4a 100644 --- a/crates/rxy_bevy/src/navigation/mod.rs +++ b/crates/rxy_bevy/src/navigation/mod.rs @@ -142,7 +142,7 @@ pub(crate) fn trigger_click_end(keyboard_input: Res>) -> bo /// Reset the clicked state. pub(crate) fn end_keyboard_click(mut interactions: Query<&mut Interaction>) { - interactions.for_each_mut(|mut interaction| { + interactions.iter_mut().for_each(|mut interaction| { if *interaction == Interaction::Pressed { // The click was triggered by the keyboard, so it doesn't make sense to go to `Interaction::Hovered`. *interaction = Interaction::None; diff --git a/crates/rxy_bevy/src/renderer/elements/span.rs b/crates/rxy_bevy/src/renderer/elements/span.rs index 8ef2555..df5cb1b 100644 --- a/crates/rxy_bevy/src/renderer/elements/span.rs +++ b/crates/rxy_bevy/src/renderer/elements/span.rs @@ -104,7 +104,6 @@ pub mod attrs { use bevy_text::TextStyle; use std::borrow::Cow; - use rxy_core::ElementAttrType; use super::*; diff --git a/crates/rxy_bevy/src/view_member/event.rs b/crates/rxy_bevy/src/view_member/event.rs index ad20fa0..e68a057 100644 --- a/crates/rxy_bevy/src/view_member/event.rs +++ b/crates/rxy_bevy/src/view_member/event.rs @@ -9,7 +9,6 @@ use bevy_utils::tracing::error; use rxy_core::{MemberOwner, ViewMember, ViewMemberCtx, ViewMemberOrigin}; use crate::event::*; -use crate::prelude::FocusInputEventIterator; use crate::BevyRenderer; #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/examples/game_ui_challenges/game_menu.rs b/examples/game_ui_challenges/game_menu.rs index 03e2c89..2269782 100644 --- a/examples/game_ui_challenges/game_menu.rs +++ b/examples/game_ui_challenges/game_menu.rs @@ -35,7 +35,7 @@ fn main() { RxyStyleSheetPlugin::default(), RxyKeyboardNavigationPlugin::default(), )) - .add_state::() + .init_state::() .add_systems(Startup, setup); app.run(); @@ -71,7 +71,7 @@ pub struct XConfirm; impl ElementEventIds for XConfirm { fn iter_event_ids(self) -> impl Iterator + Send + 'static { ( - x_just_pressed(KeyCode::Return), + x_just_pressed(KeyCode::Enter), x_just_pressed(GamepadButton::new(Gamepad::new(1), GamepadButtonType::West)), x_pointer_click(), ) diff --git a/examples/playground.rs b/examples/playground.rs index 11d6683..171dd18 100644 --- a/examples/playground.rs +++ b/examples/playground.rs @@ -529,10 +529,10 @@ fn sample_system_once() -> impl IntoView { .on_pointer_click(move || { cmd_sender.add(|world: &mut World| { let mut meshes = world.resource_mut::>(); - let mesh = meshes.add(shape::Quad::default().into()).into(); + let mesh = meshes.add(Rectangle::default()).into(); let mut materials = world.resource_mut::>(); - let material = materials.add(Color::PURPLE.into()); + let material = materials.add(Color::PURPLE); world.spawn(MaterialMesh2dBundle { mesh, From 24a76d24d42da4fdb94222bda54a740cdcdd11ba Mon Sep 17 00:00:00 2001 From: ycysdf Date: Sun, 10 Mar 2024 10:43:56 +0800 Subject: [PATCH 4/4] fix: cfg --- crates/rxy_bevy/Cargo.toml | 2 +- crates/rxy_bevy/src/lib.rs | 1 + crates/rxy_core/src/element/attr_value.rs | 1 + crates/rxy_core/src/impl/x_iter_source.rs | 2 +- crates/rxy_core/src/remove_on_drop.rs | 13 ++++++++++--- crates/rxy_core/src/utils/mod.rs | 5 +++++ crates/rxy_core/src/utils/on_drop.rs | 22 ++++++++++++++++++++++ 7 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 crates/rxy_core/src/utils/on_drop.rs diff --git a/crates/rxy_bevy/Cargo.toml b/crates/rxy_bevy/Cargo.toml index cca973f..f35a2bd 100644 --- a/crates/rxy_bevy/Cargo.toml +++ b/crates/rxy_bevy/Cargo.toml @@ -8,7 +8,7 @@ version = "0.1.0" [dependencies] #rxy_bevy_element.workspace = true rxy_bevy_macro.workspace = true -rxy_core = { workspace = true, features = ["common_renderer", "async-channel", "bevy", "xy_reactive", "bevy_reflect"] } +rxy_core = { workspace = true, features = ["common_renderer", "async-channel", "bevy", "xy_reactive", "bevy_reflect", "x_iter_source"] } xy_reactive = { workspace = true, optional = true, features = ["bevy"] } rxy_macro.workspace = true hooked_collection.workspace = true diff --git a/crates/rxy_bevy/src/lib.rs b/crates/rxy_bevy/src/lib.rs index a1fb6b6..fcd44e6 100644 --- a/crates/rxy_bevy/src/lib.rs +++ b/crates/rxy_bevy/src/lib.rs @@ -50,6 +50,7 @@ pub mod prelude { pub use crate::renderer::common_renderer::*; pub use crate::renderer::BevyElement; + #[cfg(feature = "style")] pub use crate::renderer::style::ElementViewStyleExt; pub use super::all_attrs::{CommonAttrsElementViewBuilder, CommonAttrsViewBuilder}; diff --git a/crates/rxy_core/src/element/attr_value.rs b/crates/rxy_core/src/element/attr_value.rs index 8fd98be..7f3d874 100644 --- a/crates/rxy_core/src/element/attr_value.rs +++ b/crates/rxy_core/src/element/attr_value.rs @@ -5,6 +5,7 @@ use alloc::borrow::Cow; use alloc::string::String; use core::fmt::Debug; use core::ops::Deref; +use alloc::vec::Vec; pub trait AttrValue: MaybeReflect + MaybeSend + MaybeSync + Debug + 'static { fn clone_att_value(&self) -> SmallBox; diff --git a/crates/rxy_core/src/impl/x_iter_source.rs b/crates/rxy_core/src/impl/x_iter_source.rs index 3a54889..f97840e 100644 --- a/crates/rxy_core/src/impl/x_iter_source.rs +++ b/crates/rxy_core/src/impl/x_iter_source.rs @@ -14,7 +14,7 @@ use core::future::Future; use core::hash::{Hash, Hasher}; use core::marker::PhantomData; use core::pin::pin; -use std::cmp::Ordering; +use core::cmp::Ordering; use futures_lite::stream::Map; use futures_lite::{FutureExt, StreamExt}; use hooked_collection::{ diff --git a/crates/rxy_core/src/remove_on_drop.rs b/crates/rxy_core/src/remove_on_drop.rs index 4f7a632..9b10fad 100644 --- a/crates/rxy_core/src/remove_on_drop.rs +++ b/crates/rxy_core/src/remove_on_drop.rs @@ -1,10 +1,17 @@ use crate::{NodeTree, Renderer, RendererWorld, ViewKey}; -use bevy_utils::synccell::SyncCell; -use bevy_utils::OnDrop; +use crate::utils::SyncCell; use crate::renderer::DeferredNodeTreeScoped; +use alloc::boxed::Box; +use crate::utils::OnDrop; #[allow(dead_code)] -pub struct ViewRemoveOnDrop(SyncCell>>); +#[cfg(feature = "send_sync")] +pub struct ViewRemoveOnDrop( + SyncCell>> +); +#[allow(dead_code)] +#[cfg(not(feature = "send_sync"))] +pub struct ViewRemoveOnDrop(SyncCell>>); pub trait RemoveOnDropWorldExt where diff --git a/crates/rxy_core/src/utils/mod.rs b/crates/rxy_core/src/utils/mod.rs index edced83..fb4532a 100644 --- a/crates/rxy_core/src/utils/mod.rs +++ b/crates/rxy_core/src/utils/mod.rs @@ -7,10 +7,14 @@ pub use bevy_utils::all_tuples; pub use bevy_utils::futures::now_or_never; #[cfg(feature = "bevy")] pub use bevy_utils::synccell::SyncCell; +#[cfg(feature = "bevy")] +pub use bevy_utils::OnDrop; #[cfg(not(feature = "bevy"))] pub use apis::now_or_never; #[cfg(not(feature = "bevy"))] +pub use on_drop::OnDrop; +#[cfg(not(feature = "bevy"))] pub use rxy_macro::{all_tuples, all_tuples_with_size}; #[cfg(not(feature = "bevy"))] pub use synccell::SyncCell; @@ -20,6 +24,7 @@ pub type AHasher = ahash::AHasher; #[cfg(not(feature = "bevy"))] mod synccell; +mod on_drop; #[cfg(not(feature = "bevy"))] mod apis { diff --git a/crates/rxy_core/src/utils/on_drop.rs b/crates/rxy_core/src/utils/on_drop.rs new file mode 100644 index 0000000..6085787 --- /dev/null +++ b/crates/rxy_core/src/utils/on_drop.rs @@ -0,0 +1,22 @@ +use core::mem::ManuallyDrop; + +pub struct OnDrop { + callback: ManuallyDrop, +} + +impl OnDrop { + /// Returns an object that will invoke the specified callback when dropped. + pub fn new(callback: F) -> Self { + Self { + callback: ManuallyDrop::new(callback), + } + } +} + +impl Drop for OnDrop { + fn drop(&mut self) { + // SAFETY: We may move out of `self`, since this instance can never be observed after it's dropped. + let callback = unsafe { ManuallyDrop::take(&mut self.callback) }; + callback(); + } +}