mod cache_state;
pub use cache_state::*;
mod cached_properties;
pub use cached_properties::*;
mod colors;
mod property_meta;
pub use property_meta::*;
mod property_token;
pub use property_token::*;
mod property_values;
pub use property_values::*;
mod selected_entities;
pub use selected_entities::*;
mod stylesheet_state;
pub use stylesheet_state::*;
pub(crate) mod impls;
pub(crate) mod text;
use crate::prelude::{
BevyCssError,
StyleSheetAsset,
};
use bevy::{
ecs::query::{
QueryItem,
QueryFilter,
},
prelude::{
Assets, AssetServer,
Commands,
Local,
Query,
Res,
},
};
use std::any::Any;
use bevy::ecs::query::QueryData;
pub trait Property:
Default + Sized + Send + Sync + 'static
{
type Cache: Default + Any + Send + Sync;
type Components: QueryData;
type Filters: QueryFilter;
fn name(
) -> &'static str;
fn parse(
values: &PropertyValues
) -> Result<Self::Cache, BevyCssError>;
fn apply(
cache: &Self::Cache,
components: QueryItem<Self::Components>,
asset_server: &AssetServer,
commands: &mut Commands,
);
fn apply_system(
mut local: Local<PropertyMeta<Self>>,
assets: Res<Assets<StyleSheetAsset>>,
apply_sheets: Res<StyleSheetState>,
mut q_nodes: Query<Self::Components, Self::Filters>,
asset_server: Res<AssetServer>,
mut commands: Commands,
) {
for (entity, style) in apply_sheets.iter()
{
let source = match style.get_key_value(Self::name())
{
Some((_prop, source)) => source,
None => continue,
};
let rules = match assets.get(&source.styleheet)
{
Some(asset) => asset,
None => continue,
};
let cached_value = match local.get_or_parse(rules, &source.selector)
{
CacheState::Ok(cached) => cached,
_other => continue,
};
let components = match q_nodes.get_mut(*entity)
{
Ok(cmp) => cmp,
Err(_) => continue,
};
Self::apply(cached_value, components, &asset_server, &mut commands);
}
}
}