Skip to content

Commit 5bedfe7

Browse files
committed
Merge branch 'feature/zindex-and-uistack' into feature/ui-roots-fix
2 parents 37984cb + e1d58fe commit 5bedfe7

File tree

24 files changed

+776
-491
lines changed

24 files changed

+776
-491
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,16 @@ description = "Demonstrates transparency for UI"
14421442
category = "UI (User Interface)"
14431443
wasm = true
14441444

1445+
[[example]]
1446+
name = "z_index"
1447+
path = "examples/ui/z_index.rs"
1448+
1449+
[package.metadata.example.z_index]
1450+
name = "UI Z-Index"
1451+
description = "Demonstrates z-index for UI"
1452+
category = "UI (User Interface)"
1453+
wasm = true
1454+
14451455
[[example]]
14461456
name = "ui"
14471457
path = "examples/ui/ui.rs"

crates/bevy_app/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ bevy_derive = { path = "../bevy_derive", version = "0.9.0-dev" }
2020
bevy_ecs = { path = "../bevy_ecs", version = "0.9.0-dev", default-features = false }
2121
bevy_reflect = { path = "../bevy_reflect", version = "0.9.0-dev", optional = true }
2222
bevy_utils = { path = "../bevy_utils", version = "0.9.0-dev" }
23-
bevy_tasks = { path = "../bevy_tasks", version = "0.9.0-dev" }
2423

2524
# other
2625
serde = { version = "1.0", features = ["derive"], optional = true }

crates/bevy_ecs/src/query/fetch.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,9 @@ pub unsafe trait WorldQuery: for<'w> WorldQueryGats<'w> {
436436
) -> bool;
437437
}
438438

439-
/// A helper trait for [`WorldQuery`] that works around Rust's lack of Generic Associated Types
439+
/// A helper trait for [`WorldQuery`] that works around Rust's lack of Generic Associated Types.
440+
///
441+
/// **Note**: Consider using the type aliases [`QueryItem`] and [`QueryFetch`] when using `Item` or `Fetch`.
440442
pub trait WorldQueryGats<'world> {
441443
type Item;
442444
type Fetch;

crates/bevy_input/src/input.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use bevy_ecs::system::Resource;
2+
use bevy_reflect::Reflect;
23
use bevy_utils::HashSet;
34
use std::hash::Hash;
45

@@ -33,8 +34,9 @@ use bevy_ecs::schedule::State;
3334
/// * Call the [`Input::press`] method for each press event.
3435
/// * Call the [`Input::release`] method for each release event.
3536
/// * Call the [`Input::clear`] method at each frame start, before processing events.
36-
#[derive(Debug, Clone, Resource)]
37-
pub struct Input<T: Eq + Hash> {
37+
#[derive(Debug, Clone, Resource, Reflect)]
38+
#[reflect_value]
39+
pub struct Input<T: Copy + Eq + Hash + Send + Sync + 'static> {
3840
/// A collection of every button that is currently being pressed.
3941
pressed: HashSet<T>,
4042
/// A collection of every button that has just been pressed.
@@ -43,7 +45,7 @@ pub struct Input<T: Eq + Hash> {
4345
just_released: HashSet<T>,
4446
}
4547

46-
impl<T: Eq + Hash> Default for Input<T> {
48+
impl<T: Copy + Eq + Hash + Send + Sync + 'static> Default for Input<T> {
4749
fn default() -> Self {
4850
Self {
4951
pressed: Default::default(),
@@ -55,7 +57,7 @@ impl<T: Eq + Hash> Default for Input<T> {
5557

5658
impl<T> Input<T>
5759
where
58-
T: Copy + Eq + Hash,
60+
T: Copy + Eq + Hash + Send + Sync + 'static,
5961
{
6062
/// Registers a press for the given `input`.
6163
pub fn press(&mut self, input: T) {

crates/bevy_input/src/keyboard.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{ButtonState, Input};
22
use bevy_ecs::{event::EventReader, system::ResMut};
3+
use bevy_reflect::{FromReflect, Reflect};
34

45
/// A keyboard input event.
56
///
@@ -60,8 +61,9 @@ pub fn keyboard_input_system(
6061
/// ## Updating
6162
///
6263
/// The resource is updated inside of the [`keyboard_input_system`](crate::keyboard::keyboard_input_system).
63-
#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
64+
#[derive(Reflect, FromReflect, Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
6465
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
66+
#[reflect(Hash, PartialEq)]
6567
#[repr(u32)]
6668
pub enum KeyCode {
6769
/// The `1` key over the letters.
@@ -422,6 +424,7 @@ pub enum KeyCode {
422424
/// ## Updating
423425
///
424426
/// The resource is updated inside of the [`keyboard_input_system`](crate::keyboard::keyboard_input_system).
425-
#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
427+
#[derive(Reflect, FromReflect, Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
428+
#[reflect(Hash, PartialEq)]
426429
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
427430
pub struct ScanCode(pub u32);

crates/bevy_reflect/bevy_reflect_derive/src/derive_data.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,18 @@ impl<'a> ReflectDerive<'a> {
111111
let mut force_reflect_value = false;
112112

113113
for attribute in input.attrs.iter().filter_map(|attr| attr.parse_meta().ok()) {
114-
let meta_list = if let Meta::List(meta_list) = attribute {
115-
meta_list
116-
} else {
117-
continue;
118-
};
119-
120-
if let Some(ident) = meta_list.path.get_ident() {
121-
if ident == REFLECT_ATTRIBUTE_NAME {
114+
match attribute {
115+
Meta::List(meta_list) if meta_list.path.is_ident(REFLECT_ATTRIBUTE_NAME) => {
122116
traits = ReflectTraits::from_nested_metas(&meta_list.nested);
123-
} else if ident == REFLECT_VALUE_ATTRIBUTE_NAME {
117+
}
118+
Meta::List(meta_list) if meta_list.path.is_ident(REFLECT_VALUE_ATTRIBUTE_NAME) => {
124119
force_reflect_value = true;
125120
traits = ReflectTraits::from_nested_metas(&meta_list.nested);
126121
}
122+
Meta::Path(path) if path.is_ident(REFLECT_VALUE_ATTRIBUTE_NAME) => {
123+
force_reflect_value = true;
124+
}
125+
_ => continue,
127126
}
128127
}
129128

crates/bevy_reflect/bevy_reflect_derive/src/impls/values.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ pub(crate) fn impl_value(meta: &ReflectMeta) -> TokenStream {
6868

6969
#[inline]
7070
fn clone_value(&self) -> Box<dyn #bevy_reflect_path::Reflect> {
71-
Box::new(self.clone())
71+
Box::new(std::clone::Clone::clone(self))
7272
}
7373

7474
#[inline]
7575
fn apply(&mut self, value: &dyn #bevy_reflect_path::Reflect) {
7676
let value = value.as_any();
7777
if let Some(value) = value.downcast_ref::<Self>() {
78-
*self = value.clone();
78+
*self = std::clone::Clone::clone(value);
7979
} else {
8080
panic!("Value is not {}.", std::any::type_name::<Self>());
8181
}

crates/bevy_text/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ pub mod prelude {
2828

2929
use bevy_app::prelude::*;
3030
use bevy_asset::AddAsset;
31-
use bevy_ecs::{entity::Entity, schedule::ParallelSystemDescriptorCoercion};
31+
use bevy_ecs::schedule::ParallelSystemDescriptorCoercion;
3232
use bevy_render::{RenderApp, RenderStage};
3333
use bevy_sprite::SpriteSystem;
3434
use bevy_window::ModifiesWindows;
3535

36-
pub type DefaultTextPipeline = TextPipeline<Entity>;
37-
3836
#[derive(Default)]
3937
pub struct TextPlugin;
4038

@@ -48,7 +46,7 @@ impl Plugin for TextPlugin {
4846
.register_type::<VerticalAlign>()
4947
.register_type::<HorizontalAlign>()
5048
.init_asset_loader::<FontLoader>()
51-
.insert_resource(DefaultTextPipeline::default())
49+
.insert_resource(TextPipeline::default())
5250
.add_system_to_stage(
5351
CoreStage::PostUpdate,
5452
update_text2d_layout.after(ModifiesWindows),

crates/bevy_text/src/pipeline.rs

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::hash::Hash;
2-
31
use ab_glyph::{PxScale, ScaleFont};
42
use bevy_asset::{Assets, Handle, HandleId};
3+
use bevy_ecs::component::Component;
54
use bevy_ecs::system::Resource;
65
use bevy_math::Vec2;
76
use bevy_render::texture::Image;
@@ -15,29 +14,22 @@ use crate::{
1514
TextAlignment, TextSection,
1615
};
1716

18-
#[derive(Resource)]
19-
pub struct TextPipeline<ID> {
17+
#[derive(Default, Resource)]
18+
pub struct TextPipeline {
2019
brush: GlyphBrush,
21-
glyph_map: HashMap<ID, TextLayoutInfo>,
2220
map_font_id: HashMap<HandleId, FontId>,
2321
}
2422

25-
impl<ID> Default for TextPipeline<ID> {
26-
fn default() -> Self {
27-
TextPipeline {
28-
brush: GlyphBrush::default(),
29-
glyph_map: Default::default(),
30-
map_font_id: Default::default(),
31-
}
32-
}
33-
}
34-
23+
/// Render information for a corresponding [`Text`](crate::Text) component.
24+
///
25+
/// Contains scaled glyphs and their size. Generated via [`TextPipeline::queue_text`].
26+
#[derive(Component, Clone, Default, Debug)]
3527
pub struct TextLayoutInfo {
3628
pub glyphs: Vec<PositionedGlyph>,
3729
pub size: Vec2,
3830
}
3931

40-
impl<ID: Hash + Eq> TextPipeline<ID> {
32+
impl TextPipeline {
4133
pub fn get_or_insert_font_id(&mut self, handle: &Handle<Font>, font: &Font) -> FontId {
4234
let brush = &mut self.brush;
4335
*self
@@ -46,14 +38,9 @@ impl<ID: Hash + Eq> TextPipeline<ID> {
4638
.or_insert_with(|| brush.add_font(handle.clone(), font.font.clone()))
4739
}
4840

49-
pub fn get_glyphs(&self, id: &ID) -> Option<&TextLayoutInfo> {
50-
self.glyph_map.get(id)
51-
}
52-
5341
#[allow(clippy::too_many_arguments)]
5442
pub fn queue_text(
5543
&mut self,
56-
id: ID,
5744
fonts: &Assets<Font>,
5845
sections: &[TextSection],
5946
scale_factor: f64,
@@ -62,7 +49,7 @@ impl<ID: Hash + Eq> TextPipeline<ID> {
6249
font_atlas_set_storage: &mut Assets<FontAtlasSet>,
6350
texture_atlases: &mut Assets<TextureAtlas>,
6451
textures: &mut Assets<Image>,
65-
) -> Result<(), TextError> {
52+
) -> Result<TextLayoutInfo, TextError> {
6653
let mut scaled_fonts = Vec::new();
6754
let sections = sections
6855
.iter()
@@ -90,14 +77,7 @@ impl<ID: Hash + Eq> TextPipeline<ID> {
9077
.compute_glyphs(&sections, bounds, text_alignment)?;
9178

9279
if section_glyphs.is_empty() {
93-
self.glyph_map.insert(
94-
id,
95-
TextLayoutInfo {
96-
glyphs: Vec::new(),
97-
size: Vec2::ZERO,
98-
},
99-
);
100-
return Ok(());
80+
return Ok(TextLayoutInfo::default());
10181
}
10282

10383
let mut min_x: f32 = std::f32::MAX;
@@ -125,8 +105,6 @@ impl<ID: Hash + Eq> TextPipeline<ID> {
125105
textures,
126106
)?;
127107

128-
self.glyph_map.insert(id, TextLayoutInfo { glyphs, size });
129-
130-
Ok(())
108+
Ok(TextLayoutInfo { glyphs, size })
131109
}
132110
}

0 commit comments

Comments
 (0)