use crate::ecs::ui::components::UiNodeContent;
use crate::ecs::world::World;
pub fn ui_theme_apply_system(world: &mut World) {
if !world.resources.retained_ui.enabled {
return;
}
let generation = world.resources.retained_ui.theme_state.generation;
if generation
== world
.resources
.retained_ui
.theme_state
.last_applied_generation
{
return;
}
world
.resources
.retained_ui
.theme_state
.last_applied_generation = generation;
let theme = world
.resources
.retained_ui
.theme_state
.active_theme()
.clone();
let entities: Vec<freecs::Entity> = world
.ui
.query_entities(crate::ecs::world::UI_THEME_BINDING)
.collect();
for entity in entities {
let binding = match world.ui.get_ui_theme_binding(entity) {
Some(binding) => binding.clone(),
None => continue,
};
if let Some(node_color) = world.ui.get_ui_node_color_mut(entity) {
for (state_index, role) in binding.color_roles.iter().enumerate() {
if let Some(role) = role {
node_color.colors[state_index] = Some(role.resolve(&theme));
}
}
}
if let Some(border_role) = binding.border_color_role
&& let Some(content) = world.ui.get_ui_node_content_mut(entity)
&& let UiNodeContent::Rect { border_color, .. } = content
{
*border_color = border_role.resolve(&theme);
}
}
}