2020-04-06 21:20:53 +00:00
|
|
|
use super::Node;
|
2020-05-30 19:31:04 +00:00
|
|
|
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;
|
2020-06-25 17:13:00 +00:00
|
|
|
use bevy_render::{draw::Draw, mesh::Mesh, pipeline::{PipelineSpecialization, RenderPipelines, DynamicBinding, RenderPipeline}};
|
|
|
|
use bevy_sprite::{ColorMaterial, QUAD_HANDLE};
|
|
|
|
use bevy_transform::prelude::{Translation, Transform, Rotation, Scale};
|
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-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>,
|
2020-06-10 06:16:48 +00:00
|
|
|
pub draw: Draw,
|
|
|
|
pub render_pipelines: RenderPipelines,
|
2020-06-25 17:13:00 +00:00
|
|
|
pub transform: Transform,
|
|
|
|
pub translation: Translation,
|
|
|
|
pub rotation: Rotation,
|
|
|
|
pub scale: Scale,
|
2020-04-06 21:20:53 +00:00
|
|
|
}
|
2020-05-03 19:35:07 +00:00
|
|
|
|
|
|
|
impl Default for UiEntity {
|
|
|
|
fn default() -> Self {
|
|
|
|
UiEntity {
|
2020-06-20 19:39:12 +00:00
|
|
|
mesh: QUAD_HANDLE,
|
2020-06-25 17:13:00 +00:00
|
|
|
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
|
|
|
UI_PIPELINE_HANDLE,
|
|
|
|
PipelineSpecialization {
|
|
|
|
dynamic_bindings: vec![
|
|
|
|
// Transform
|
|
|
|
DynamicBinding {
|
|
|
|
bind_group: 1,
|
|
|
|
binding: 0,
|
|
|
|
},
|
|
|
|
// Node_size
|
|
|
|
DynamicBinding {
|
|
|
|
bind_group: 1,
|
|
|
|
binding: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)]),
|
2020-05-03 19:35:07 +00:00
|
|
|
node: Default::default(),
|
2020-05-04 06:49:45 +00:00
|
|
|
material: Default::default(),
|
2020-06-10 06:16:48 +00:00
|
|
|
draw: Default::default(),
|
2020-06-25 17:13:00 +00:00
|
|
|
transform: Default::default(),
|
|
|
|
translation: Default::default(),
|
|
|
|
rotation: Default::default(),
|
|
|
|
scale: Default::default(),
|
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-10 06:16:48 +00:00
|
|
|
pub draw: Draw,
|
2020-05-18 01:09:29 +00:00
|
|
|
pub label: Label,
|
2020-06-25 17:13:00 +00:00
|
|
|
pub transform: Transform,
|
|
|
|
pub translation: Translation,
|
|
|
|
pub rotation: Rotation,
|
|
|
|
pub scale: Scale,
|
2020-05-18 01:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for LabelEntity {
|
|
|
|
fn default() -> Self {
|
|
|
|
LabelEntity {
|
2020-06-20 19:39:12 +00:00
|
|
|
label: Label::default(),
|
2020-05-18 01:09:29 +00:00
|
|
|
node: Default::default(),
|
2020-06-25 17:13:00 +00:00
|
|
|
draw: Draw {
|
|
|
|
is_transparent: true,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
transform: Default::default(),
|
|
|
|
translation: Default::default(),
|
|
|
|
rotation: Default::default(),
|
|
|
|
scale: Default::default(),
|
2020-05-18 01:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|