bevy/crates/bevy_ui/src/entity.rs

56 lines
1.6 KiB
Rust
Raw Normal View History

2020-04-06 21:20:53 +00:00
use super::Node;
use crate::{render::UI_PIPELINE_HANDLE, widget::Label};
2020-05-04 06:49:45 +00:00
use bevy_asset::Handle;
2020-04-06 23:15:59 +00:00
use bevy_derive::EntityArchetype;
use bevy_render::{draw::Draw, mesh::Mesh, pipeline::RenderPipelines};
2020-06-01 06:39:20 +00:00
use bevy_sprite::{ColorMaterial, Quad, QUAD_HANDLE};
2020-04-06 21:20:53 +00:00
2020-05-03 19:35:07 +00:00
#[derive(EntityArchetype)]
2020-04-06 21:20:53 +00:00
pub struct UiEntity {
pub node: Node,
2020-06-01 06:39:20 +00:00
pub quad: Quad,
2020-05-06 01:44:32 +00:00
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
2020-05-04 06:49:45 +00:00
pub material: Handle<ColorMaterial>,
pub draw: Draw,
pub render_pipelines: RenderPipelines,
2020-04-06 21:20:53 +00:00
}
2020-05-03 19:35:07 +00:00
impl Default for UiEntity {
fn default() -> Self {
UiEntity {
node: Default::default(),
2020-06-01 06:39:20 +00:00
quad: Default::default(),
2020-05-03 19:35:07 +00:00
mesh: QUAD_HANDLE,
2020-05-04 06:49:45 +00:00
material: Default::default(),
draw: Default::default(),
render_pipelines: RenderPipelines::from_handles(&[UI_PIPELINE_HANDLE]),
2020-05-03 19:35:07 +00:00
}
}
2020-05-04 06:49:45 +00:00
}
2020-05-04 08:22:25 +00:00
2020-05-18 01:09:29 +00:00
#[derive(EntityArchetype)]
pub struct LabelEntity {
pub node: Node,
2020-06-01 06:39:20 +00:00
pub quad: Quad,
2020-05-18 01:09:29 +00:00
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
pub material: Handle<ColorMaterial>,
pub draw: Draw,
pub render_pipelines: RenderPipelines,
2020-05-18 01:09:29 +00:00
pub label: Label,
}
impl Default for LabelEntity {
fn default() -> Self {
LabelEntity {
node: Default::default(),
2020-06-01 06:39:20 +00:00
quad: Default::default(),
2020-05-18 01:09:29 +00:00
mesh: QUAD_HANDLE,
// NOTE: labels each get their own material.
material: Handle::new(), // TODO: maybe abstract this out
draw: Default::default(),
render_pipelines: RenderPipelines::from_handles(&[UI_PIPELINE_HANDLE]),
2020-05-18 01:09:29 +00:00
label: Label::default(),
}
}
}