Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple root UI Node #1211

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/bevy_ecs/src/core/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ impl EntityFilter for AnyEntityFilter {

pub struct Or<T>(pub T);

pub struct Not<T>(pub T);

/// Query transformer that retrieves components of type `T` that have been mutated since the start of the frame.
/// Added components do not count as mutated.
pub struct Mutated<T>(NonNull<ComponentFlags>, PhantomData<T>);
Expand Down Expand Up @@ -270,3 +272,23 @@ impl_query_filter_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M);
impl_query_filter_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N);
impl_query_filter_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O);
impl_query_filter_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P);

impl<T: QueryFilter> QueryFilter for Not<T> {
type EntityFilter = Not<T::EntityFilter>;

fn access() -> QueryAccess {
T::access()
}

fn get_entity_filter(archetype: &Archetype) -> Option<Self::EntityFilter> {
T::get_entity_filter(archetype).map(Not)
}
}

impl<T: EntityFilter> EntityFilter for Not<T> {
const DANGLING: Self = Not(T::DANGLING);

unsafe fn matches_entity(&self, offset: usize) -> bool {
!self.0.matches_entity(offset)
}
}
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub use bundle::{Bundle, DynamicBundle, MissingComponent};
pub use entities::{Entity, EntityReserver, Location, NoSuchEntity};
pub use entity_builder::{BuiltEntity, EntityBuilder};
pub use entity_map::*;
pub use filter::{Added, Changed, EntityFilter, Mutated, Or, QueryFilter, With, Without};
pub use filter::{Added, Changed, EntityFilter, Mutated, Not, Or, QueryFilter, With, Without};
pub use query::{Batch, BatchedIter, Flags, Mut, QueryIter, ReadOnlyFetch, WorldQuery};
pub use world::{ArchetypesGeneration, Component, ComponentError, SpawnBatchIter, World};
pub use world_builder::*;
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod prelude {
resource::{ChangedRes, FromResources, Local, Res, ResMut, Resource, Resources},
schedule::{Schedule, State, StateStage, SystemStage},
system::{Commands, IntoSystem, Query, System},
Added, Bundle, Changed, Component, Entity, Flags, In, IntoChainSystem, Mut, Mutated, Or,
QuerySet, Ref, RefMut, With, Without, World,
Added, Bundle, Changed, Component, Entity, Flags, In, IntoChainSystem, Mut, Mutated, Not,
Or, QuerySet, Ref, RefMut, With, Without, World,
};
}
60 changes: 28 additions & 32 deletions crates/bevy_ui/src/flex/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,31 @@ use crate::{
};
use bevy_math::{Rect, Size};

pub fn from_rect(
scale_factor: f64,
rect: Rect<Val>,
) -> stretch::geometry::Rect<stretch::style::Dimension> {
pub fn from_rect(rect: Rect<Val>) -> stretch::geometry::Rect<stretch::style::Dimension> {
stretch::geometry::Rect {
start: from_val(scale_factor, rect.left),
end: from_val(scale_factor, rect.right),
start: rect.left.into(),
end: rect.right.into(),
// NOTE: top and bottom are intentionally flipped. stretch has a flipped y-axis
top: from_val(scale_factor, rect.bottom),
bottom: from_val(scale_factor, rect.top),
top: rect.bottom.into(),
bottom: rect.top.into(),
}
}

pub fn from_f32_size(scale_factor: f64, size: Size<f32>) -> stretch::geometry::Size<f32> {
pub fn from_f32_size(size: Size<f32>) -> stretch::geometry::Size<f32> {
stretch::geometry::Size {
width: (scale_factor * size.width as f64) as f32,
height: (scale_factor * size.height as f64) as f32,
width: size.width,
height: size.height,
}
}

pub fn from_val_size(
scale_factor: f64,
size: Size<Val>,
) -> stretch::geometry::Size<stretch::style::Dimension> {
pub fn from_val_size(size: Size<Val>) -> stretch::geometry::Size<stretch::style::Dimension> {
stretch::geometry::Size {
width: from_val(scale_factor, size.width),
height: from_val(scale_factor, size.height),
width: size.width.into(),
height: size.height.into(),
}
}

pub fn from_style(scale_factor: f64, value: &Style) -> stretch::style::Style {
pub fn from_style(value: &Style) -> stretch::style::Style {
stretch::style::Style {
overflow: stretch::style::Overflow::Visible,
display: value.display.into(),
Expand All @@ -46,29 +40,31 @@ pub fn from_style(scale_factor: f64, value: &Style) -> stretch::style::Style {
align_self: value.align_self.into(),
align_content: value.align_content.into(),
justify_content: value.justify_content.into(),
position: from_rect(scale_factor, value.position),
margin: from_rect(scale_factor, value.margin),
padding: from_rect(scale_factor, value.padding),
border: from_rect(scale_factor, value.border),
position: from_rect(value.position),
margin: from_rect(value.margin),
padding: from_rect(value.padding),
border: from_rect(value.border),
flex_grow: value.flex_grow,
flex_shrink: value.flex_shrink,
flex_basis: from_val(scale_factor, value.flex_basis),
size: from_val_size(scale_factor, value.size),
min_size: from_val_size(scale_factor, value.min_size),
max_size: from_val_size(scale_factor, value.max_size),
flex_basis: value.flex_basis.into(),
size: from_val_size(value.size),
min_size: from_val_size(value.min_size),
max_size: from_val_size(value.max_size),
aspect_ratio: match value.aspect_ratio {
Some(value) => stretch::number::Number::Defined(value),
None => stretch::number::Number::Undefined,
},
}
}

pub fn from_val(scale_factor: f64, val: Val) -> stretch::style::Dimension {
match val {
Val::Auto => stretch::style::Dimension::Auto,
Val::Percent(value) => stretch::style::Dimension::Percent(value / 100.0),
Val::Px(value) => stretch::style::Dimension::Points((scale_factor * value as f64) as f32),
Val::Undefined => stretch::style::Dimension::Undefined,
impl From<Val> for stretch::style::Dimension {
fn from(val: Val) -> Self {
match val {
Val::Auto => stretch::style::Dimension::Auto,
Val::Percent(value) => stretch::style::Dimension::Percent(value / 100.0),
Val::Px(value) => stretch::style::Dimension::Points(value),
Val::Undefined => stretch::style::Dimension::Undefined,
}
}
}

Expand Down
Loading