#[macro_use] extern crate conrod;
extern crate find_folder;
fn main() {
const WIDTH: u32 = 200;
const HEIGHT: u32 = 200;
use conrod::{widget, Labelable, Positionable, Sizeable, Widget};
use conrod::backend::piston::{self, Window, WindowEvents, OpenGL};
use conrod::backend::piston::event::UpdateEvent;
let opengl = OpenGL::V3_2;
let mut window: Window = piston::window::WindowSettings::new("Click me!", [WIDTH, HEIGHT])
.opengl(opengl).exit_on_esc(true).build().unwrap();
let mut events = WindowEvents::new();
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
widget_ids!(struct Ids { canvas, counter });
let ids = Ids::new(ui.widget_id_generator());
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 = 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_event(&mut events) {
if let Some(e) = piston::window::convert_event(event.clone(), &window) {
ui.handle_event(e);
}
event.update(|_| {
let ui = &mut ui.set_widgets();
widget::Canvas::new().pad(40.0).set(ids.canvas, ui);
for _click in widget::Button::new()
.middle_of(ids.canvas)
.w_h(80.0, 80.0)
.label(&count.to_string())
.set(ids.counter, ui)
{
count += 1;
}
});
window.draw_2d(&event, |c, g| {
if let Some(primitives) = ui.draw_if_changed() {
fn texture_from_image<T>(img: &T) -> &T { img };
piston::window::draw(c, g, primitives,
&mut text_texture_cache,
&image_map,
texture_from_image);
}
});
}
}