logo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#![allow(unused_variables)]
use std::fmt::Debug;

use crate::elements::WidgetComponent;

/// A widget renderer interface.
pub trait WidgetRenderer<T>: Debug {
    // fn rendering(&self) -> Rendering;
    // fn control(&self) -> WidgetComponent;
    fn render(&self, widget: &T);

    fn post_render(&self, widget: &T) {}
}

/// The basic implementation for a control Renderer.
/// This includes convenience functions and implementation
/// of the base control events which are called
/// to simplify integration. Be aware of the timing of signals.
/// Implementation should contain:
///
/// rendering: Rendering,
/// control: WidgetComponent,
pub trait BaseRender
where
    Self: AsRef<WidgetComponent>,
{
    // fn new(render: Rendering, control: WidgetComponent) {
    //     control = control;
    //     rendering = render;

    //     control.oncreate.listen(internal_connect);
    // }

    /// Don"t need to call this from Render subclasses
    fn internal_connect(&self) {
        // let control = self.as_ref();
        // control.canvas.onscalechange.listen(onscale);
        // control.onvisible.listen(onvisible);
        // control.ondepth.listen(ondepth);
        // control.ondestroy.listen(ondestroy);
        // control.onclip.listen(onclip);
        // control.onchildadd.listen(onchildadd);
        // control.onchildremove.listen(onchildremove);
        // control.onbounds.listen(onbounds);
        // control.ondestroy.listen(internal_disconnect);
    }

    /// Don"t need to call this from Render subclasses
    fn internal_disconnect(&self) {
        // let control = self.as_ref();
        // control.canvas.onscalechange.remove(onscale);
        // control.onvisible.remove(onvisible);
        // control.ondepth.remove(ondepth);
        // control.ondestroy.remove(ondestroy);
        // control.onclip.remove(onclip);
        // control.onchildadd.remove(onchildadd);
        // control.onchildremove.remove(onchildremove);
        // control.onbounds.remove(onbounds);

        // control.oncreate.remove(internal_connect);
        // control.ondestroy.remove(internal_disconnect);
    }

    #[inline]
    fn scale(&self) -> f32 {
        let control = self.as_ref();
        if let Some(canvas) = control.canvas.as_ref() {
            canvas.scale()
        } else {
            1.0
        }
    }

    #[inline]
    fn sx(&self) -> f32 {
        let control = self.as_ref();
        if let Some(canvas) = control.canvas.as_ref() {
            control.x * canvas.scale()
        } else {
            control.x
        }
    }

    #[inline]
    fn sy(&self) -> f32 {
        let control = self.as_ref();
        if let Some(canvas) = control.canvas.as_ref() {
            control.y * canvas.scale()
        } else {
            control.y
        }
    }

    #[inline]
    fn sw(&self) -> f32 {
        let control = self.as_ref();
        if let Some(canvas) = control.canvas.as_ref() {
            control.w * canvas.scale()
        } else {
            control.w
        }
    }

    #[inline]
    fn sh(&self) -> f32 {
        let control = self.as_ref();
        if let Some(canvas) = control.canvas.as_ref() {
            control.h * canvas.scale()
        } else {
            control.h
        }
    }

    #[inline]
    fn cs(&self, value: f32) -> f32 {
        let control = self.as_ref();
        if let Some(canvas) = control.canvas.as_ref() {
            value * canvas.scale()
        } else {
            value
        }
    }

    fn onscale(&self, scale: f32, prev: f32) {}
    fn onvisible(&self, value: bool) {}
    fn ondepth(&self, depth: f32) {}
    fn ondestroy(&self) {}
    fn onbounds(&self) {}
    fn onclip(&self, disable: bool, x: f32, y: f32, w: f32, h: f32) {}
    fn onchildadd(&self, control: WidgetComponent) {}
    fn onchildremove(&self, control: WidgetComponent) {}
}