use crate::ecs::{Component, Entity, World};
use crate::scene::SceneEntity;
use crate::ui::icons::path;
use crate::ui::{Color, Widget};
use crate::{AppState, Category, SceneObject};
#[derive(Component, Clone, Copy, Debug)]
pub struct Grid {
pub spacing: f32,
pub major_every: f32,
pub height: f32,
pub fade_from: f32,
pub fade_to: f32,
pub line: Color,
pub major_line: Color,
pub x_axis: Color,
pub z_axis: Color,
}
impl SceneObject for Grid {
fn label(&self) -> &'static str {
"Grid"
}
fn icon(&self) -> &'static str {
path::GRID_NINE
}
fn category(&self) -> Category {
Category::Utilities
}
fn spawn(&self, app: &mut AppState) -> Entity {
app.spawn(*self)
}
}
impl Default for Grid {
fn default() -> Self {
Self {
spacing: 1.0,
major_every: 10.0,
height: 0.0,
fade_from: 30.0,
fade_to: 90.0,
line: Color::srgba(0.45, 0.45, 0.50, 0.45),
major_line: Color::srgba(0.62, 0.62, 0.68, 0.75),
x_axis: Color::srgba(0.80, 0.25, 0.30, 0.95),
z_axis: Color::srgba(0.25, 0.42, 0.85, 0.95),
}
}
}
impl Grid {
pub fn spacing(mut self, units: f32) -> Self {
self.spacing = units;
self
}
pub fn at_height(mut self, y: f32) -> Self {
self.height = y;
self
}
pub fn fade(mut self, from: f32, to: f32) -> Self {
self.fade_from = from;
self.fade_to = to;
self
}
}
pub fn grid() -> Grid {
Grid::default()
}
impl Widget for Grid {
type Output = Entity;
fn spawn(self, world: &mut World, _screen_width: f32, _screen_height: f32) -> Entity {
world.spawn((self, SceneEntity)).id()
}
}