mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 13:38:35 +00:00
Let's use encode_utf8
This commit is contained in:
parent
4dfdf0ae5e
commit
ace021b94a
10
src/lib.rs
10
src/lib.rs
@ -228,14 +228,10 @@ impl ImGui {
|
||||
io.key_map[key as usize] = mapping as i32;
|
||||
}
|
||||
pub fn add_input_character(&mut self, character: char) {
|
||||
// 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 mut string = String::new();
|
||||
string.push(character);
|
||||
string.push('\0');
|
||||
let mut buf = [0; 5];
|
||||
character.encode_utf8(&mut buf);
|
||||
unsafe {
|
||||
imgui_sys::ImGuiIO_AddInputCharactersUTF8(string.as_ptr() as *const _);
|
||||
imgui_sys::ImGuiIO_AddInputCharactersUTF8(buf.as_ptr() as *const _);
|
||||
}
|
||||
}
|
||||
pub fn get_time(&self) -> f32 { unsafe { imgui_sys::igGetTime() } }
|
||||
|
||||
@ -29,6 +29,10 @@ impl ImString {
|
||||
self.0.clear();
|
||||
self.0.push(b'\0');
|
||||
}
|
||||
pub fn push(&mut self, ch: char) {
|
||||
let mut buf = [0; 4];
|
||||
self.push_str(ch.encode_utf8(&mut buf));
|
||||
}
|
||||
pub fn push_str(&mut self, string: &str) {
|
||||
self.refresh_len();
|
||||
self.0.extend_from_slice(string.as_bytes());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user