Encode string of UTF8 chars using encode_default API

Using encode_utf8 will be better when it stabilizes since we won't need
the String intermediate and can go directly to a Vec<u8>.

Update to glium 0.10 to resolve ctrl/shift/etc virtual keycodes on Win10
This commit is contained in:
Will Usher 2015-10-14 11:19:26 -06:00
parent 238f5fead1
commit 6eb3ffefdf
4 changed files with 20 additions and 9 deletions

View File

@ -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

View File

@ -16,7 +16,7 @@ bitflags = "0.3"
libc = "0.1"
[dependencies.glium]
version = "0.9"
version = "0.10"
default-features = false
optional = true

View File

@ -131,7 +131,7 @@ pub struct DeviceObjects {
texture: Texture2d
}
fn compile_default_program<F: Facade>(ctx: &F) -> Result<Program, program::ProgramCreationError> {
fn compile_default_program<F: Facade>(ctx: &F) -> Result<Program, program::ProgramChooserCreationError> {
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),

View File

@ -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() } }