SecondHalfGames / yakui

yakui is a declarative Rust UI library for games
Apache License 2.0
237 stars 21 forks source link

IME and CJK Support #120

Closed stolen-programmer closed 11 months ago

stolen-programmer commented 12 months ago

native input method support is required

Need to input Chinese, Japanese, and Korean text

stolen-programmer commented 12 months ago
use yakui::widgets::{Pad, TextBox};
use yakui::{center, use_state};

pub fn run() {
    let text = use_state(|| "".to_owned());

    center(|| {
        let mut my_box = TextBox::new(text.borrow().as_str());
        my_box.style.font = "MSYH".into();
        my_box.style.font_size = 60.0;
        my_box.padding = Pad::all(50.0);
        my_box.placeholder = "你好".into();

        let response = my_box.show().into_inner();
        if let Some(new_text) = response.text {
            text.set(format!("你好世界{}", new_text));
        }
        if response.activated {
            println!("{}", text.borrow());
        }
    });
}

fn main() {
    bootstrap::start(run as fn());
}

At present, it can be confirmed that the display is normal, but the Chinese input method cannot be switched

stolen-programmer commented 12 months ago
window.set_ime_allowed(true);
/// yakui/crates/yakui-winit/src/lib.rs
WinitEvent::WindowEvent {
    event: WindowEvent::Ime(winit::event::Ime::Commit(text)),
    ..
} => {
    for c in text.chars() {
        state.handle_event(Event::TextInput(c));
    }
    true
}
LPGhatguy commented 11 months ago

Thank you for the PR on this! I did some testing after I merged your PR. I filed issues #122, #123, and #124 with specific things that we still need to make our IME support good.