use super::LayoutEngine;
use crate::{
layout::{
quad::RichTextSpan,
text_style::{DEFAULT_TEXT_COLOR, TextStyle},
},
node::{color::Color, node::Node, node_kind::TextStyleSource},
};
impl LayoutEngine {
pub(super) fn enter_foreground_scope(&self, node: &Node) -> Option<Color> {
let inherited = self.foreground.get();
let animated = match node.animation_override(crate::animation::AnimatableProperty::Foreground) {
Some(crate::animation::AnimatableValue::Color(color)) => Some(color),
_ => None,
};
let own = animated.or_else(|| {
node
.effective_foreground()
.and_then(|color| color.resolve(&self.palette.borrow()))
});
if own.is_some() {
self.foreground.set(own);
}
inherited
}
pub(super) fn leave_foreground_scope(&self, previous: Option<Color>) {
self.foreground.set(previous);
}
pub(super) fn painted_spans(&self, mut spans: Vec<RichTextSpan>) -> Vec<RichTextSpan> {
if let Some(foreground) = self.foreground.get() {
for span in spans.iter_mut().filter(|span| span.style.color == DEFAULT_TEXT_COLOR) {
span.style.color = foreground;
}
}
spans
}
pub(super) fn painted_text_style(&self, style: &TextStyleSource) -> TextStyle {
let mut resolved = style.resolve(&self.typography.borrow(), &self.palette.borrow());
if !style.names_color()
&& let Some(foreground) = self.foreground.get()
{
resolved.color = foreground;
}
resolved
}
}