~saiko/game

ref: c11aa26b4a8d8866d1487be434e52908c03fb7ef game/src/ui/controller.rs -rw-r--r-- 1.0 KiB
c11aa26b2xsaiko Don't have this inside the trait 11 months ago
                                                                                
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
use crate::ui::access::UiAccess;
use crate::ui::graphics::{DrawPreview, Graphics};
use crate::ui::rescap::ResizeCapabilities;

pub trait UiController {
    type Elements: UiAccess + 'static;

    fn create_elements(&self) -> Self::Elements;

    fn update(&mut self, elements: &mut Self::Elements);

    fn resize(&mut self, elements: &mut Self::Elements, g: &Graphics, width: u32, height: u32);

    fn get_resize_capabilities(&self, elements: &Self::Elements, g: &DrawPreview) -> ResizeCapabilities;

    fn draw(&mut self, elements: &mut Self::Elements, g: &mut Graphics) {
        draw_elements(elements, g);
    }

    fn click(&mut self, x: i32, y: i32) -> bool { true }

    fn open(&mut self) {}

    fn close(&mut self) {}

    // TODO implement redraw on demand
    fn is_animated(&self) -> bool { true }
}

pub fn draw_elements<T>(elements: &mut T, g: &mut Graphics)
    where T: UiAccess + 'static {

    use crate::ui::access::Values;

    let all = T::Access::values();
    for el in all {
        elements.get_element_mut(*el).draw(g);
    }
}