makepad_widgets/
link_label.rs1use {
2    crate::{
3        makepad_derive_widget::*,
4        widget::*,
5        makepad_draw::*,
6        button::{Button, ButtonAction}
7    }
8};
9
10live_design!{
11    LinkLabelBase = {{LinkLabel}} {}
12}
13
14#[derive(Live)]
15pub struct LinkLabel {
16    #[deref] button: Button
17}
18
19impl LiveHook for LinkLabel {
20    fn before_live_design(cx: &mut Cx) {
21        register_widget!(cx, LinkLabel)
22    }
23}
24
25impl Widget for LinkLabel {
26       fn handle_widget_event_with(
27        &mut self,
28        cx: &mut Cx,
29        event: &Event,
30        dispatch_action: &mut dyn FnMut(&mut Cx, WidgetActionItem)
31    ) {
32        self.button.handle_widget_event_with(cx,event,dispatch_action);
33    }
34    
35    fn redraw(&mut self, cx: &mut Cx) {
36        self.button.redraw(cx)
37    }
38    
39    fn walk(&mut self, cx:&mut Cx) -> Walk {
40        self.button.walk(cx)
41    }
42    
43    fn draw_walk_widget(&mut self, cx: &mut Cx2d, walk: Walk) -> WidgetDraw {
44        self.button.draw_walk_widget(cx, walk)
45    }
46    
47    fn text(&self)->String{
48        self.button.text()
49    }
50    
51    fn set_text(&mut self, v:&str){
52        self.button.set_text(v);
53    }
54}
55
56#[derive(Clone, PartialEq, WidgetRef)]
57pub struct LinkLabelRef(WidgetRef);
58
59impl LinkLabelRef {
60    pub fn clicked(&self, actions:&WidgetActions) -> bool {
61        if let Some(inner) = self.borrow(){ 
62            if let Some(item) = actions.find_single_action(inner.button.widget_uid()) {
63                if let ButtonAction::Clicked = item.action() {
64                    return true
65                }
66            }
67        }
68        false
69    }
70    
71    pub fn pressed(&self, actions:&WidgetActions) -> bool {
72        if let Some(inner) = self.borrow(){ 
73            if let Some(item) = actions.find_single_action(inner.button.widget_uid()) {
74                if let ButtonAction::Pressed = item.action() {
75                    return true
76                }
77            }
78        }
79        false
80    }
81}