extern crate glfw;
extern crate gust_render as gust;
use gust::prelude::*;
use std::cell::RefCell;
use std::rc::Rc;
fn main() {
let mut window = Window::new(gust::WIDTH, gust::HEIGHT, "Hello");
let event_handler = EventHandler::new(&window);
let font = Rc::new(RefCell::new(
Font::from_path("examples/font/test.ttf").unwrap(),
));
let mut text = Text::new(&font);
text.set_content("Welcome to Gust you can write text and\na lot more !\t(Like tabs)");
text.set_position(Vector::new(100.0, 100.0));
let mut text2 = Text::from_str(&font, "Salut !");
text2.set_position(Vector::new(200.0, 200.0));
text2.update();
window.set_clear_color(Color::new(0.0, 0.0, 0.0));
window.enable_cursor();
window.poll(None);
while window.is_open() {
text.update();
window.poll_events();
event_handler
.fetch()
.for_each(|event| handle(&event, &mut window, &mut text));
window.clear();
window.draw(&text);
window.draw(&text2);
window.display();
}
}
fn handle(event: &Event, window: &mut Window, text: &mut Text) {
match event.1 {
Events::Key(Key::Escape, _, Action::Press, _) => window.close(),
Events::CursorPos(x, y) => {
text.set_position(Vector::new(x as f32, y as f32));
}
_ => {}
}
}