#[macro_use] extern crate conrod;
extern crate find_folder;
mod support;
use conrod::backend::piston::gfx::{GfxContext, G2dTexture, Texture, TextureSettings, Flip};
use conrod::backend::piston::{self, Window, WindowEvents, OpenGL};
use conrod::backend::piston::event::UpdateEvent;
fn main() {
const WIDTH: u32 = support::WIN_W;
const HEIGHT: u32 = support::WIN_H;
let mut window: Window =
piston::window::WindowSettings::new("All Widgets - Piston Backend", [WIDTH, HEIGHT])
.opengl(OpenGL::V3_2) .samples(4)
.exit_on_esc(true)
.vsync(true)
.build()
.unwrap();
let mut events = WindowEvents::new();
let mut app = support::DemoApp::new();
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64])
.theme(support::theme())
.build();
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 ids = support::Ids::new(ui.widget_id_generator());
let image_map = support::image_map(&ids, load_rust_logo(&mut window.context));
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 mut ui = ui.set_widgets();
support::gui(&mut ui, &ids, &mut app);
});
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);
}
});
}
}
fn load_rust_logo(context: &mut GfxContext) -> G2dTexture<'static> {
let assets = find_folder::Search::ParentsThenKids(3, 3).for_folder("assets").unwrap();
let path = assets.join("images/rust.png");
let factory = &mut context.factory;
let settings = TextureSettings::new();
Texture::from_path(factory, &path, Flip::None, &settings).unwrap()
}