hello/
hello.rs

1use ezui::mouse::*;
2use ezui::standard::*;
3use ezui::widget::*;
4use ezui::*;
5
6use ezui::glium::glutin;
7use ezui::glium::DisplayBuild;
8use ezui::glium::Surface;
9
10pub const FONT_RAW: &'static [u8] = include_bytes!("resource/OpenSans-Regular.ttf");
11pub const KNOB_BASE_WHITE_RAW: &'static [u8] = include_bytes!("resource/white.png");
12pub const KNOB_BASE_BLACK_RAW: &'static [u8] = include_bytes!("resource/black.png");
13pub const KNOB_LIGHT_RAW: &'static [u8] = include_bytes!("resource/light.png");
14
15fn main() {
16    let display = glutin::WindowBuilder::new()
17        .with_dimensions(640, 640)
18        .with_vsync()
19        .build_glium()
20        .unwrap();
21
22    let mut ui = Ui::new(&display);
23
24    let font =
25        FontTexture::new(&display, FONT_RAW, 50, FontTexture::ascii_character_list()).unwrap();
26
27    let text_display = ui.build_text_display(&font, "hello");
28
29    let mut text = UiTextBuilder::default()
30        .position((0.1, 0.1))
31        .size((0.15, 0.1))
32        .text(text_display)
33        .color((0.1, 0.1, 0.1, 1.0))
34        .build()
35        .unwrap();
36
37    let mut button1 = UiButtonBuilder::default()
38        .position((0.1, 0.1))
39        .size((0.15, 0.1))
40        .build()
41        .unwrap();
42
43    let mut button2 = UiButtonBuilder::default()
44        .position((0.5, 0.5))
45        .size((0.3, 0.3))
46        .build()
47        .unwrap();
48
49    let texture = SimpleTexture::from(&KNOB_BASE_WHITE_RAW, ImageFormat::PNG, &display).unwrap();
50    let knob_base = UiTextureBuilder::default()
51        .position((0.5, 0.5))
52        .size((0.3, 0.3))
53        .rotation(0.0)
54        .texture(&texture)
55        .build()
56        .unwrap();
57
58    let texture = SimpleTexture::from(&KNOB_LIGHT_RAW, ImageFormat::PNG, &display).unwrap();
59    let mut knob_light = UiTextureBuilder::default()
60        .position((0.5, 0.5))
61        .size((0.3, 0.3))
62        .rotation(0.0)
63        .texture(&texture)
64        .build()
65        .unwrap();
66
67    loop {
68        ui.update(|target, mouse, system| {
69            button1.update(&mouse);
70            button2.update(&mouse);
71
72            target.clear_color(0.4, 0.4, 0.4, 1.0);
73
74            match *button1.left() {
75                ButtonState::Pressed(_x, _y) => {
76                    text.set_text("world");
77                    text.color.0 += mouse.delta_position().0 * 2.55;
78                    text.color.1 += mouse.delta_position().1 * 2.55;
79                }
80                _ => {
81                    text.set_text("hello");
82                }
83            }
84            match *button1.right() {
85                ButtonState::Pressed(_x, _y) => {
86                    text.set_text("MOVE!");
87                    text.position.0 += mouse.delta_position().0 * 5.0;
88                    text.position.1 += mouse.delta_position().1 * 5.0;
89                    button1.position.0 += mouse.delta_position().0 * 5.0;
90                    button1.position.1 += mouse.delta_position().1 * 5.0;
91                }
92                _ => {
93                    text.set_text("hello");
94                }
95            }
96
97            match *button2.left() {
98                ButtonState::Pressed(_x, _y) => {
99                    knob_light.rotation += mouse.delta_position().1 * 360.0;
100                }
101                _ => (),
102            }
103            match *button2.right() {
104                ButtonState::Pressed(_x, _y) => {
105                    knob_light.rotation += mouse.delta_position().1 * 360.0 * 2.0;
106                }
107                _ => (),
108            }
109
110            text.draw(target, system);
111            knob_base.draw(target, system);
112            knob_light.draw(target, system);
113        });
114    }
115}