freya_material_design/
tile.rs1use std::time::Duration;
2
3use freya_components::tile::Tile;
4use freya_core::prelude::*;
5use torin::size::Size;
6
7use crate::ripple::Ripple;
8
9pub trait TileRippleExt {
28 fn ripple(self) -> RippleTile;
31}
32
33impl TileRippleExt for Tile {
34 fn ripple(self) -> RippleTile {
35 RippleTile {
36 tile: self,
37 ripple: Ripple::new(),
38 }
39 }
40}
41
42#[derive(Clone, PartialEq)]
47pub struct RippleTile {
48 tile: Tile,
49 ripple: Ripple,
50}
51
52impl ChildrenExt for RippleTile {
53 fn get_children(&mut self) -> &mut Vec<Element> {
54 self.tile.get_children()
55 }
56}
57
58impl KeyExt for RippleTile {
59 fn write_key(&mut self) -> &mut DiffKey {
60 self.tile.write_key()
61 }
62}
63
64impl RippleTile {
65 pub fn color(mut self, color: impl Into<Color>) -> Self {
67 self.ripple = self.ripple.color(color);
68 self
69 }
70
71 pub fn duration(mut self, duration: Duration) -> Self {
73 self.ripple = self.ripple.duration(duration);
74 self
75 }
76
77 pub fn leading(mut self, leading: impl Into<Element>) -> Self {
79 self.tile = self.tile.leading(leading);
80 self
81 }
82}
83
84impl Component for RippleTile {
85 fn render(&self) -> impl IntoElement {
86 let tile = self.tile.clone();
87
88 let mut ripple = self.ripple.clone();
89 ripple.get_children().clear();
90 ripple.get_children().push(tile.into());
91 ripple.width(Size::fill())
92 }
93
94 fn render_key(&self) -> DiffKey {
95 self.tile.render_key()
96 }
97}