repose_core/
indication.rs1use crate::{InteractionSource, Rect, Scene};
2
3pub trait Indication: std::fmt::Debug {}
5
6pub trait IndicationNodeFactory: Indication {
8 fn create(&self, interaction_source: &InteractionSource) -> Box<dyn IndicationDrawNode>;
9}
10
11pub trait IndicationDrawNode {
14 fn draw(&self, scene: &mut Scene, rect: Rect, alpha: f32);
17}
18
19#[deprecated]
21#[derive(Clone, Debug)]
22pub struct DebugIndication {
23 pub press_color: crate::Color,
24 pub hover_color: crate::Color,
25 pub focus_color: crate::Color,
26}
27
28impl Default for DebugIndication {
29 fn default() -> Self {
30 Self {
31 press_color: crate::Color(0, 0, 255, 40),
32 hover_color: crate::Color::TRANSPARENT,
33 focus_color: crate::Color::TRANSPARENT,
34 }
35 }
36}
37
38impl Indication for DebugIndication {}
39
40impl IndicationNodeFactory for DebugIndication {
41 fn create(&self, interaction_source: &InteractionSource) -> Box<dyn IndicationDrawNode> {
42 Box::new(DebugIndicationDrawNode {
43 interaction_source: interaction_source.clone(),
44 press_color: self.press_color,
45 hover_color: self.hover_color,
46 focus_color: self.focus_color,
47 })
48 }
49}
50
51struct DebugIndicationDrawNode {
52 interaction_source: InteractionSource,
53 press_color: crate::Color,
54 hover_color: crate::Color,
55 focus_color: crate::Color,
56}
57
58impl IndicationDrawNode for DebugIndicationDrawNode {
59 fn draw(&self, scene: &mut Scene, rect: Rect, alpha: f32) {
60 let pressed = self.interaction_source.collect_is_pressed();
61 let hovered = self.interaction_source.collect_is_hovered();
62 let _focused = self.interaction_source.collect_is_focused();
63
64 if pressed {
66 scene.nodes.push(crate::SceneNode::Rect {
67 rect,
68 brush: self
69 .press_color
70 .with_alpha_f32(self.press_color.3 as f32 / 255.0 * alpha)
71 .into(),
72 radius: [0.0; 4],
73 });
74 }
75 if hovered && !pressed {
77 scene.nodes.push(crate::SceneNode::Rect {
78 rect,
79 brush: self
80 .hover_color
81 .with_alpha_f32(self.hover_color.3 as f32 / 255.0 * alpha)
82 .into(),
83 radius: [0.0; 4],
84 });
85 }
86 }
87}