rename rect to quad
This commit is contained in:
parent
5d40bddf6c
commit
e68ae995f8
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
render::SPRITE_PIPELINE_HANDLE, sprite::Sprite, ColorMaterial, Rect, QUAD_HANDLE,
|
render::SPRITE_PIPELINE_HANDLE, sprite::Sprite, ColorMaterial, Quad, QUAD_HANDLE,
|
||||||
};
|
};
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
use bevy_derive::EntityArchetype;
|
use bevy_derive::EntityArchetype;
|
||||||
@ -8,7 +8,7 @@ use bevy_render::{mesh::Mesh, Renderable};
|
|||||||
#[derive(EntityArchetype)]
|
#[derive(EntityArchetype)]
|
||||||
pub struct SpriteEntity {
|
pub struct SpriteEntity {
|
||||||
pub sprite: Sprite,
|
pub sprite: Sprite,
|
||||||
pub rect: Rect,
|
pub quad: Quad,
|
||||||
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
||||||
pub material: Handle<ColorMaterial>,
|
pub material: Handle<ColorMaterial>,
|
||||||
pub renderable: Renderable,
|
pub renderable: Renderable,
|
||||||
@ -18,7 +18,7 @@ impl Default for SpriteEntity {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
SpriteEntity {
|
SpriteEntity {
|
||||||
sprite: Default::default(),
|
sprite: Default::default(),
|
||||||
rect: Default::default(),
|
quad: Default::default(),
|
||||||
mesh: QUAD_HANDLE,
|
mesh: QUAD_HANDLE,
|
||||||
material: Default::default(),
|
material: Default::default(),
|
||||||
renderable: Renderable {
|
renderable: Renderable {
|
||||||
|
|||||||
@ -1,18 +1,20 @@
|
|||||||
mod color_material;
|
mod color_material;
|
||||||
pub mod entity;
|
pub mod entity;
|
||||||
mod rect;
|
mod quad;
|
||||||
mod render;
|
mod render;
|
||||||
mod sprite;
|
mod sprite;
|
||||||
|
mod sprite_sheet;
|
||||||
|
|
||||||
pub use color_material::*;
|
pub use color_material::*;
|
||||||
pub use rect::*;
|
pub use quad::*;
|
||||||
pub use render::*;
|
pub use render::*;
|
||||||
pub use sprite::*;
|
pub use sprite::*;
|
||||||
|
pub use sprite_sheet::*;
|
||||||
|
|
||||||
use bevy_app::{stage, AppBuilder, AppPlugin};
|
use bevy_app::{stage, AppBuilder, AppPlugin};
|
||||||
use bevy_asset::{AddAsset, Assets, Handle};
|
use bevy_asset::{AddAsset, Assets, Handle};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
mesh::{shape::Quad, Mesh},
|
mesh::{shape, Mesh},
|
||||||
render_graph::RenderGraph,
|
render_graph::RenderGraph,
|
||||||
shader::asset_shader_def_system,
|
shader::asset_shader_def_system,
|
||||||
};
|
};
|
||||||
@ -41,7 +43,7 @@ impl AppPlugin for SpritePlugin {
|
|||||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||||
meshes.set(
|
meshes.set(
|
||||||
QUAD_HANDLE,
|
QUAD_HANDLE,
|
||||||
Mesh::from(Quad {
|
Mesh::from(shape::Quad {
|
||||||
size: Vec2::new(1.0, 1.0),
|
size: Vec2::new(1.0, 1.0),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
20
crates/bevy_sprite/src/quad.rs
Normal file
20
crates/bevy_sprite/src/quad.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
use bevy_core::bytes::GetBytes;
|
||||||
|
use bevy_derive::Uniform;
|
||||||
|
use glam::Vec2;
|
||||||
|
use zerocopy::AsBytes;
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Default, Clone, Copy, Debug, Uniform, AsBytes)]
|
||||||
|
pub struct Quad {
|
||||||
|
pub position: Vec2,
|
||||||
|
pub size: Vec2,
|
||||||
|
pub z_index: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetBytes for Quad {
|
||||||
|
fn get_bytes(&self) -> Vec<u8> {
|
||||||
|
self.as_bytes().to_vec()
|
||||||
|
}
|
||||||
|
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
||||||
|
Some(self.as_bytes())
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,20 +1,14 @@
|
|||||||
use bevy_core::bytes::GetBytes;
|
|
||||||
use bevy_derive::Uniform;
|
|
||||||
use glam::Vec2;
|
|
||||||
use zerocopy::AsBytes;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Default, Clone, Copy, Debug, Uniform, AsBytes)]
|
|
||||||
pub struct Rect {
|
pub struct Rect {
|
||||||
pub position: Vec2,
|
pub min: Vec2,
|
||||||
pub size: Vec2,
|
pub max: Vec2,
|
||||||
pub z_index: f32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetBytes for Rect {
|
impl Rect {
|
||||||
fn get_bytes(&self) -> Vec<u8> {
|
pub fn width(&self) -> f32 {
|
||||||
self.as_bytes().to_vec()
|
self.max.x - self.min.x
|
||||||
}
|
}
|
||||||
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
|
||||||
Some(self.as_bytes())
|
pub fn height(&self) -> f32 {
|
||||||
|
self.max.y - self.min.y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
use crate::{ColorMaterial, Rect};
|
use crate::{ColorMaterial, Quad};
|
||||||
use bevy_asset::{Assets, Handle};
|
use bevy_asset::{Assets, Handle};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
base_render_graph,
|
base_render_graph,
|
||||||
@ -63,7 +63,7 @@ pub fn build_sprite_pipeline(shaders: &mut Assets<Shader>) -> PipelineDescriptor
|
|||||||
|
|
||||||
pub mod node {
|
pub mod node {
|
||||||
pub const COLOR_MATERIAL: &'static str = "color_material";
|
pub const COLOR_MATERIAL: &'static str = "color_material";
|
||||||
pub const RECT: &'static str = "rect";
|
pub const QUAD: &'static str = "quad";
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SpriteRenderGraphBuilder {
|
pub trait SpriteRenderGraphBuilder {
|
||||||
@ -79,8 +79,8 @@ impl SpriteRenderGraphBuilder for RenderGraph {
|
|||||||
self.add_node_edge(node::COLOR_MATERIAL, base_render_graph::node::MAIN_PASS)
|
self.add_node_edge(node::COLOR_MATERIAL, base_render_graph::node::MAIN_PASS)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
self.add_system_node(node::RECT, UniformNode::<Rect>::new(false));
|
self.add_system_node(node::QUAD, UniformNode::<Quad>::new(false));
|
||||||
self.add_node_edge(node::RECT, base_render_graph::node::MAIN_PASS)
|
self.add_node_edge(node::QUAD, base_render_graph::node::MAIN_PASS)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut pipelines = resources.get_mut::<Assets<PipelineDescriptor>>().unwrap();
|
let mut pipelines = resources.get_mut::<Assets<PipelineDescriptor>>().unwrap();
|
||||||
|
|||||||
@ -10,15 +10,15 @@ layout(set = 0, binding = 0) uniform Camera2d {
|
|||||||
mat4 ViewProj;
|
mat4 ViewProj;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform Rect {
|
layout(set = 1, binding = 0) uniform Quad {
|
||||||
vec2 Rect_Position;
|
vec2 Quad_Position;
|
||||||
vec2 Rect_Size;
|
vec2 Quad_Size;
|
||||||
float Rect_ZIndex;
|
float Quad_ZIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
v_Uv = Vertex_Uv;
|
v_Uv = Vertex_Uv;
|
||||||
vec3 position = Vertex_Position * vec3(Rect_Size, 0.0);
|
vec3 position = Vertex_Position * vec3(Quad_Size, 0.0);
|
||||||
position = position + vec3(Rect_Position, -Rect_ZIndex);
|
position = position + vec3(Quad_Position, -Quad_ZIndex);
|
||||||
gl_Position = ViewProj * vec4(position, 1.0);
|
gl_Position = ViewProj * vec4(position, 1.0);
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
use crate::{ColorMaterial, Rect};
|
use crate::{ColorMaterial, Quad};
|
||||||
use bevy_asset::{Assets, Handle};
|
use bevy_asset::{Assets, Handle};
|
||||||
use bevy_render::texture::Texture;
|
use bevy_render::texture::Texture;
|
||||||
pub use legion::prelude::*;
|
pub use legion::prelude::*;
|
||||||
@ -17,8 +17,8 @@ pub fn sprite_system() -> Box<dyn Schedulable> {
|
|||||||
.read_resource::<Assets<ColorMaterial>>()
|
.read_resource::<Assets<ColorMaterial>>()
|
||||||
.read_resource::<Assets<Texture>>()
|
.read_resource::<Assets<Texture>>()
|
||||||
.with_query(
|
.with_query(
|
||||||
<(Read<Sprite>, Read<Handle<ColorMaterial>>, Write<Rect>)>::query().filter(
|
<(Read<Sprite>, Read<Handle<ColorMaterial>>, Write<Quad>)>::query().filter(
|
||||||
changed::<Sprite>() | changed::<Rect>() | changed::<Handle<ColorMaterial>>(),
|
changed::<Sprite>() | changed::<Quad>() | changed::<Handle<ColorMaterial>>(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.build(|_, world, (materials, textures), query| {
|
.build(|_, world, (materials, textures), query| {
|
||||||
|
|||||||
8
crates/bevy_sprite/src/sprite_sheet.rs
Normal file
8
crates/bevy_sprite/src/sprite_sheet.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
use crate::Quad;
|
||||||
|
use bevy_asset::Handle;
|
||||||
|
use bevy_render::texture::Texture;
|
||||||
|
|
||||||
|
pub struct SpriteSheet {
|
||||||
|
pub texture: Handle<Texture>,
|
||||||
|
pub sprites: Vec<Quad>,
|
||||||
|
}
|
||||||
@ -3,12 +3,12 @@ use crate::{render::UI_PIPELINE_HANDLE, widget::Label};
|
|||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
use bevy_derive::EntityArchetype;
|
use bevy_derive::EntityArchetype;
|
||||||
use bevy_render::{mesh::Mesh, Renderable};
|
use bevy_render::{mesh::Mesh, Renderable};
|
||||||
use bevy_sprite::{ColorMaterial, Rect, QUAD_HANDLE};
|
use bevy_sprite::{ColorMaterial, Quad, QUAD_HANDLE};
|
||||||
|
|
||||||
#[derive(EntityArchetype)]
|
#[derive(EntityArchetype)]
|
||||||
pub struct UiEntity {
|
pub struct UiEntity {
|
||||||
pub node: Node,
|
pub node: Node,
|
||||||
pub rect: Rect,
|
pub quad: Quad,
|
||||||
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
||||||
pub material: Handle<ColorMaterial>,
|
pub material: Handle<ColorMaterial>,
|
||||||
pub renderable: Renderable,
|
pub renderable: Renderable,
|
||||||
@ -18,7 +18,7 @@ impl Default for UiEntity {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
UiEntity {
|
UiEntity {
|
||||||
node: Default::default(),
|
node: Default::default(),
|
||||||
rect: Default::default(),
|
quad: Default::default(),
|
||||||
mesh: QUAD_HANDLE,
|
mesh: QUAD_HANDLE,
|
||||||
material: Default::default(),
|
material: Default::default(),
|
||||||
renderable: Renderable {
|
renderable: Renderable {
|
||||||
@ -32,7 +32,7 @@ impl Default for UiEntity {
|
|||||||
#[derive(EntityArchetype)]
|
#[derive(EntityArchetype)]
|
||||||
pub struct LabelEntity {
|
pub struct LabelEntity {
|
||||||
pub node: Node,
|
pub node: Node,
|
||||||
pub rect: Rect,
|
pub quad: Quad,
|
||||||
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
||||||
pub material: Handle<ColorMaterial>,
|
pub material: Handle<ColorMaterial>,
|
||||||
pub renderable: Renderable,
|
pub renderable: Renderable,
|
||||||
@ -43,7 +43,7 @@ impl Default for LabelEntity {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
LabelEntity {
|
LabelEntity {
|
||||||
node: Default::default(),
|
node: Default::default(),
|
||||||
rect: Default::default(),
|
quad: Default::default(),
|
||||||
mesh: QUAD_HANDLE,
|
mesh: QUAD_HANDLE,
|
||||||
// NOTE: labels each get their own material.
|
// NOTE: labels each get their own material.
|
||||||
material: Handle::new(), // TODO: maybe abstract this out
|
material: Handle::new(), // TODO: maybe abstract this out
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use super::{Anchors, Margins};
|
use super::{Anchors, Margins};
|
||||||
use bevy_sprite::Rect;
|
use bevy_sprite::Quad;
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -36,12 +36,12 @@ impl Node {
|
|||||||
|
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
rect: &mut Rect,
|
quad: &mut Quad,
|
||||||
parent_size: Vec2,
|
parent_size: Vec2,
|
||||||
parent_position: Vec2,
|
parent_position: Vec2,
|
||||||
z_index: f32,
|
z_index: f32,
|
||||||
) {
|
) {
|
||||||
let (rect_x, rect_width) = Self::compute_dimension_properties(
|
let (quad_x, quad_width) = Self::compute_dimension_properties(
|
||||||
self.position.x(),
|
self.position.x(),
|
||||||
self.margins.left,
|
self.margins.left,
|
||||||
self.margins.right,
|
self.margins.right,
|
||||||
@ -49,7 +49,7 @@ impl Node {
|
|||||||
self.anchors.right,
|
self.anchors.right,
|
||||||
parent_size.x(),
|
parent_size.x(),
|
||||||
);
|
);
|
||||||
let (rect_y, rect_height) = Self::compute_dimension_properties(
|
let (quad_y, quad_height) = Self::compute_dimension_properties(
|
||||||
self.position.y(),
|
self.position.y(),
|
||||||
self.margins.bottom,
|
self.margins.bottom,
|
||||||
self.margins.top,
|
self.margins.top,
|
||||||
@ -58,9 +58,9 @@ impl Node {
|
|||||||
parent_size.y(),
|
parent_size.y(),
|
||||||
);
|
);
|
||||||
|
|
||||||
rect.size = Vec2::new(rect_width, rect_height);
|
quad.size = Vec2::new(quad_width, quad_height);
|
||||||
rect.position = Vec2::new(rect_x, rect_y) + parent_position;
|
quad.position = Vec2::new(quad_x, quad_y) + parent_position;
|
||||||
rect.z_index = z_index;
|
quad.z_index = z_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_dimension_properties(
|
fn compute_dimension_properties(
|
||||||
@ -85,15 +85,15 @@ impl Node {
|
|||||||
MarginGrowDirection::Negative
|
MarginGrowDirection::Negative
|
||||||
};
|
};
|
||||||
|
|
||||||
let p0 = Self::compute_rect_position(offset, margin0, anchor_p0, p0_grow_direction);
|
let p0 = Self::compute_quad_position(offset, margin0, anchor_p0, p0_grow_direction);
|
||||||
let p1 = Self::compute_rect_position(offset, margin1, anchor_p1, p1_grow_direction);
|
let p1 = Self::compute_quad_position(offset, margin1, anchor_p1, p1_grow_direction);
|
||||||
|
|
||||||
let final_width = p1 - p0;
|
let final_width = p1 - p0;
|
||||||
let p = (p0 + p1) / 2.0;
|
let p = (p0 + p1) / 2.0;
|
||||||
(p, final_width.abs())
|
(p, final_width.abs())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_rect_position(
|
fn compute_quad_position(
|
||||||
position: f32,
|
position: f32,
|
||||||
margin: f32,
|
margin: f32,
|
||||||
anchor_position: f32,
|
anchor_position: f32,
|
||||||
|
|||||||
@ -10,15 +10,15 @@ layout(set = 0, binding = 0) uniform UiCamera {
|
|||||||
mat4 ViewProj;
|
mat4 ViewProj;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform Rect {
|
layout(set = 1, binding = 0) uniform Quad {
|
||||||
vec2 Rect_Position;
|
vec2 Quad_Position;
|
||||||
vec2 Rect_Size;
|
vec2 Quad_Size;
|
||||||
float Rect_ZIndex;
|
float Quad_ZIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
v_Uv = Vertex_Uv;
|
v_Uv = Vertex_Uv;
|
||||||
vec3 position = Vertex_Position * vec3(Rect_Size, 0.0);
|
vec3 position = Vertex_Position * vec3(Quad_Size, 0.0);
|
||||||
position = position + vec3(Rect_Position, -Rect_ZIndex);
|
position = position + vec3(Quad_Position, -Quad_ZIndex);
|
||||||
gl_Position = ViewProj * vec4(position, 1.0);
|
gl_Position = ViewProj * vec4(position, 1.0);
|
||||||
}
|
}
|
||||||
@ -4,7 +4,7 @@ use bevy_transform::prelude::{Children, Parent};
|
|||||||
use bevy_window::Windows;
|
use bevy_window::Windows;
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use legion::{prelude::*, systems::SubWorld};
|
use legion::{prelude::*, systems::SubWorld};
|
||||||
use bevy_sprite::Rect;
|
use bevy_sprite::Quad;
|
||||||
|
|
||||||
pub const UI_Z_STEP: f32 = 0.0001;
|
pub const UI_Z_STEP: f32 = 0.0001;
|
||||||
|
|
||||||
@ -13,11 +13,11 @@ pub fn ui_update_system() -> Box<dyn Schedulable> {
|
|||||||
.read_resource::<Windows>()
|
.read_resource::<Windows>()
|
||||||
.with_query(<Read<Node>>::query().filter(!component::<Parent>()))
|
.with_query(<Read<Node>>::query().filter(!component::<Parent>()))
|
||||||
.write_component::<Node>()
|
.write_component::<Node>()
|
||||||
.write_component::<Rect>()
|
.write_component::<Quad>()
|
||||||
.read_component::<Children>()
|
.read_component::<Children>()
|
||||||
.build(move |_, world, windows, node_query| {
|
.build(move |_, world, windows, node_query| {
|
||||||
if let Some(window) = windows.get_primary() {
|
if let Some(window) = windows.get_primary() {
|
||||||
let mut window_rect = Rect {
|
let mut window_quad = Quad {
|
||||||
size: Vec2::new(window.width as f32, window.height as f32),
|
size: Vec2::new(window.width as f32, window.height as f32),
|
||||||
position: Vec2::new(0.0, 0.0),
|
position: Vec2::new(0.0, 0.0),
|
||||||
z_index: 0.9999,
|
z_index: 0.9999,
|
||||||
@ -30,34 +30,34 @@ pub fn ui_update_system() -> Box<dyn Schedulable> {
|
|||||||
let result = run_on_hierarchy_subworld_mut(
|
let result = run_on_hierarchy_subworld_mut(
|
||||||
world,
|
world,
|
||||||
entity,
|
entity,
|
||||||
window_rect.clone(),
|
window_quad.clone(),
|
||||||
&mut update_node_entity,
|
&mut update_node_entity,
|
||||||
&mut process_child_result,
|
&mut process_child_result,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(result) = result {
|
if let Some(result) = result {
|
||||||
window_rect.z_index = result.z_index;
|
window_quad.z_index = result.z_index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_node_entity(world: &mut SubWorld, entity: Entity, parent_rect: Rect) -> Option<Rect> {
|
fn update_node_entity(world: &mut SubWorld, entity: Entity, parent_quad: Quad) -> Option<Quad> {
|
||||||
// TODO: Somehow remove this unsafe
|
// TODO: Somehow remove this unsafe
|
||||||
unsafe {
|
unsafe {
|
||||||
if let Some(mut node) = world.get_component_mut_unchecked::<Node>(entity) {
|
if let Some(mut node) = world.get_component_mut_unchecked::<Node>(entity) {
|
||||||
if let Some(mut rect) = world.get_component_mut_unchecked::<Rect>(entity) {
|
if let Some(mut quad) = world.get_component_mut_unchecked::<Quad>(entity) {
|
||||||
node.update(
|
node.update(
|
||||||
&mut rect,
|
&mut quad,
|
||||||
parent_rect.size,
|
parent_quad.size,
|
||||||
parent_rect.position,
|
parent_quad.position,
|
||||||
parent_rect.z_index,
|
parent_quad.z_index,
|
||||||
);
|
);
|
||||||
return Some(Rect {
|
return Some(Quad {
|
||||||
size: rect.size,
|
size: quad.size,
|
||||||
position: rect.position - rect.size / 2.0,
|
position: quad.position - quad.size / 2.0,
|
||||||
z_index: rect.z_index - UI_Z_STEP,
|
z_index: quad.z_index - UI_Z_STEP,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ fn update_node_entity(world: &mut SubWorld, entity: Entity, parent_rect: Rect) -
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_child_result(_parent_result: Rect, child_result: Rect) -> Rect {
|
fn process_child_result(_parent_result: Quad, child_result: Quad) -> Quad {
|
||||||
// "earlier" children are sorted behind "later" children
|
// "earlier" children are sorted behind "later" children
|
||||||
let mut result = child_result.clone();
|
let mut result = child_result.clone();
|
||||||
result.z_index -= UI_Z_STEP;
|
result.z_index -= UI_Z_STEP;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use bevy_asset::{Assets, Handle};
|
use bevy_asset::{Assets, Handle};
|
||||||
use bevy_render::{texture::Texture, Color};
|
use bevy_render::{texture::Texture, Color};
|
||||||
use bevy_sprite::{ColorMaterial, Rect};
|
use bevy_sprite::{ColorMaterial, Quad};
|
||||||
use bevy_text::Font;
|
use bevy_text::Font;
|
||||||
use legion::prelude::{Com, Res, ResMut};
|
use legion::prelude::{Com, Res, ResMut};
|
||||||
|
|
||||||
@ -29,12 +29,12 @@ impl Label {
|
|||||||
mut textures: ResMut<Assets<Texture>>,
|
mut textures: ResMut<Assets<Texture>>,
|
||||||
fonts: Res<Assets<Font>>,
|
fonts: Res<Assets<Font>>,
|
||||||
label: Com<Label>,
|
label: Com<Label>,
|
||||||
rect: Com<Rect>,
|
quad: Com<Quad>,
|
||||||
color_material_handle: Com<Handle<ColorMaterial>>,
|
color_material_handle: Com<Handle<ColorMaterial>>,
|
||||||
) {
|
) {
|
||||||
// ensure the texture is at least 1x1
|
// ensure the texture is at least 1x1
|
||||||
let width = rect.size.x().max(1.0);
|
let width = quad.size.x().max(1.0);
|
||||||
let height = rect.size.y().max(1.0);
|
let height = quad.size.y().max(1.0);
|
||||||
|
|
||||||
if let Some(font) = fonts.get(&label.font) {
|
if let Some(font) = fonts.get(&label.font) {
|
||||||
let texture =
|
let texture =
|
||||||
|
|||||||
@ -17,8 +17,7 @@ fn setup(
|
|||||||
.build()
|
.build()
|
||||||
.add_entity(OrthographicCameraEntity::default())
|
.add_entity(OrthographicCameraEntity::default())
|
||||||
.add_entity(SpriteEntity {
|
.add_entity(SpriteEntity {
|
||||||
rect: Rect {
|
quad: Quad {
|
||||||
position: Vec2::new(0.0, 0.0),
|
|
||||||
z_index: 0.5,
|
z_index: 0.5,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|||||||
@ -33,7 +33,7 @@ pub use crate::render::{
|
|||||||
#[cfg(feature = "scene")]
|
#[cfg(feature = "scene")]
|
||||||
pub use crate::scene::{Scene, SceneSpawner};
|
pub use crate::scene::{Scene, SceneSpawner};
|
||||||
#[cfg(feature = "sprite")]
|
#[cfg(feature = "sprite")]
|
||||||
pub use crate::sprite::{ColorMaterial, Rect, Sprite, entity::SpriteEntity};
|
pub use crate::sprite::{ColorMaterial, Quad, Sprite, entity::SpriteEntity};
|
||||||
#[cfg(feature = "text")]
|
#[cfg(feature = "text")]
|
||||||
pub use crate::text::Font;
|
pub use crate::text::Font;
|
||||||
#[cfg(feature = "transform")]
|
#[cfg(feature = "transform")]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user