hello_world/
hello_world.rs

1extern crate juke;
2
3use juke::{egui::Context, resources::ResourceManager, *};
4use std::time::Duration;
5
6fn main() {
7    Engine::new("Hello, World! - ESC to exit", 256, 144, 4)
8        .ui(ui)
9        .run(update);
10}
11
12fn update(f: FrameContext, resources: &mut ResourceManager) {
13    for pixel in f.buffer.chunks_exact_mut(4) {
14        pixel[0] = 0xff; // R
15        pixel[1] = 0x00; // G
16        pixel[2] = 0xff; // B
17        pixel[3] = 0xff; // A
18    }
19
20    resources.set("frame_time", f.delta);
21}
22
23fn ui(ctx: &Context, resources: &mut ResourceManager) {
24    egui::Window::new("Hello, egui!").show(ctx, |ui| {
25        ui.label("This example demonstrates using egui with juke.");
26
27        ui.separator();
28
29        ui.horizontal(|ui| {
30            let delta = resources.get::<Duration>("frame_time").unwrap();
31
32            ui.spacing_mut().item_spacing.x /= 2.0;
33            ui.label(format!("Frame Time: {:?}", delta));
34            ui.label(format!("FPS: {}", 1. / delta.as_secs_f32()));
35        });
36    });
37}