bevy/crates/bevy_ui/src/entity.rs

146 lines
4.3 KiB
Rust
Raw Normal View History

2020-04-06 21:20:53 +00:00
use super::Node;
use crate::{
render::UI_PIPELINE_HANDLE,
widget::{Button, Label},
Click, Hover, FocusPolicy,
};
2020-05-04 06:49:45 +00:00
use bevy_asset::Handle;
2020-07-10 04:18:35 +00:00
use bevy_ecs::Bundle;
2020-07-10 08:37:06 +00:00
use bevy_render::{
draw::Draw,
mesh::Mesh,
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines},
};
use bevy_sprite::{ColorMaterial, QUAD_HANDLE};
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
2020-04-06 21:20:53 +00:00
2020-07-10 04:18:35 +00:00
#[derive(Bundle)]
pub struct NodeComponents {
2020-04-06 21:20:53 +00:00
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>,
pub draw: Draw,
pub render_pipelines: RenderPipelines,
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 NodeComponents {
2020-05-03 19:35:07 +00:00
fn default() -> Self {
NodeComponents {
mesh: QUAD_HANDLE,
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(),
draw: Default::default(),
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-07-10 04:18:35 +00:00
#[derive(Bundle)]
pub struct LabelComponents {
2020-05-18 01:09:29 +00:00
pub node: Node,
pub draw: Draw,
2020-05-18 01:09:29 +00:00
pub label: Label,
pub focus_policy: FocusPolicy,
pub transform: Transform,
pub translation: Translation,
pub rotation: Rotation,
pub scale: Scale,
2020-05-18 01:09:29 +00:00
}
impl Default for LabelComponents {
2020-05-18 01:09:29 +00:00
fn default() -> Self {
LabelComponents {
label: Label::default(),
2020-05-18 01:09:29 +00:00
node: Default::default(),
focus_policy: FocusPolicy::Pass,
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
}
}
}
#[derive(Bundle)]
pub struct ButtonComponents {
pub node: Node,
pub button: Button,
pub click: Click,
pub hover: Hover,
pub focus_policy: FocusPolicy,
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
pub material: Handle<ColorMaterial>,
pub draw: Draw,
pub render_pipelines: RenderPipelines,
pub transform: Transform,
pub translation: Translation,
pub rotation: Rotation,
pub scale: Scale,
}
impl Default for ButtonComponents {
fn default() -> Self {
ButtonComponents {
button: Button,
click: Click::default(),
hover: Hover::default(),
focus_policy: FocusPolicy::default(),
mesh: QUAD_HANDLE,
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()
},
)]),
node: Default::default(),
material: Default::default(),
draw: Default::default(),
transform: Default::default(),
translation: Default::default(),
rotation: Default::default(),
scale: Default::default(),
}
}
}