2020-04-06 21:20:53 +00:00
|
|
|
use super::Node;
|
2020-07-18 21:08:46 +00:00
|
|
|
use crate::{
|
2020-07-25 06:04:45 +00:00
|
|
|
prelude::Flex,
|
2020-07-18 21:08:46 +00:00
|
|
|
render::UI_PIPELINE_HANDLE,
|
2020-07-20 03:33:55 +00:00
|
|
|
widget::{Button, Text},
|
2020-07-25 06:04:45 +00:00
|
|
|
Click, FlexSurfaceId, FocusPolicy, Hover,
|
2020-07-18 21:08:46 +00:00
|
|
|
};
|
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::{
|
2020-07-25 06:04:45 +00:00
|
|
|
camera::{Camera, OrthographicProjection, VisibleEntities, WindowOrigin},
|
2020-07-10 08:37:06 +00:00
|
|
|
draw::Draw,
|
|
|
|
mesh::Mesh,
|
|
|
|
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines},
|
|
|
|
};
|
|
|
|
use bevy_sprite::{ColorMaterial, QUAD_HANDLE};
|
2020-07-25 06:04:45 +00:00
|
|
|
use bevy_transform::{
|
|
|
|
components::LocalTransform,
|
|
|
|
prelude::{Rotation, Scale, Transform, Translation},
|
|
|
|
};
|
2020-04-06 21:20:53 +00:00
|
|
|
|
2020-07-10 04:18:35 +00:00
|
|
|
#[derive(Bundle)]
|
2020-07-18 21:08:46 +00:00
|
|
|
pub struct NodeComponents {
|
2020-04-06 21:20:53 +00:00
|
|
|
pub node: Node,
|
2020-07-25 06:04:45 +00:00
|
|
|
pub flex: Flex,
|
|
|
|
pub flex_surface_id: FlexSurfaceId,
|
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,
|
2020-07-20 03:33:55 +00:00
|
|
|
pub local_transform: LocalTransform,
|
2020-04-06 21:20:53 +00:00
|
|
|
}
|
2020-05-03 19:35:07 +00:00
|
|
|
|
2020-07-18 21:08:46 +00:00
|
|
|
impl Default for NodeComponents {
|
2020-05-03 19:35:07 +00:00
|
|
|
fn default() -> Self {
|
2020-07-18 21:08:46 +00:00
|
|
|
NodeComponents {
|
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-07-25 06:04:45 +00:00
|
|
|
flex_surface_id: Default::default(),
|
|
|
|
flex: Flex::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(),
|
2020-07-20 03:33:55 +00:00
|
|
|
local_transform: 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)]
|
2020-07-20 03:33:55 +00:00
|
|
|
pub struct TextComponents {
|
2020-05-18 01:09:29 +00:00
|
|
|
pub node: Node,
|
2020-07-25 06:04:45 +00:00
|
|
|
pub flex: Flex,
|
|
|
|
pub flex_surface_id: FlexSurfaceId,
|
2020-06-10 06:16:48 +00:00
|
|
|
pub draw: Draw,
|
2020-07-20 03:33:55 +00:00
|
|
|
pub text: Text,
|
2020-07-19 00:03:37 +00:00
|
|
|
pub focus_policy: FocusPolicy,
|
2020-06-25 17:13:00 +00:00
|
|
|
pub transform: Transform,
|
2020-07-20 03:33:55 +00:00
|
|
|
pub local_transform: LocalTransform,
|
2020-05-18 01:09:29 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 03:33:55 +00:00
|
|
|
impl Default for TextComponents {
|
2020-05-18 01:09:29 +00:00
|
|
|
fn default() -> Self {
|
2020-07-20 03:33:55 +00:00
|
|
|
TextComponents {
|
|
|
|
text: Text::default(),
|
2020-05-18 01:09:29 +00:00
|
|
|
node: Default::default(),
|
2020-07-25 06:04:45 +00:00
|
|
|
flex: Flex::default(),
|
|
|
|
flex_surface_id: Default::default(),
|
2020-07-19 00:03:37 +00:00
|
|
|
focus_policy: FocusPolicy::Pass,
|
2020-06-25 17:13:00 +00:00
|
|
|
draw: Draw {
|
|
|
|
is_transparent: true,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
transform: Default::default(),
|
2020-07-20 03:33:55 +00:00
|
|
|
local_transform: Default::default(),
|
2020-05-18 01:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-18 21:08:46 +00:00
|
|
|
|
|
|
|
#[derive(Bundle)]
|
|
|
|
pub struct ButtonComponents {
|
|
|
|
pub node: Node,
|
|
|
|
pub button: Button,
|
2020-07-25 06:04:45 +00:00
|
|
|
pub flex: Flex,
|
|
|
|
pub flex_surface_id: FlexSurfaceId,
|
2020-07-18 21:08:46 +00:00
|
|
|
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,
|
2020-07-20 03:33:55 +00:00
|
|
|
pub local_transform: LocalTransform,
|
2020-07-18 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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(),
|
2020-07-25 06:04:45 +00:00
|
|
|
flex_surface_id: Default::default(),
|
|
|
|
flex: Flex::default(),
|
2020-07-18 21:08:46 +00:00
|
|
|
material: Default::default(),
|
|
|
|
draw: Default::default(),
|
|
|
|
transform: Default::default(),
|
2020-07-20 03:33:55 +00:00
|
|
|
local_transform: Default::default(),
|
2020-07-18 21:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-25 06:04:45 +00:00
|
|
|
|
|
|
|
#[derive(Bundle)]
|
|
|
|
pub struct UiCameraComponents {
|
|
|
|
pub camera: Camera,
|
|
|
|
pub orthographic_projection: OrthographicProjection,
|
|
|
|
pub visible_entities: VisibleEntities,
|
|
|
|
pub transform: Transform,
|
|
|
|
pub translation: Translation,
|
|
|
|
pub rotation: Rotation,
|
|
|
|
pub scale: Scale,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for UiCameraComponents {
|
|
|
|
fn default() -> Self {
|
|
|
|
// we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset
|
|
|
|
// the camera's translation by far and use a right handed coordinate system
|
|
|
|
let far = 1000.0;
|
|
|
|
UiCameraComponents {
|
|
|
|
camera: Camera {
|
|
|
|
name: Some(crate::camera::UI_CAMERA.to_string()),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
orthographic_projection: OrthographicProjection {
|
|
|
|
far,
|
|
|
|
window_origin: WindowOrigin::BottomLeft,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
visible_entities: Default::default(),
|
|
|
|
transform: Default::default(),
|
|
|
|
translation: Translation::new(0.0, 0.0, far - 0.1),
|
|
|
|
rotation: Default::default(),
|
|
|
|
scale: Default::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|