Giter VIP home page Giter VIP logo

nuklear-rust's Introduction

nuklear-rust's People

Contributors

2asoft avatar nvzqz avatar snuk182 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nuklear-rust's Issues

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();

gfx backend mouse input is scaled by 2 on Mac

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!

How draw a line

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

Do You know how do this in C and Rust?

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"

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!

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.

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.

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.

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.

SDL2

In future SDL2 backend will be created?

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

Possibly rename crate to "nuklear"?

This would be more of a bikeshed than anything else, but it's been a convention to not have crate names on crates.io or rust package names start with rust_, as this pollutes code with useless information.

There are two distinct possibilities for changing this though, if you were interested in it:

  • A. rename the rust package to nuklear, keep the crate name nuklear-rust.

    Crate would be used like:

    // Cargo.toml:
    nuklear-rust = "0.3"
    // lib.rs:
    extern crate nuklear;
  • B. rename both to nuklear, and publish a small release on crates.io for nuklear-rust marking it as deprecated, with a README pointing to the nuklear crate.

    Crate would be used like:

    // Cargo.toml:
    nuklear = "0.3"
    // lib.rs:
    extern crate nuklear;
  • C. Don't change anything. Possibly recommend renaming on usage?

    Crate could be used like:

    // Cargo.toml:
    nuklear-rust = "0.3"
    // lib.rs:
    extern crate nuklear_rust as nk;

I would prefer A or B, but any is an alright option. There's nothing inherently bad about *-rust or *-rs crate names besides community bias. A. would be a lot less churn over B., as it would still be the same crates.io package, so that might be the best option?

I should note that none of this is suggesting renaming the project name, nor the repository name, just the name to use in rust programs. I definitely agree with it being called "nuklear-rust" everywhere else - it's just a bit redundant from within rust. It's a large convention to have projects named xxx-rs or xxx-rust (with matching git repositories) with just xxx as the name in crates.io and as the package name.

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

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?

Build failed using latest nightly toolchain

E:\prj\rust\nuklear-test-gdi>cargo build
   Compiling nuklear-rust v0.3.0
error[E0425]: cannot find function `allocate` in module `heap`
  --> C:\Users\lynnux\.cargo\registry\src\mirrors.ustc.edu.cn-15f9db60536bad60\n
uklear-rust-0.3.0\src\alloc_heap.rs:19:24
   |
19 |     let memory = heap::allocate(size, ALIGNMENT);
   |                        ^^^^^^^^ not found in `heap`

error[E0425]: cannot find function `deallocate` in module `heap`
  --> C:\Users\lynnux\.cargo\registry\src\mirrors.ustc.edu.cn-15f9db60536bad60\n
uklear-rust-0.3.0\src\alloc_heap.rs:40:11
   |
40 |     heap::deallocate(old as *mut u8, old_size, ALIGNMENT);
   |           ^^^^^^^^^^ not found in `heap`

error: use of unstable library feature 'allocator_api': the precise API and guar
antees it provides may be tweaked slightly, especially to possibly take into acc
ount the types being stored to make room for a future tracing garbage collector
(see issue #32838)
 --> C:\Users\lynnux\.cargo\registry\src\mirrors.ustc.edu.cn-15f9db60536bad60\nu
klear-rust-0.3.0\src\alloc_heap.rs:9:5
  |
9 | use self::alloc::heap;
  |     ^^^^^^^^^^^^^^^^^
  |
  = help: add #![feature(allocator_api)] to the crate attributes to enable

error: aborting due to 3 previous errors

there is no heap::allocate and heap::deallocate in the latest nightly rust source: https://github.com/rust-lang/rust/blob/master/src/liballoc/heap.rs

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

โœŒ๏ธ

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.