update to 0.13.1

This commit is contained in:
Rowan Vixen 2024-03-24 22:38:08 -04:00
parent 273660d33d
commit 3e31b27d6e
8 changed files with 876 additions and 933 deletions

1698
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -4,38 +4,25 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
bevy = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" } bevy = "0.13.1"
dioxus = { git = "https://github.com/ealmloff/dioxus", branch = "fix-event-bubbling", default-features = false, features = [ bevy_mod_picking = "0.18.2"
"macro", dioxus = "0.4.3"
"hooks", #dioxus = { git = "https://github.com/ealmloff/dioxus", branch = "fix-event-bubbling", default-features = false, features = [
] } # "macro",
dioxus-rsx = { git = "https://github.com/ealmloff/dioxus", branch = "fix-event-bubbling", default-features = false, features = [ # "hooks",
"hot_reload", #] }
], optional = true } #dioxus-rsx = { git = "https://github.com/ealmloff/dioxus", branch = "fix-event-bubbling", default-features = false, features = [
dioxus-hot-reload = { git = "https://github.com/ealmloff/dioxus", branch = "fix-event-bubbling", default-features = false, features = [ # "hot_reload",
"custom_file_watcher", #], optional = true }
], optional = true } #dioxus-hot-reload = { git = "https://github.com/ealmloff/dioxus", branch = "fix-event-bubbling", default-features = false, features = [
bevy_mod_picking = { version = "0.17", default-features = false, features = [ # "custom_file_watcher",
"backend_bevy_ui", #], optional = true }
] } #bevy_mod_picking = { version = "0.17", default-features = false, features = [
# "backend_bevy_ui",
#] }
[features] [features]
hot_reload = ["dioxus/hot-reload", "dioxus-rsx", "dioxus-hot-reload"] #hot_reload = ["dioxus/hot-reload", "dioxus-rsx", "dioxus-hot-reload"]
[patch.crates-io]
bevy_app = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_asset = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_core = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_ecs = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_hierarchy = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_input = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_math = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_reflect = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_render = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_transform = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_ui = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_utils = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
bevy_window = { git = "https://github.com/JMS55/bevy", branch = "query_new_12" }
[[example]] [[example]]
name = "demo" name = "demo"

View File

@ -1,6 +1,6 @@
use bevy::{prelude::*, reflect::TypeInfo}; use bevy::{prelude::*, reflect::TypeInfo};
use bevy_dioxus::{colors::*, prelude::*}; use bevy_dioxus::{colors::*, prelude::*};
use bevy_mod_picking::DefaultPickingPlugins; use bevy_mod_picking::{debug::DebugName, DefaultPickingPlugins};
fn main() { fn main() {
App::new() App::new()
@ -33,7 +33,7 @@ fn Editor(cx: Scope) -> Element {
#[component] #[component]
fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseStateSendable<Option<Entity>>) -> Element { fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseStateSendable<Option<Entity>>) -> Element {
let mut entities = use_query_filtered::<(Entity, DebugName), Without<Node>>(cx); let mut entities = use_query_filtered::<(Entity, &Name), ()>(cx);
let entities = entities.query(); let entities = entities.query();
let mut entities = entities.into_iter().collect::<Vec<_>>(); let mut entities = entities.into_iter().collect::<Vec<_>>();
entities.sort_by_key(|(entity, _)| *entity); entities.sort_by_key(|(entity, _)| *entity);
@ -58,13 +58,13 @@ fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseStateSendable<Option<Entity>
} }
event.stop_propagation(); event.stop_propagation();
}, },
base_color: if Some(entity) == *selected_entity.read() { Some(VIOLET_700) } else { None }, base_color: VIOLET_700,
click_color: if Some(entity) == *selected_entity.read() { Some(VIOLET_400) } else { None }, click_color: VIOLET_400,
hover_color: if Some(entity) == *selected_entity.read() { Some(VIOLET_500) } else { None }, hover_color: VIOLET_500,
match name.name { //base_color: if Some(entity) == *selected_entity.read() { Some(VIOLET_700) } else { None },
Some(name) => format!("{name}"), //click_color: if Some(entity) == *selected_entity.read() { Some(VIOLET_400) } else { None },
_ => format!("Entity ({:?})", name.entity) //hover_color: if Some(entity) == *selected_entity.read() { Some(VIOLET_500) } else { None },
} name
} }
} }
} }

View File

@ -4,7 +4,7 @@ use crate::{
}; };
use bevy::{ use bevy::{
asset::AssetServer, asset::AssetServer,
ecs::{entity::Entity, system::Command, world::World}, ecs::{entity::{Entity, EntityHashMap}, system::Command, world::World},
hierarchy::{BuildWorldChildren, Children, DespawnRecursive, Parent}, hierarchy::{BuildWorldChildren, Children, DespawnRecursive, Parent},
prelude::default, prelude::default,
render::{color::Color, view::Visibility}, render::{color::Color, view::Visibility},
@ -15,7 +15,7 @@ use bevy::{
widget::TextFlags, widget::TextFlags,
*, *,
}, },
utils::{EntityHashMap, HashMap}, utils::HashMap,
}; };
use dioxus::core::{ use dioxus::core::{
BorrowedAttributeValue, ElementId, Mutation, Mutations, Template, TemplateAttribute, BorrowedAttributeValue, ElementId, Mutation, Mutations, Template, TemplateAttribute,
@ -25,7 +25,7 @@ use dioxus::core::{
pub fn apply_mutations( pub fn apply_mutations(
mutations: Mutations, mutations: Mutations,
element_id_to_bevy_ui_entity: &mut HashMap<ElementId, Entity>, element_id_to_bevy_ui_entity: &mut HashMap<ElementId, Entity>,
bevy_ui_entity_to_element_id: &mut EntityHashMap<Entity, ElementId>, bevy_ui_entity_to_element_id: &mut EntityHashMap<ElementId>,
templates: &mut HashMap<String, BevyTemplate>, templates: &mut HashMap<String, BevyTemplate>,
root_entity: Entity, root_entity: Entity,
world: &mut World, world: &mut World,

View File

@ -3,7 +3,7 @@ use bevy::{
ecs::{ ecs::{
component::ComponentId, component::ComponentId,
event::{Event, EventIterator, Events, ManualEventReader}, event::{Event, EventIterator, Events, ManualEventReader},
query::ReadOnlyWorldQuery, query::{QueryData, QueryFilter, ReadOnlyQueryData, WorldQuery},
system::{Query, Resource, SystemState}, system::{Query, Resource, SystemState},
world::World, world::World,
}, },
@ -89,15 +89,15 @@ pub fn use_resource<T: Resource>(cx: &ScopeState) -> &T {
pub fn use_query<Q>(cx: &ScopeState) -> UseQuery<'_, Q, ()> pub fn use_query<Q>(cx: &ScopeState) -> UseQuery<'_, Q, ()>
where where
Q: ReadOnlyWorldQuery, Q: ReadOnlyQueryData,
{ {
use_query_filtered(cx) use_query_filtered(cx)
} }
pub fn use_query_filtered<Q, F>(cx: &ScopeState) -> UseQuery<'_, Q, F> pub fn use_query_filtered<Q, F>(cx: &ScopeState) -> UseQuery<'_, Q, F>
where where
Q: ReadOnlyWorldQuery, Q: ReadOnlyQueryData,
F: ReadOnlyWorldQuery, F: ReadOnlyQueryData + QueryFilter,
{ {
let world = EcsContext::get_world(cx); let world = EcsContext::get_world(cx);
@ -128,15 +128,15 @@ pub fn use_event_reader<E: Event>(cx: &ScopeState) -> EventIterator<'_, E> {
event_reader.read(events) event_reader.read(events)
} }
pub struct UseQuery<'a, Q: ReadOnlyWorldQuery + 'static, F: ReadOnlyWorldQuery + 'static> { pub struct UseQuery<'a, Q: ReadOnlyQueryData + 'static, F: ReadOnlyQueryData + QueryFilter + 'static> {
system_state: SystemState<Query<'static, 'static, Q, F>>, system_state: SystemState<Query<'static, 'static, Q, F>>,
world_ref: &'a World, world_ref: &'a World,
} }
impl<'a, Q, F> UseQuery<'a, Q, F> impl<'a, Q, F> UseQuery<'a, Q, F>
where where
Q: ReadOnlyWorldQuery, Q: ReadOnlyQueryData,
F: ReadOnlyWorldQuery, F: ReadOnlyQueryData + QueryFilter,
{ {
pub fn query(&mut self) -> Query<Q, F> { pub fn query(&mut self) -> Query<Q, F> {
self.system_state.get(self.world_ref) self.system_state.get(self.world_ref)

View File

@ -1,7 +1,7 @@
use bevy::{ use bevy::{
ecs::{ ecs::{
component::Component, component::Component,
entity::Entity, entity::{Entity, EntityHashSet},
event::{Event, EventWriter, Events, ManualEventReader}, event::{Event, EventWriter, Events, ManualEventReader},
system::{Local, Query, Resource}, system::{Local, Query, Resource},
world::World, world::World,
@ -9,7 +9,6 @@ use bevy::{
hierarchy::Parent, hierarchy::Parent,
prelude::EntityWorldMut, prelude::EntityWorldMut,
ui::RelativeCursorPosition, ui::RelativeCursorPosition,
utils::EntityHashSet,
}; };
use bevy_mod_picking::events::{Click, Down, Out, Over, Pointer, Up}; use bevy_mod_picking::events::{Click, Down, Out, Over, Pointer, Up};
use dioxus::core::ScopeState; use dioxus::core::ScopeState;
@ -166,12 +165,12 @@ fn bubble_event_helper<T: Component>(target_entity: &mut Entity, world: &World)
pub fn generate_mouse_enter_leave_events( pub fn generate_mouse_enter_leave_events(
entities: Query<(Entity, &RelativeCursorPosition)>, entities: Query<(Entity, &RelativeCursorPosition)>,
mut previous_over: Local<EntityHashSet<Entity>>, mut previous_over: Local<EntityHashSet>,
mut over: Local<EntityHashSet<Entity>>, mut over: Local<EntityHashSet>,
mut enter: EventWriter<MouseEnter>, mut enter: EventWriter<MouseEnter>,
mut leave: EventWriter<MouseExit>, mut leave: EventWriter<MouseExit>,
) { ) {
mem::swap::<EntityHashSet<Entity>>(&mut previous_over, &mut over); mem::swap::<EntityHashSet>(&mut previous_over, &mut over);
over.clear(); over.clear();
for (entity, relative_cursor_position) in &entities { for (entity, relative_cursor_position) in &entities {

View File

@ -1,3 +1,4 @@
#![feature(trait_alias)]
mod apply_mutations; mod apply_mutations;
pub mod colors; pub mod colors;
mod deferred_system; mod deferred_system;
@ -20,10 +21,10 @@ use self::{
}; };
use bevy::{ use bevy::{
app::{App, Last, Plugin, PreUpdate}, app::{App, Last, Plugin, PreUpdate},
ecs::{bundle::Bundle, component::Component, entity::Entity, schedule::IntoSystemConfigs}, ecs::{bundle::Bundle, component::Component, entity::{Entity, EntityHashMap}, schedule::IntoSystemConfigs},
prelude::Deref, prelude::Deref,
ui::{node_bundles::NodeBundle, ui_focus_system}, ui::{node_bundles::NodeBundle, ui_focus_system},
utils::{EntityHashMap, HashMap}, utils::HashMap,
}; };
use dioxus::core::{Element, ElementId, Scope, VirtualDom}; use dioxus::core::{Element, ElementId, Scope, VirtualDom};
@ -32,7 +33,7 @@ pub mod prelude {
pub use super::ecs_hooks::{ pub use super::ecs_hooks::{
use_event_reader, use_query, use_query_filtered, use_resource, use_world, use_event_reader, use_query, use_query_filtered, use_resource, use_world,
}; };
pub use super::elements::*; pub use super::elements::dioxus_elements;
pub use super::use_state_sendable::*; pub use super::use_state_sendable::*;
pub use super::{DioxusUiBundle, DioxusUiPlugin, DioxusUiRoot}; pub use super::{DioxusUiBundle, DioxusUiPlugin, DioxusUiRoot};
pub use bevy_mod_picking::pointer::PointerButton; pub use bevy_mod_picking::pointer::PointerButton;
@ -80,7 +81,7 @@ struct UiContext {
struct UiRoot { struct UiRoot {
virtual_dom: VirtualDom, virtual_dom: VirtualDom,
element_id_to_bevy_ui_entity: HashMap<ElementId, Entity>, element_id_to_bevy_ui_entity: HashMap<ElementId, Entity>,
bevy_ui_entity_to_element_id: EntityHashMap<Entity, ElementId>, bevy_ui_entity_to_element_id: EntityHashMap<ElementId>,
templates: HashMap<String, BevyTemplate>, templates: HashMap<String, BevyTemplate>,
needs_rebuild: bool, needs_rebuild: bool,
} }

View File

@ -2,7 +2,7 @@ use bevy::{
asset::{AssetPath, AssetServer}, asset::{AssetPath, AssetServer},
math::Quat, math::Quat,
render::{color::Color, view::Visibility}, render::{color::Color, view::Visibility},
text::{Text, TextAlignment}, text::{JustifyText, Text},
transform::components::Transform, transform::components::Transform,
ui::*, ui::*,
}; };
@ -188,13 +188,13 @@ pub fn set_attribute(
style.direction = Direction::RightToLeft; style.direction = Direction::RightToLeft;
} }
("text_multiline_alignment", "left") if text.is_some() => { ("text_multiline_alignment", "left") if text.is_some() => {
text.unwrap().alignment = TextAlignment::Left; text.unwrap().justify = JustifyText::Left;
} }
("text_multiline_alignment", "center") if text.is_some() => { ("text_multiline_alignment", "center") if text.is_some() => {
text.unwrap().alignment = TextAlignment::Center; text.unwrap().justify = JustifyText::Center;
} }
("text_multiline_alignment", "right") if text.is_some() => { ("text_multiline_alignment", "right") if text.is_some() => {
text.unwrap().alignment = TextAlignment::Right; text.unwrap().justify = JustifyText::Right;
} }
("text_size", value) if text.is_some() => { ("text_size", value) if text.is_some() => {
text.unwrap().sections[0].style.font_size = parse_f32(value); text.unwrap().sections[0].style.font_size = parse_f32(value);