Skip to content

Commit

Permalink
Add basic IME support and fix some font setup
Browse files Browse the repository at this point in the history
  • Loading branch information
drey7925 committed Jun 27, 2024
1 parent c94d32e commit f11023c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
6 changes: 5 additions & 1 deletion perovskite_client/src/game_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,13 @@ impl ClientState {
}

pub(crate) fn next_frame(&self, aspect_ratio: f64) -> FrameState {
let mut egui_wants_events = false;
{
self.timekeeper.update_frame();

let mut input = self.input.lock();
input.set_modal_active(self.egui.lock().wants_user_events());
egui_wants_events = self.egui.lock().wants_user_events();
input.set_modal_active(egui_wants_events);
if input.take_just_pressed(BoundAction::Inventory) {
self.egui.lock().open_inventory();
} else if input.take_just_pressed(BoundAction::Menu) {
Expand Down Expand Up @@ -771,6 +773,7 @@ impl ClientState {
},
player_position,
tool_state,
ime_enabled: egui_wants_events,
}
}

Expand Down Expand Up @@ -838,6 +841,7 @@ pub(crate) struct FrameState {
pub(crate) scene_state: SceneState,
pub(crate) player_position: Vector3<f64>,
pub(crate) tool_state: ToolState,
pub(crate) ime_enabled: bool,
}

use perovskite_core::protocol::blocks::{self as blocks_proto, CubeVariantEffect};
Expand Down
3 changes: 2 additions & 1 deletion perovskite_client/src/game_ui/egui_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,8 @@ impl EguiUi {
TextEdit::singleline(&mut self.chat_message_input)
.hint_text("Type a message; press Enter to send or Escape to close.")
.lock_focus(true)
.desired_width(f32::INFINITY),
.desired_width(f32::INFINITY)
.font(egui::FontId::proportional(16.0)),
);
if self.chat_force_request_focus {
self.chat_force_request_focus = false;
Expand Down
11 changes: 9 additions & 2 deletions perovskite_client/src/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use std::{ops::Deref, sync::Arc};

use anyhow::Context;
use arc_swap::ArcSwap;
use egui::{Color32, Layout, ProgressBar, RichText, TextEdit};
use egui::{Color32, FontId, Layout, ProgressBar, RichText, TextEdit};
use tokio::sync::{oneshot, watch};
use vulkano::{image::SampleCount, render_pass::Subpass};
use winit::{event::WindowEvent, event_loop::EventLoop};

use crate::vulkan::shaders::egui_adapter::set_up_fonts;
use crate::{
game_state::settings::GameSettings,
vulkan::{
Expand Down Expand Up @@ -39,7 +40,7 @@ impl MainMenu {
is_overlay: true,
samples: SampleCount::Sample1,
};
let egui_gui = egui_winit_vulkano::Gui::new_with_subpass(
let mut egui_gui = egui_winit_vulkano::Gui::new_with_subpass(
event_loop,
ctx.swapchain().surface().clone(),
ctx.clone_queue(),
Expand All @@ -49,6 +50,12 @@ impl MainMenu {
ctx.swapchain().image_format(),
gui_config,
);
set_up_fonts(&mut egui_gui.egui_ctx);
let mut style = (*egui_gui.egui_ctx.style()).clone();
style
.text_styles
.insert(egui::TextStyle::Body, FontId::proportional(16.0));
egui_gui.egui_ctx.set_style(style);
let settings_guard = settings.load();
MainMenu {
egui_gui,
Expand Down
5 changes: 5 additions & 0 deletions perovskite_client/src/vulkan/game_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use vulkano::{
sync::{future::FenceSignalFuture, FlushError, GpuFuture},
};

use winit::window::ImePurpose;
use winit::{
dpi::{PhysicalPosition, PhysicalSize},
event::{Event, WindowEvent},
Expand Down Expand Up @@ -85,9 +86,11 @@ impl ActiveGame {
scene_state,
mut player_position,
tool_state,
ime_enabled,
} = self
.client_state
.next_frame((window_size.width as f64) / (window_size.height as f64));
ctx.window.set_ime_allowed(ime_enabled);
ctx.start_render_pass(
&mut command_buf_builder,
framebuffer,
Expand Down Expand Up @@ -543,6 +546,8 @@ impl GameRenderer {
command_buf_builder,
)
} else {
// we're not in the active game, allow the IME
self.ctx.window.set_ime_allowed(true);
self.ctx
.start_render_pass(
&mut command_buf_builder,
Expand Down
2 changes: 1 addition & 1 deletion perovskite_client/src/vulkan/shaders/egui_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl EguiAdapter {
}
}

fn set_up_fonts(egui_ctx: &mut egui::Context) {
pub(crate) fn set_up_fonts(egui_ctx: &mut egui::Context) {
let mut fonts = egui::FontDefinitions::default();
fonts.font_data.insert(
"NotoSans-Light".to_owned(),
Expand Down
2 changes: 1 addition & 1 deletion perovskite_server/src/network_server/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// SPDX-License-Identifier: Apache-2.0

use std::{sync::Arc, u8};
use std::sync::Arc;

use opaque_ke::{
CredentialFinalization, CredentialRequest, RegistrationRequest, RegistrationUpload,
Expand Down

0 comments on commit f11023c

Please sign in to comment.