#[macro_use] extern crate conrod;
extern crate find_folder;
extern crate piston_window;
fn main() {
const WIDTH: u32 = 200;
const HEIGHT: u32 = 200;
use conrod::{Labelable, Positionable, Sizeable, Theme, Widget};
use piston_window::{EventLoop, OpenGL, PistonWindow, UpdateEvent, WindowSettings};
let opengl = OpenGL::V3_2;
let mut window: PistonWindow = WindowSettings::new("Click me!", [WIDTH, HEIGHT])
.opengl(opengl).exit_on_esc(true).build().unwrap();
window.set_ups(60);
let mut ui = conrod::Ui::new(Theme::default());
let assets = find_folder::Search::KidsThenParents(3, 5).for_folder("assets").unwrap();
let font_path = assets.join("fonts/NotoSans/NotoSans-Regular.ttf");
ui.fonts.insert_from_file(font_path).unwrap();
let mut text_texture_cache =
conrod::backend::piston_window::GlyphCache::new(&mut window, WIDTH, HEIGHT);
let image_map = conrod::image::Map::new();
let mut count = 0;
while let Some(event) = window.next() {
if let Some(e) = conrod::backend::piston_window::convert_event(event.clone(), &window) {
ui.handle_event(e);
}
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| {
if let Some(primitives) = ui.draw_if_changed(&image_map) {
fn texture_from_image<T>(img: &T) -> &T { img };
conrod::backend::piston_window::draw(c, g, primitives,
&mut text_texture_cache,
texture_from_image);
}
});
}
}