use crate::{InteractionSource, Rect, Scene};
pub trait Indication: std::fmt::Debug {}
pub trait IndicationNodeFactory: Indication {
fn create(&self, interaction_source: &InteractionSource) -> Box<dyn IndicationDrawNode>;
}
pub trait IndicationDrawNode {
fn draw(&self, scene: &mut Scene, rect: Rect, alpha: f32);
}
#[deprecated]
#[derive(Clone, Debug)]
pub struct DebugIndication {
pub press_color: crate::Color,
pub hover_color: crate::Color,
pub focus_color: crate::Color,
}
impl Default for DebugIndication {
fn default() -> Self {
Self {
press_color: crate::Color(0, 0, 255, 40),
hover_color: crate::Color::TRANSPARENT,
focus_color: crate::Color::TRANSPARENT,
}
}
}
impl Indication for DebugIndication {}
impl IndicationNodeFactory for DebugIndication {
fn create(&self, interaction_source: &InteractionSource) -> Box<dyn IndicationDrawNode> {
Box::new(DebugIndicationDrawNode {
interaction_source: interaction_source.clone(),
press_color: self.press_color,
hover_color: self.hover_color,
focus_color: self.focus_color,
})
}
}
struct DebugIndicationDrawNode {
interaction_source: InteractionSource,
press_color: crate::Color,
hover_color: crate::Color,
focus_color: crate::Color,
}
impl IndicationDrawNode for DebugIndicationDrawNode {
fn draw(&self, scene: &mut Scene, rect: Rect, alpha: f32) {
let pressed = self.interaction_source.collect_is_pressed();
let hovered = self.interaction_source.collect_is_hovered();
let _focused = self.interaction_source.collect_is_focused();
if pressed {
scene.nodes.push(crate::SceneNode::Rect {
rect,
brush: self
.press_color
.with_alpha_f32(self.press_color.3 as f32 / 255.0 * alpha)
.into(),
radius: [0.0; 4],
});
}
if hovered && !pressed {
scene.nodes.push(crate::SceneNode::Rect {
rect,
brush: self
.hover_color
.with_alpha_f32(self.hover_color.3 as f32 / 255.0 * alpha)
.into(),
radius: [0.0; 4],
});
}
}
}