makepad_widgets/
tab_close_button.rs1use crate::makepad_draw::*;
2
3live_design!{
4    TabCloseButtonBase = {{TabCloseButton}} {}
5}
6
7#[derive(Live, LiveHook)]
8pub struct TabCloseButton {
9    #[live] draw_button: DrawQuad,
10    #[animator] animator: Animator,
11
12    #[walk] walk: Walk
13}
14
15impl TabCloseButton {
16    
17    pub fn draw(&mut self, cx: &mut Cx2d) {
18        self.draw_button.draw_walk(
19            cx,
20            self.walk
21        );
22    }
23    
24    pub fn handle_event(
25        &mut self,
26        cx: &mut Cx,
27        event: &Event,
28    ) -> TabCloseButtonAction {
29        self.animator_handle_event(cx, event);
30        match event.hits(cx, self.draw_button.area()) {
31            Hit::FingerHoverIn(_) => {
32                self.animator_play(cx, id!(hover.on));
33                return TabCloseButtonAction::HoverIn;
34            }
35            Hit::FingerHoverOut(_)=>{
36                self.animator_play(cx, id!(hover.off));
37                return TabCloseButtonAction::HoverOut;
38            }
39            Hit::FingerDown(_) => return TabCloseButtonAction::WasPressed,
40            _ => {}
41        }
42        TabCloseButtonAction::None
43    }
44}
45
46pub enum TabCloseButtonAction {
47    None,
48    WasPressed,
49    HoverIn,
50    HoverOut,
51}