use beet_core::prelude::*;
use beet_flow::prelude::*;
use std::borrow::Cow;
use std::marker::PhantomData;
#[action(set_text_on_run::<F>)]
#[derive(Debug, Clone, PartialEq, Component, Reflect)]
#[reflect(Component)]
pub struct SetTextOnRun<F: Component> {
pub value: Cow<'static, str>,
#[reflect(ignore)]
phantom: PhantomData<F>,
}
impl<F: Component> SetTextOnRun<F> {
pub fn new(value: impl Into<Cow<'static, str>>) -> Self {
Self {
value: value.into(),
phantom: PhantomData,
}
}
}
fn set_text_on_run<F: Component>(
ev: On<GetOutcome>,
query: Query<&SetTextOnRun<F>, Added<Running>>,
mut texts: Query<&mut Text, With<F>>,
mut text_spans: Query<&mut TextSpan, With<F>>,
) -> Result {
let set_text_on_run = query.get(ev.target())?;
for mut text in texts.iter_mut() {
**text = set_text_on_run.value.to_string();
}
for mut text in text_spans.iter_mut() {
**text = set_text_on_run.value.to_string();
}
Ok(())
}