#[macro_use] extern crate conrod;
extern crate find_folder;
extern crate piston_window;
fn main() {
use conrod::{Labelable, Positionable, Sizeable, Theme, Widget};
use piston_window::{EventLoop, OpenGL, PistonWindow, UpdateEvent, WindowSettings};
type Backend = (piston_window::G2dTexture<'static>, piston_window::Glyphs);
type Ui = conrod::Ui<Backend>;
let opengl = OpenGL::V3_2;
let mut window: PistonWindow = WindowSettings::new("Click me!", [200, 200])
.opengl(opengl).exit_on_esc(true).build().unwrap();
let mut ui = {
let assets = find_folder::Search::KidsThenParents(3, 5)
.for_folder("assets").unwrap();
let font_path = assets.join("fonts/NotoSans/NotoSans-Regular.ttf");
let theme = Theme::default();
let glyph_cache = piston_window::Glyphs::new(&font_path, window.factory.clone()).unwrap();
Ui::new(glyph_cache, theme)
};
let mut count = 0;
window.set_ups(60);
while let Some(event) = window.next() {
ui.handle_event(event.clone());
event.update(|_| ui.set_widgets(|ref mut ui| {
widget_ids!(CANVAS, COUNTER);
conrod::Canvas::new().pad(40.0).set(CANVAS, ui);
conrod::Button::new()
.middle_of(CANVAS)
.w_h(80.0, 80.0)
.label(&count.to_string())
.react(|| count += 1)
.set(COUNTER, ui);
}));
window.draw_2d(&event, |c, g| ui.draw_if_changed(c, g));
}
}