makepad_widgets/
rotated_image.rs

1use crate::{image_cache::*, makepad_draw::*, widget::*};
2
3live_design! {
4    RotatedImageBase = {{RotatedImage}} {}
5}
6
7#[derive(Live)]
8pub struct RotatedImage {
9    #[walk]
10    walk: Walk,
11    #[layout]
12    layout: Layout,
13    #[live]
14    draw_bg: DrawColor,
15
16    #[live]
17    source: LiveDependency,
18    #[live]
19    texture: Option<Texture>,
20    #[live]
21    scale: f64,
22}
23
24impl ImageCacheImpl for RotatedImage {
25    fn get_texture(&self) -> &Option<Texture> {
26        &self.texture
27    }
28
29    fn set_texture(&mut self, texture: Option<Texture>) {
30        self.texture = texture;
31    }
32}
33
34impl LiveHook for RotatedImage {
35    fn before_live_design(cx: &mut Cx) {
36        register_widget!(cx, RotatedImage)
37    }
38
39    fn after_apply(&mut self, cx: &mut Cx, _from: ApplyFrom, _index: usize, _nodes: &[LiveNode]) {
40        self.lazy_create_image_cache(cx);
41        let source = self.source.clone();
42        if source.as_str().len()>0{
43            self.load_image_dep_by_path(cx, source.as_str())
44        }
45    }
46}
47
48impl Widget for RotatedImage {
49    fn redraw(&mut self, cx: &mut Cx) {
50        self.draw_bg.redraw(cx)
51    }
52
53    fn walk(&mut self, _cx:&mut Cx) -> Walk {
54        self.walk
55    }
56
57    fn draw_walk_widget(&mut self, cx: &mut Cx2d, walk: Walk) -> WidgetDraw {
58        self.draw_walk(cx, walk)
59    }
60}
61
62impl RotatedImage {
63    pub fn draw_walk(&mut self, cx: &mut Cx2d, walk: Walk) -> WidgetDraw {
64        if let Some(image_texture) = &self.texture {
65            self.draw_bg.draw_vars.set_texture(0, image_texture);
66        }
67        self.draw_bg.draw_walk(cx, walk);
68
69        WidgetDraw::done()
70    }
71}