Crates.io | bevy_egui_ime |
lib.rs | bevy_egui_ime |
version | 0.1.4 |
source | src |
created_at | 2024-01-20 12:06:25.807088 |
updated_at | 2024-07-06 12:36:55.2156 |
description | This is a plugin that supports Japanese input with bevy_egui |
homepage | |
repository | https://github.com/8bitTD/bevy_egui_ime |
max_upload_size | |
id | 1106436 |
size | 15,415 |
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);
});
}