Rust-Nuklear rust: nuklear-rust — Rust bindings for Nuklear

nuklear-rust

Latest Version

The bindings to the Nuklear 2D immediate GUI library.

Currently beta.

Drawing backends:

All examples are based on the extended example of the original library.

API suggestions, PRs and improvement ideas are welcome!

Comments

  • Remove logger
    Remove logger

    Oct 1, 2018

    Ain't help a lot, although hogs resources.

    Reply
  • gfx backend mouse input is scaled by 2 on Mac
    gfx backend mouse input is scaled by 2 on Mac

    Feb 28, 2019

    This must be a hidpi issue, but on Mac on a retina display the mouse input positions are all doubled (or equivalently, the output image is doubled).

    That is, if you click 1cm to the right the left window edge, the click will be received by the widget 2cm to the right of the window edge. The doubling is relative to the window, not the screen. Hope that's clear!

    bug 
    Reply
  • Pulled from Crates.io, nuklear-sys build script panics
    Pulled from Crates.io, nuklear-sys build script panics

    Jun 18, 2019

    When pulling from Git, there is no issue, it is exclusively when nuklear-sys is imported from a Cargo repository.

    Panic with trace: https://gist.github.com/khionu/cac71a3176ed42840caa79b53af26bbd

    OS: Win 10 Pro (1903) Compiler: 1.35.0 (3c235d560 2019-05-20) Toolchain: stable-x86_64-pc-windows-msvc

    Reply
  • How draw a line
    How draw a line

    Sep 4, 2019

    How draw object on background? Not in windows but on background?

    Do You know how do this in C and Rust?

    Reply
  • SDL2
    SDL2

    Sep 4, 2019

    In future SDL2 backend will be created?

    Reply
  • style_push_* API seem to be unusable
    style_push_* API seem to be unusable

    Feb 6, 2020

    Here's an example of using this API in C: https://github.com/Immediate-Mode-UI/Nuklear/blob/d74ffc7157890fe1e16c09e3cb3e5103f5067720/demo/overview.c#L957-L958

        nk_style_push_vec2(ctx, &ctx->style.window.spacing, nk_vec2(0,0));
        nk_style_push_float(ctx, &ctx->style.button.rounding, 0);
    

    This doesn't seem like it would work in Rust, since it requires mutable references to ctx and ctx->style.window.spacing at the same time (mutable aliasing).

    I am able to push a value into a cloned struct, then copy it to the context with a setter, but this is more code (and more copying):

        let mut spacing = ctx.style().window().spacing().clone();
        ctx.style_push_vec2(&mut spacing, Vec2 { x: 0.0, y: 0.0 });
        ctx.style_mut().window_mut().set_spacing(spacing);
    
        let mut rounding = ctx.style().button().rounding();
        ctx.style_push_float(&mut rounding, 0.0);
        ctx.style_mut().button_mut().set_rounding(rounding);
    

    Seems there should be a better way?

    Reply
  • Crash on i686 target
    Crash on i686 target

    Jan 14, 2020

    At first, I build the gdi demo by nightly-x86_64-pc-windows-msvc, all good, but got crash when build by nightly-i686-pc-windows-msvc. And I debugged to figure out the crash palce is nk_init, relate to nk_handle. In nuklear-sys-4.0.4:

    pub union nk_handle {
        pub ptr: *mut ::std::os::raw::c_void,
        pub id: ::std::os::raw::c_int,
        _bindgen_union_align: u64,   
    }
    

    this cause nk_handle take 8 bytes in i686 build, but the C def is

    typedef union {void *ptr; int id;} nk_handle;
    

    it only take 4 bytes in i686 build, so that's the problem!

    bug 
    Reply
  • Linux or SDL2
    Linux or SDL2

    May 11, 2019

    Is possible run this in SDL2 or native in linux?

    Reply
  • Please add an example of using GDI+ backend
    Please add an example of using GDI+ backend

    Feb 7, 2017

                                                                                                                                                                                                            enhancement 
    Reply
  • No way of accessing clipboard struct on context
    No way of accessing clipboard struct on context

    May 12, 2019

    On the context struct the internal nk_context struct is not accessable. but some members should be mutably accessable according to nuklear.

    From the nk_context struct in c: /* public: can be accessed freely */

    And without that access i dont see a way to setup the clipboard callbacks

    enhancement v0.6.2 
    Reply
  • Documentation on initializing fonts?
    Documentation on initializing fonts?

    Jan 14, 2018

    Just trying to run a simple example, but I'm having a bit of trouble with initializing everything. I can do most of it through nuklear-rust, but I can't seem to find how I should initialize a nuklear_rust::NkUserFont.

    Here's what I have right now:

    extern crate glium;
    extern crate nuklear_backend_glium;
    extern crate nuklear_rust as nk;
    
    use glium::glutin;
    
    fn main() {
        let mut glutin_events_loop = glutin::EventsLoop::new();
        let mut glium_display = glium::Display::new(
            glutin::WindowBuilder::new(),
            glutin::ContextBuilder::new(),
            &glutin_events_loop,
        ).unwrap();
    
        let draw_buffer = nk::NkBuffer::new(&mut nk::NkAllocator::new_vec());
    
        let font = {
            let mut font = nk::NkUserFont::default();
    
            // how to initialize font here?
            font
        };
    
        let mut nk_context = nk::NkContext::new(&mut nk::NkAllocator::new_vec(), &font);
        let mut nk_convert_config = nk::NkConvertConfig::default();
    
        let mut nk_draw = nuklear_backend_glium::Drawer::new(&mut glium_display, 1024, 1024, 1024, draw_buffer);
    
        let mut closed = false;
        while !closed {
            let (window_width, window_height) = match glium_display.gl_window().window().get_inner_size() {
                Some(size) => size,
                None => break,
            };
    
            let mut draw_target = glium_display.draw();
    
            nk_context.begin(
                "Nuklear Example".into(),
                nk::NkRect {
                    x: 0.,
                    y: 0.,
                    w: 640.,
                    h: 480.,
                },
                0,
            );
            nk_context.layout_row(nk::NkLayoutFormat::NK_DYNAMIC, 240.0, &[1.0]);
            nk_context.button_text("hello");
    
            nk_context.end();
    
            nk_draw.draw(
                &mut nk_context,
                &mut nk_convert_config,
                &mut draw_target,
                nk::NkVec2 {
                    x: window_width as f32,
                    y: window_height as f32,
                },
            );
    
            draw_target.finish().unwrap();
    
            glutin_events_loop.poll_events(|ev| match ev {
                glutin::Event::WindowEvent { event, .. } => match event {
                    glutin::WindowEvent::Closed => closed = true,
                    _ => (),
                },
                _ => (),
            });
        }
    }
    

    However, this errors upon running with:

    nuklear-c/nuklear/nuklear.h:17269: nk_begin_titled: Assertion `ctx->style.font && ctx->style.font->width && "if this triggers you forgot to add a font"' failed.
    
    Reply
  • Format examples according to the Rust guidelines
    Format examples according to the Rust guidelines

    Feb 28, 2018

    Hello, not sure if I just didn't find it, but there seems to be no example, even though one is mentioned in the README. Having one would (even if it's just a Hello World), of course, be super-useful for quickly evaluating the library.

    v0.4 
    Reply