use egui::{epaint::{TextShape, Color32}, Shape, Pos2, Stroke, Ui, WidgetText};
use crate::predicate;
#[derive(Debug, Clone, PartialEq)]
pub struct TextShapePredicate {
pub pos: Pos2,
pub underline: Stroke,
pub fallback_color: Color32,
pub override_text_color: Option<Color32>,
pub opacity_factor: f32,
pub angle: f32,
pub text: String
}
impl predicate::ShapePredicate for TextShapePredicate {
fn finalise(&self, ui: &Ui) -> Option<Shape> {
let valign = ui.text_valign();
let widget_text: WidgetText = self.text.clone().into();
let layout_job = widget_text.into_layout_job(
ui.style(), egui::FontSelection::Default, valign
);
let galley = ui.fonts(|fonts| fonts.layout_job(layout_job));
Some(TextShape {
pos: self.pos,
galley,
underline: self.underline,
fallback_color: self.fallback_color,
override_text_color: self.override_text_color,
opacity_factor: self.opacity_factor,
angle: self.angle
}.into())
}
}