use std::rc::Rc;
use waft_embedder::{Canvas, Color, Matrix4, Offset, TextDirection};
use waft_foundation::{App, Handle, Listener, Ref};
use waft_painting::{BorderRadius, ShapeBorderRef};
use waft_rendering::AnyRenderBox;
use crate::ink_well::{
InteractiveInkFeatureData, InteractiveInkFeatureFactory, InteractiveInkFeatureFactoryRef,
InteractiveInkFeatureLeaf, InteractiveInkFeatureLeafData, InteractiveInkFeatureRef,
};
use crate::material::{
AnyMaterialInkController, InkFeatureData, InkFeatureLeaf, InkFeatureLeafData, RectCallback,
};
#[derive(Debug)]
struct NoSplashFactory;
impl InteractiveInkFeatureFactory for NoSplashFactory {
fn create(
&self,
app: &mut App,
controller: AnyMaterialInkController,
reference_box: AnyRenderBox,
_position: Offset,
color: Color,
_text_direction: TextDirection,
_contained_ink_well: bool,
_rect_callback: Option<RectCallback>,
_border_radius: Option<BorderRadius>,
_custom_border: Option<ShapeBorderRef>,
_radius: Option<f64>,
on_removed: Option<Listener>,
) -> InteractiveInkFeatureRef {
NoSplash::new(app, controller, reference_box, color, on_removed).into_erased()
}
}
pub struct NoSplash {
ink_feature: InkFeatureData,
interactive_ink_feature: InteractiveInkFeatureData,
}
impl NoSplash {
pub fn new(
app: &mut App,
controller: AnyMaterialInkController,
reference_box: AnyRenderBox,
color: Color,
on_removed: Option<Listener>,
) -> Ref<NoSplash> {
let ink_feature = InkFeatureData::new(app, controller, reference_box, on_removed);
app.create(NoSplash {
ink_feature,
interactive_ink_feature: InteractiveInkFeatureData::new(color, None),
})
}
pub fn splash_factory() -> InteractiveInkFeatureFactoryRef {
thread_local! {
static FACTORY: InteractiveInkFeatureFactoryRef = Rc::new(NoSplashFactory);
}
FACTORY.with(Rc::clone)
}
}
impl InkFeatureLeafData for NoSplash {
fn ink_feature(&self) -> &InkFeatureData {
&self.ink_feature
}
fn ink_feature_mut(&mut self) -> &mut InkFeatureData {
&mut self.ink_feature
}
}
impl InteractiveInkFeatureLeafData for NoSplash {
fn interactive_ink_feature(&self) -> &InteractiveInkFeatureData {
&self.interactive_ink_feature
}
fn interactive_ink_feature_mut(&mut self) -> &mut InteractiveInkFeatureData {
&mut self.interactive_ink_feature
}
}
impl InkFeatureLeaf for NoSplash {
fn paint_feature(
self: Handle<Self>,
_app: &mut App,
_canvas: &mut Canvas,
_transform: &Matrix4,
) {
}
}
impl InteractiveInkFeatureLeaf for NoSplash {
fn confirm(self: Handle<Self>, app: &mut App) {
InkFeatureLeaf::dispose(self, app);
}
fn cancel(self: Handle<Self>, app: &mut App) {
InkFeatureLeaf::dispose(self, app);
}
}