use bevy::prelude::*;
use bevy::ui::FocusPolicy;
use crate::element::{Common, Element};
use crate::ext::ElementFlags;
use crate::protocol::animatable::Animatable;
use crate::protocol::units::Length;
use crate::style::Style;
use crate::style::props::{FLEX_DIRECTION, FOCUS_POLICY, GLOBAL_Z_INDEX, HEIGHT, WIDTH};
pub static NODE: Element = Element::new("node");
pub static BUTTON: Element = Element {
default_style: Some(button_style),
spawn: Some(|ctx| ctx.spawn(Button)),
..Element::new("button")
};
fn button_style() -> Style {
let mut style = Style::default();
style.set(&FOCUS_POLICY, FocusPolicy::Block);
style
}
pub static ROOT: Element = Element {
flags: ElementFlags {
pick_ignore: true,
..ElementFlags::DETACHED_ROOT
},
common: Common::IDENTITY,
default_style: Some(root_style),
spawn: Some(|ctx| ctx.spawn(crate::bridge::RRoot)),
..Element::new("root")
};
fn root_style() -> Style {
let mut style = Style::default();
style.set(&WIDTH, Animatable::Static(Length::Percent(100.0)));
style.set(&HEIGHT, Animatable::Static(Length::Percent(100.0)));
style.set(&FLEX_DIRECTION, FlexDirection::Column);
style.set(&GLOBAL_Z_INDEX, 1);
style
}