#[macro_use] extern crate conrod;
extern crate find_folder;
extern crate piston_window;
fn main() {
use conrod::{Canvas, Colorable, Image, Positionable, Theme, Widget, color};
use piston_window::{EventLoop, Flip, PistonWindow, Texture, UpdateEvent, WindowSettings};
use std::sync::Arc;
type Backend = (piston_window::G2dTexture<'static>, piston_window::Glyphs);
type Ui = conrod::Ui<Backend>;
let opengl = piston_window::OpenGL::V3_2;
let mut window: PistonWindow =
WindowSettings::new("Image Widget Demonstration", [800, 600])
.opengl(opengl).exit_on_esc(true).vsync(true).samples(4).build().unwrap();
let assets = find_folder::Search::ParentsThenKids(3, 3).for_folder("assets").unwrap();
let mut ui = {
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 rust_logo = {
let path = assets.join("images/rust.png");
let factory = &mut window.factory;
let settings = piston_window::TextureSettings::new();
Arc::new(Texture::from_path(factory, &path, Flip::None, &settings).unwrap())
};
window.set_ups(60);
while let Some(event) = window.next() {
ui.handle_event(event.clone());
window.draw_2d(&event, |c, g| ui.draw_if_changed(c, g));
event.update(|_| ui.set_widgets(|mut ui| {
widget_ids!(CANVAS, RUST_LOGO);
Canvas::new().color(color::LIGHT_BLUE).set(CANVAS, &mut ui);
Image::from_texture(rust_logo.clone())
.middle_of(CANVAS)
.set(RUST_LOGO, &mut ui);
}));
}
}