snuk182 / nuklear-rust

The bindings to the Nuklear 2D immediate GUI library.
Apache License 2.0
359 stars 16 forks source link

Font ids inversion? #17

Closed Catvert closed 6 years ago

Catvert commented 6 years ago

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.

snuk182 commented 6 years ago

Looks like NK uses stack instead of linked list for font storage. Fixed in https://github.com/snuk182/nuklear-rust/commit/8587eb73f49a4a25e52ec966d51674500cc78de7 .

cedric-h commented 5 years ago

I'm still getting this issue in version 0.6. My code is almost identical to the code shared above.