The bindings to the Nuklear 2D immediate GUI library.

Overview
Comments
  • Format examples according to the Rust guidelines

    Format examples according to the Rust guidelines

    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 
    opened by mruegenberg 6
  • Documentation on initializing fonts?

    Documentation on initializing fonts?

    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.
    
    opened by daboross 6
  • No way of accessing clipboard struct on context

    No way of accessing clipboard struct on context

    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 
    opened by GideonUng 5
  • Crash on i686 target

    Crash on i686 target

    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 
    opened by lynnux 3
  • Font ids inversion?

    Font ids inversion?

    Hi ! I've tried to add multiple fonts size in my program. I did the following, like samples :

    let mut font_atlas = FontAtlas::new(&mut allo);
    
    let mut font_cfg = FontConfig::with_size(0.0);
    font_cfg.set_oversample_h(3);
    font_cfg.set_oversample_v(2);
    font_cfg.set_glyph_range(font_cyrillic_glyph_ranges());
    font_cfg.set_ttf(include_bytes!("../../font.ttf"));
    
    font_cfg.set_ttf_data_owned_by_atlas(false);
    font_cfg.set_size(14f32);
    let font_14 = font_atlas.add_font_with_config(&font_cfg).unwrap();
    
    font_cfg.set_ttf_data_owned_by_atlas(false);
    font_cfg.set_size(32f32);
    let font_32 = font_atlas.add_font_with_config(&font_cfg).unwrap();
    
    let font_tex = {
            let (b, w, h) = font_atlas.bake(FontAtlasFormat::NK_FONT_ATLAS_RGBA32);
            drawer.add_texture(&mut *ggez_ctx.gfx_context.factory, b, w, h)
    };
    
    let mut null = DrawNullTexture::default();
    font_atlas.end(font_tex, Some(&mut null));
    
    let mut ctx = Context::new(&mut allo, font_atlas.font(font_14).unwrap().handle());
    

    Unfortunately, nuklear use the 32px font if I set the font_14 in the Context constructor and inversely when I set the font 32. It's very weird, I've checked my code several times without success. I have also tried to use different FontConfig instance without success.

    Thanks for your help.

    v0.5 
    opened by Catvert 2
  • Styles

    Styles

    Hi ! I'm trying your library and it works very well ! I've just got an issue (?) while styling my ui. When I've tried for example to style buttons, I did the following :

     ctx.style().button().set_hover(StyleItem::color(color_rgba(...)));
    

    Unfortunately, the button() method doesn't return a mutable ref so I can't mutate the style. However, I've seen that the window method return a mut ref, so why not for buttons and other items? Is there an other way to achieve that?

    Thanks for your help.

    v0.5 
    opened by Catvert 2
  • Use Drop to automatically free things?

    Use Drop to automatically free things?

    Hi,

    I'm getting used to using this library, and I was wondering one thing: if all nuklear types have free() methods, why not just implement Drop?

    Drop would run at the end of where the variable exists, so it would make the library much easier to use without creating memory leaks. At least, that's my understanding.

    Is there a technical reason which stops these types from implementing Drop and instead requires them to have free methods?

    I don't want to assume anything, but if you're less experienced with the rust idioms I can make more issues on things I'd notice and potential submit PRs to fix them if you see the changes as OK in the FFI side of things.

    enhancement v0.4 
    opened by daboross 2
  • Unideomatic naming convention

    Unideomatic naming convention

    I'm a bit confused with all these Nk in front of every type. It serves absolutely no purpose because Rust has namespaces, and the common usage looks like:

    use nuklear_rust as nk;
    //....
    nk::NkAllocator::new_vec();
    
    v0.4 
    opened by vitvakatu 2
  • Generate Nuklear bindings at build time

    Generate Nuklear bindings at build time

    Since bindings are no longer in source control, they are easier to keep up to date (always regenerated on build). I also took the chance and pointed the Nuklear submodule to the current repo.

    opened by 2asoft 1
  • Is it possible to remove default Titlebar and other window chrome?

    Is it possible to remove default Titlebar and other window chrome?

    I've quite liked my (admittedly super limited) experience with this so far, and was wondering if there was a way to hide the default chrome on windows (not just on Windows) and then create my own titlebar and controls and such

    I'm unsure whether this is something that hasn't been implemented or if I've just missed something, any help/advice/etc would be appreciated :D

    ✌️

    opened by ILikeTeaALot 1
  • Stability and Lifetime/Maintenance

    Stability and Lifetime/Maintenance

    Hi Serhii,

    I'm planning a software project, that will cost me 1-2 years of full time to finish. I'll bet my financial existence on it. Should I use nuklear-rust for the GUI? What risks would I be taking? Do you have an estimate when it will leave beta? How long will you maintained it?

    Cheers, Navid

    opened by NeverGivinUp 1
  • i8 u8 tomato tomato?

    i8 u8 tomato tomato?

    Got this puppy running on my old Macbook and it works like a charm! Muchas gracias! But moving over to Raspberry Pi4, there seems to be many i8 u8 type problems. The nk_ functions seem to want u8, but get i8..

    error[E0308]: mismatched types
        --> /root/.cargo/registry/src/github.com-1285ae84e5963aae/nuklear-rust-0.6.3/src/lib.rs:3352:50
         |
    3352 |             nk_textedit_text(&mut self.internal, arg2.as_ptr() as *const i8, arg2.as_bytes().len() as ::std::os::raw::c_int);
         |                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
         |
         = note: expected raw pointer `*const u8`
                    found raw pointer `*const i8`
    
    error[E0308]: mismatched types
        --> /root/.cargo/registry/src/github.com-1285ae84e5963aae/nuklear-rust-0.6.3/src/lib.rs:3379:56
         |
    3379 |         unsafe { nk_textedit_paste(&mut self.internal, arg2.as_ptr() as *const i8, arg2.as_bytes().len() as ::std::os::raw::c_int) != 0 }
         |                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
         |
         = note: expected raw pointer `*const u8`
                    found raw pointer `*const i8`
    

    Is this easily fixed?

    My Cargo.toml has the following deps:

    nuklear-rust = {version = "~0.6"}
    nuklear-backend-gfx = "~0.9"
    gfx_device_gl = "~0.16"
    gfx_window_glutin = "~0.30"
    gfx = "~0.18"
    glutin = "~0.20"
    image = "~0.12"
    
    opened by pietervandermeer 1
  • Please derive Debug on CommandType

    Please derive Debug on CommandType

    let names = [
    	"NK_COMMAND_NOP",
    	"NK_COMMAND_SCISSOR",
    	"NK_COMMAND_LINE",
    	"NK_COMMAND_CURVE",
    	"NK_COMMAND_RECT",
    	"NK_COMMAND_RECT_FILLED",
    	"NK_COMMAND_RECT_MULTI_COLOR",
    	"NK_COMMAND_CIRCLE",
    	"NK_COMMAND_CIRCLE_FILLED",
    	"NK_COMMAND_ARC",
    	"NK_COMMAND_ARC_FILLED",
    	"NK_COMMAND_TRIANGLE",
    	"NK_COMMAND_TRIANGLE_FILLED",
    	"NK_COMMAND_POLYGON",
    	"NK_COMMAND_POLYGON_FILLED",
    	"NK_COMMAND_POLYLINE",
    	"NK_COMMAND_TEXT",
    	"NK_COMMAND_IMAGE",
    	"NK_COMMAND_CUSTOM"
    ];
    
    println!("Command: {}", names[unsafe { std::mem::transmute::<CommandType, u32>(cmd.get_type()) } as usize]);
    

    This is bad

    opened by LoganDark 0
  • Use repr(transparent) for wrapper structs

    Use repr(transparent) for wrapper structs

    repr(transparent) provides stronger guarantees that the struct will have the exact same representation as its only field. And Context didn't even have an explicit representation, not even repr(C)!!

    Because of all the transmutation that this library does between wrapper types and the types that they wrap, those guarantees are quite important, don't you think? :)

    opened by LoganDark 1
  • style_push_* API seem to be unusable

    style_push_* API seem to be unusable

    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?

    opened by parasyte 1
Owner
Serhii Plyhun
Serhii Plyhun
egui: an easy-to-use immediate mode GUI in pure Rust

?? egui: an easy-to-use GUI in pure Rust egui is a simple, fast, and highly portable immediate mode GUI library for Rust. egui runs on the web, native

Emil Ernerfeldt 12.6k Jan 3, 2023
Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.

libui: a portable GUI library for C This README is being written. Status It has come to my attention that I have not been particularly clear about how

Pietro Gagliardi 10.4k Dec 31, 2022
Rust bindings for the FLTK GUI library.

fltk-rs Rust bindings for the FLTK Graphical User Interface library. The FLTK crate is a crossplatform lightweight gui library which can be statically

Mohammed Alyousef 1.1k Jan 9, 2023
Rust bindings for the FLTK GUI library.

fltk-rs Rust bindings for the FLTK Graphical User Interface library. The fltk crate is a cross-platform lightweight gui library which can be staticall

fltk-rs 1.1k Jan 9, 2023
An easy-to-use, 2D GUI library written entirely in Rust.

Conrod An easy-to-use, 2D GUI library written entirely in Rust. Guide What is Conrod? A Brief Summary Screenshots and Videos Feature Overview Availabl

PistonDevelopers 3.3k Jan 1, 2023
Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust

Relm Asynchronous, GTK+-based, GUI library, inspired by Elm, written in Rust. This library is in beta stage: it has not been thoroughly tested and its

null 2.2k Dec 31, 2022
Clear Coat is a Rust wrapper for the IUP GUI library.

Clear Coat Clear Coat is a Rust wrapper for the IUP GUI library. IUP uses native controls and has Windows and GTK backends. A macOS backend has been o

Jordan Miner 18 Feb 13, 2021
A cross-platform GUI library for Rust, inspired by Elm

Iced A cross-platform GUI library for Rust focused on simplicity and type-safety. Inspired by Elm. Features Simple, easy-to-use, batteries-included AP

Héctor Ramón 17.5k Jan 2, 2023
A cross-platform GUI library for Rust focused on simplicity and type-safety

A cross-platform GUI library for Rust, inspired by Elm

Héctor Ramón 17.5k Jan 8, 2023
An idiomatic GUI library inspired by Elm and based on gtk4-rs

An idiomatic GUI library inspired by Elm and based on gtk4-rs. Relm4 is a new version of relm that's built from scratch and is compatible with GTK4 an

Aaron Erhardt 722 Dec 31, 2022
A cross-platform GUI library for Rust, inspired by Elm

Iced A cross-platform GUI library for Rust focused on simplicity and type-safety. Inspired by Elm. Features Simple, easy-to-use, batteries-included AP

null 17.5k Dec 28, 2022
A simple, cross-platform GUI automation module for Rust.

AutoPilot AutoPilot is a Rust port of the Python C extension AutoPy, a simple, cross-platform GUI automation library for Python. For more information,

null 271 Dec 27, 2022
Desktop GUI Framework

Azul - Desktop GUI framework WARNING: The features advertised in this README may not work yet. Azul is a free, functional, immediate mode GUI framewor

Maps4Print 5.4k Jan 1, 2023
Truly cross platform, truly native. multiple backend GUI for rust

WIP: Sauron-native a rust UI library that conquers all platforms ranging from desktop to mobile devices. An attempt to create a truly native, truly cr

Jovansonlee Cesar 627 Jan 5, 2023
A GUI for Cargo

A GUI for Cargo This is a project to make a GUI for cargo, built using SixtyFPS: The idea cargo install cargo-ui cargo ui Prerequisites In addition to

SixtyFPS 128 Dec 28, 2022
Automatically create GUI applications from clap3 apps

Automatically create GUI applications from clap3 apps

Michał Gniadek 340 Dec 20, 2022
A simple news reading GUI app built in Rust

Headlines [WIP] A native GUI app built with Rust using egui. Uses newsapi.org as the source to fetch news articles. This is a WIP and the current stat

creativcoder 89 Dec 29, 2022
Build GUI applications with minimal dependencies in Rust

winapi-app-windows A crate to build applications' windows in Windows using WinAPI. This would be less confusing if the operating system was called som

Lonami 5 Jul 26, 2022
A simple GUI version of the pH calibration tool written in egui, based on the eframe template.

caliphui A simple GUI version of the pH calibration tool written in egui, based on the eframe template. Usage Native binaries are provided under relea

Peter Dunne 0 Dec 29, 2021