use bevy::prelude::*;
use super::property::PropertyValue;
use super::{Style, Writer, WriterCtx};
#[derive(Component, Debug, Clone, PartialEq)]
pub struct StyleValue<T: PropertyValue>(pub T);
pub static STAMP_WRITER: Writer = Writer {
reads: &[],
attrs: &[],
writes: &[],
apply: apply_stamps,
};
fn apply_stamps(ctx: &WriterCtx, s: &Style, ec: &mut EntityCommands) {
for &id in ctx.styles.stamped() {
if let Some(property) = ctx.styles.by_id(id) {
property.stamp(s, ec, ctx.fresh);
}
}
}
pub(super) fn stamp<T: PropertyValue>(value: Option<&T>, ec: &mut EntityCommands, fresh: bool) {
match value {
Some(value) => {
ec.queue(crate::ui_map::set_if_neq_or_insert(StyleValue(
value.clone(),
)));
}
None if fresh => {}
None => {
ec.remove::<StyleValue<T>>();
}
}
}