-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
absolute_coordinates.rs
51 lines (46 loc) · 1.48 KB
/
absolute_coordinates.rs
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
use mq::color::{RED, WHITE};
use zgui as ui;
mod common;
#[derive(Clone, Copy, Debug)]
enum Message {
Command,
}
fn make_gui(font: mq::text::Font) -> ui::Result<ui::Gui<Message>> {
let mut gui = ui::Gui::new();
let anchor = ui::Anchor(ui::HAnchor::Right, ui::VAnchor::Bottom);
let text = ui::Drawable::text("Button", font);
let button = ui::Button::new(text, 0.2, gui.sender(), Message::Command)?;
gui.add(&ui::pack(button), anchor);
Ok(gui)
}
fn draw_scene() {
let x = 0.0;
let y = 0.0;
let r = 0.4;
let color = RED;
mq::shapes::draw_circle(x, y, r, color);
}
#[mq::main("ZGui: Absolute Coordinates Demo")]
#[macroquad(crate_rename = "mq")]
async fn main() {
let assets = common::Assets::load().await.expect("Can't load assets");
let mut gui = make_gui(assets.font).expect("Can't create the gui");
loop {
// Update the camera and the GUI.
let aspect_ratio = common::aspect_ratio();
let camera = common::make_and_set_camera(aspect_ratio);
gui.resize_if_needed(aspect_ratio);
// Handle cursor updates.
let pos = common::get_world_mouse_pos(&camera);
gui.move_mouse(pos);
if mq::input::is_mouse_button_pressed(mq::input::MouseButton::Left) {
let message = gui.click(pos);
println!("{:?}", message);
}
// Draw the GUI.
mq::window::clear_background(WHITE);
draw_scene();
gui.draw();
mq::window::next_frame().await;
}
}