use std::any::TypeId;
use bevy::prelude::*;
use super::AnyStyleProperty;
use crate::ext::ElementFlags;
use crate::style::Style;
pub type ComponentKey = fn() -> (TypeId, &'static str);
pub fn owns<C: Component>() -> (TypeId, &'static str) {
(TypeId::of::<C>(), std::any::type_name::<C>())
}
pub struct Writer {
pub reads: &'static [&'static dyn AnyStyleProperty],
pub attrs: &'static [&'static dyn crate::element::AnyAttribute],
pub writes: &'static [ComponentKey],
pub apply: fn(&WriterCtx, &Style, &mut EntityCommands),
}
pub struct WriterCtx<'a> {
pub promoted: bool,
pub fresh: bool,
pub kind: &'a str,
pub flags: ElementFlags,
pub assets: &'a AssetServer,
pub(crate) fonts: &'a crate::plugin::Fonts,
pub(crate) styles: &'a super::StyleRegistry,
pub(crate) element: &'a crate::element::ElementInfo,
pub attrs: &'a crate::element::Attrs,
pub events: &'a crate::element::Attrs,
pub id: crate::protocol::NodeId,
}
impl WriterCtx<'_> {
pub fn attr<T: super::PropertyValue>(
&self,
attribute: &crate::element::Attribute<T>,
) -> Option<&T> {
self.attrs.get(attribute)
}
pub fn event<T: super::PropertyValue>(
&self,
attribute: &crate::element::Attribute<T>,
) -> Option<&T> {
self.events.get(attribute)
}
pub fn text(&self) -> bool {
self.flags.text != crate::ext::TextRole::None
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct WriterMask(pub u64);
impl WriterMask {
pub const NONE: Self = Self(0);
pub const ALL: Self = Self(u64::MAX);
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
pub const fn without(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
pub const fn intersection(self, other: Self) -> Self {
Self(self.0 & other.0)
}
pub const fn intersects(self, other: Self) -> bool {
self.0 & other.0 != 0
}
pub const fn is_empty(self) -> bool {
self.0 == 0
}
}