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.