mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-20 01:48:29 +00:00
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:
parent
238f5fead1
commit
6eb3ffefdf
@ -15,7 +15,7 @@ default = ["glium"]
|
|||||||
libc = "0.1"
|
libc = "0.1"
|
||||||
|
|
||||||
[dependencies.glium]
|
[dependencies.glium]
|
||||||
version = "0.9.3"
|
version = "0.10"
|
||||||
default-features = false
|
default-features = false
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
@ -30,6 +30,6 @@ gcc = "0.3"
|
|||||||
time = "0.1"
|
time = "0.1"
|
||||||
|
|
||||||
[dev-dependencies.glium]
|
[dev-dependencies.glium]
|
||||||
version = "0.9.3"
|
version = "0.10"
|
||||||
features = ["glutin"]
|
features = ["glutin"]
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|||||||
@ -16,7 +16,7 @@ bitflags = "0.3"
|
|||||||
libc = "0.1"
|
libc = "0.1"
|
||||||
|
|
||||||
[dependencies.glium]
|
[dependencies.glium]
|
||||||
version = "0.9"
|
version = "0.10"
|
||||||
default-features = false
|
default-features = false
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
|
|||||||
@ -131,7 +131,7 @@ pub struct DeviceObjects {
|
|||||||
texture: Texture2d
|
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!(
|
program!(
|
||||||
ctx,
|
ctx,
|
||||||
140 => {
|
140 => {
|
||||||
@ -152,7 +152,11 @@ impl DeviceObjects {
|
|||||||
let vertex_buffer = try!(VertexBuffer::empty_dynamic(ctx, 0));
|
let vertex_buffer = try!(VertexBuffer::empty_dynamic(ctx, 0));
|
||||||
let index_buffer = try!(IndexBuffer::empty_dynamic(ctx, PrimitiveType::TrianglesList, 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 texture = try!(im_gui.prepare_texture(|handle| {
|
||||||
let data = RawImage2d {
|
let data = RawImage2d {
|
||||||
data: Cow::Borrowed(handle.pixels),
|
data: Cow::Borrowed(handle.pixels),
|
||||||
|
|||||||
15
src/lib.rs
15
src/lib.rs
@ -231,10 +231,17 @@ impl ImGui {
|
|||||||
io.key_map[key as usize] = mapping as i32;
|
io.key_map[key as usize] = mapping as i32;
|
||||||
}
|
}
|
||||||
pub fn add_input_character(&mut self, character: char) {
|
pub fn add_input_character(&mut self, character: char) {
|
||||||
unsafe {
|
if !character.is_control() {
|
||||||
// TODO: This is not good. We should use char::encode_ut8 when it stabilizes
|
// TODO: This is slightly better. We should use char::encode_utf8 when it stabilizes
|
||||||
// (or whatever stabilizes to fill its place) and call ImGuiIO_AddInputCharactersUTF8
|
// to allow us to skip the string intermediate since we can then go directly
|
||||||
imgui_sys::ImGuiIO_AddInputCharacter(character as u16);
|
// 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() } }
|
pub fn get_time(&self) -> f32 { unsafe { imgui_sys::igGetTime() } }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user