#ui #graphics #gamedev #render

yakui-miniquad

A library integrating yakui with miniquad

12 releases

0.3.1 Apr 29, 2024
0.3.0 Apr 29, 2024
0.2.4 Nov 28, 2023
0.1.4 Nov 8, 2023

#533 in GUI

Download history 11/week @ 2024-02-27 7/week @ 2024-03-05 11/week @ 2024-03-12 1/week @ 2024-03-26 30/week @ 2024-04-02 135/week @ 2024-04-23 463/week @ 2024-04-30

598 downloads per month
Used in yakui-macroquad

MIT license

35KB
685 lines

yakui-miniquad

CI Docs Crates.io version

This is a simple library integrating yakui with miniquad, allowing you to use yakui with your miniquad projects easily.

I'm happy to accept contributions in the form of fixes or improvements, just be nice :)

If you're interested in the version usable with macroquad directly, it's here: yakui-macroquad!

Version

This version is for miniquad 0.4 and yakui 0.2.0.

Example

See the example, you can also cargo run --example hello-world to test the example.

License

See LICENSE


lib.rs:

yakui-miniquad integrates yakui with miniquad.

Usage

In order to use this library, create an instance of YakuiMiniQuad and call its event-handler functions from your miniquad::EventHandler implementation.

Here's an example which just renders "hello, world" in the middle of the screen.

use std::ops::DerefMut;

use miniquad::*;
use miniquad::window::new_rendering_backend;
use yakui::{widgets::Pad, Color};

use yakui_miniquad::*;

struct Stage {
    ctx: Box<Context>,
    yakui_mq: YakuiMiniQuad,
}

impl Stage {
    pub fn new(mut ctx: Box<Context>) -> Stage {
        let yakui_mq = YakuiMiniQuad::new(ctx.deref_mut());
        Stage {
            ctx,
            yakui_mq
        }
    }
}

impl EventHandler for Stage {
    fn update(&mut self) {
        self.yakui_mq.start();

        yakui::center(|| {
            yakui::colored_box_container(Color::CORNFLOWER_BLUE, || {
                yakui::pad(Pad::all(16.0), || {
                    yakui::text(32.0, "hello, world!");
                });
            });
        });

        self.yakui_mq.finish();
    }

    fn draw(&mut self) {
        self.ctx.begin_default_pass(Default::default());

        // draw some stuff before the UI?

        self.yakui_mq.draw(self.ctx.deref_mut());

        // ... draw some stuff after the UI!

        self.ctx.end_render_pass();

        self.ctx.commit_frame();
    }

    fn resize_event(&mut self, width: f32, height: f32) {
        self.yakui_mq.resize_event(width, height);
    }

    fn mouse_motion_event(&mut self, x: f32, y: f32) {
        self.yakui_mq.mouse_motion_event(x, y);
    }

    fn mouse_wheel_event(&mut self, x: f32, y: f32) {
        self.yakui_mq.mouse_wheel_event(x, y);
    }

    fn mouse_button_down_event(&mut self, button: MouseButton, x: f32, y: f32) {
        self.yakui_mq.mouse_button_down_event(button, x, y);
    }

    fn mouse_button_up_event(&mut self, button: MouseButton, x: f32, y: f32) {
        self.yakui_mq.mouse_button_up_event(button, x, y);
    }

    fn char_event(&mut self, character: char, keymods: KeyMods, repeat: bool) {
        self.yakui_mq.char_event(character, keymods, repeat);
    }

    fn key_down_event(
        &mut self,
        keycode: KeyCode,
        keymods: KeyMods,
        repeat: bool,
    ) {
        self.yakui_mq.key_down_event(keycode, keymods, repeat);
    }

    fn key_up_event(&mut self, keycode: KeyCode, keymods: KeyMods) {
        self.yakui_mq.key_up_event(keycode, keymods);
    }
}

fn main() {
    miniquad::start(conf::Conf::default(), || {
        Box::new(Stage::new(new_rendering_backend()))
    });
}

Dependencies

~8.5MB
~208K SLoC