diff --git a/Cargo.toml b/Cargo.toml index 6b0ea00..106669d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ default = ["glium"] libc = "0.1" [dependencies.glium] -version = "0.9.3" +version = "0.10" default-features = false optional = true @@ -30,6 +30,6 @@ gcc = "0.3" time = "0.1" [dev-dependencies.glium] -version = "0.9.3" +version = "0.10" features = ["glutin"] default-features = false diff --git a/imgui-sys/Cargo.toml b/imgui-sys/Cargo.toml index ac035d5..97e0c4a 100644 --- a/imgui-sys/Cargo.toml +++ b/imgui-sys/Cargo.toml @@ -16,7 +16,7 @@ bitflags = "0.3" libc = "0.1" [dependencies.glium] -version = "0.9" +version = "0.10" default-features = false optional = true diff --git a/src/glium_renderer.rs b/src/glium_renderer.rs index daab72f..92b2d56 100644 --- a/src/glium_renderer.rs +++ b/src/glium_renderer.rs @@ -131,7 +131,7 @@ pub struct DeviceObjects { texture: Texture2d } -fn compile_default_program(ctx: &F) -> Result { +fn compile_default_program(ctx: &F) -> Result { program!( ctx, 140 => { @@ -152,7 +152,11 @@ impl DeviceObjects { let vertex_buffer = try!(VertexBuffer::empty_dynamic(ctx, 0)); let index_buffer = try!(IndexBuffer::empty_dynamic(ctx, PrimitiveType::TrianglesList, 0)); - let program = try!(compile_default_program(ctx)); + let program = match compile_default_program(ctx) { + Ok(p) => p, + Err(program::ProgramChooserCreationError::NoVersion) => panic!("No version for GLSL program"), + Err(e) => panic!("Error compiling shaders {:?}", e), + }; let texture = try!(im_gui.prepare_texture(|handle| { let data = RawImage2d { data: Cow::Borrowed(handle.pixels), diff --git a/src/lib.rs b/src/lib.rs index f2ba293..8539235 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -231,10 +231,17 @@ impl ImGui { io.key_map[key as usize] = mapping as i32; } pub fn add_input_character(&mut self, character: char) { - unsafe { - // TODO: This is not good. We should use char::encode_ut8 when it stabilizes - // (or whatever stabilizes to fill its place) and call ImGuiIO_AddInputCharactersUTF8 - imgui_sys::ImGuiIO_AddInputCharacter(character as u16); + if !character.is_control() { + // TODO: This is slightly better. We should use char::encode_utf8 when it stabilizes + // to allow us to skip the string intermediate since we can then go directly + // to bytes + let utf8_str: String = character.escape_default().collect(); + let mut bytes = utf8_str.into_bytes(); + // into_bytes does not produce a c-string, we must append the null terminator + bytes.push(0); + unsafe { + imgui_sys::ImGuiIO_AddInputCharactersUTF8(bytes.as_ptr() as *const i8); + } } } pub fn get_time(&self) -> f32 { unsafe { imgui_sys::igGetTime() } }