5 releases
0.1.4 | Jul 6, 2024 |
---|---|
0.1.3 | Jun 20, 2024 |
0.1.2 | Mar 27, 2024 |
0.1.1 | Jan 21, 2024 |
0.1.0 | Jan 20, 2024 |
#650 in Game dev
15KB
299 lines
This is a plugin that supports Japanese input with bevy_egui
bevy = "*"
bevy_egui = "*"
bevy_egui_ime = "*"
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use bevy::prelude::*;
use bevy_egui_ime::*;
#[derive(Resource, Default)]
pub struct MyApp{
single_text: String,
multi_text: String,
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
.add_plugins(ImePlugin)
.insert_resource(MyApp::default())
.add_systems(Startup, setup_system)
.add_systems(Update, ui_system)
.run();
}
pub fn setup_system(
mut egui_context: EguiContexts,
mut windows: Query<&mut Window>,
) {
let mut window = windows.single_mut();
window.ime_enabled = true;
let mut txt_font = egui::FontDefinitions::default();
txt_font.families.get_mut(&egui::FontFamily::Proportional).unwrap().insert(0, "Meiryo".to_owned());
let fd = egui::FontData::from_static(include_bytes!("C:/Windows/Fonts/Meiryo.ttc"));
txt_font.font_data.insert("Meiryo".to_owned(), fd);
egui_context.ctx_mut().set_fonts(txt_font);
}
pub fn ui_system(
mut contexts: EguiContexts,
mut app: ResMut<MyApp>,
mut ime: ResMut<ImeManager>,
) {
let ctx = contexts.ctx_mut();
egui::CentralPanel::default().show(ctx, |ui| {
let _teo_s = ime.text_edit_singleline(&mut app.single_text, 400.0, ui, ctx);
let _teo_m = ime.text_edit_multiline(&mut app.multi_text, 400.0, ui, ctx);
});
}
Dependencies
~28–62MB
~1M SLoC