text, ui: follow a language change, and resolve the language before the fonts
Review follow-ups on #312: - `crates/ui-egui/src/theme.rs`'s `japanese_font_tests` still called `install` with two arguments, so `cargo test` did not compile. Every call site now passes a language. - The call sites passed the stored `general.language` preference. With the default `system` that is `""`, which handed the CJK choice back to the environment locale — one macOS and Windows usually do not set. They now pass `crate::i18n::language(app)`, the resolved language, so Match System draws Chinese on a Chinese system. - Changing Settings ▸ General ▸ Language only reached the fonts on the first frame. `EffectcraftApp` now remembers the language its fonts were installed for and installs them again when it changes, so the switch applies without a restart. - Documented that `fonts::set_cjk_locale` is process-global: the Han preference therefore applies to composition text as well as the interface chrome (docs/preferences.md and the function's own comment). Rebased onto main after #309 landed — `header.rs` gained an `install` call site in the meantime, and the catalogs now resolve through `i18n::language`.
This commit is contained in:
@@ -212,6 +212,8 @@ pub struct EffectcraftApp {
|
||||
last_time: f64,
|
||||
styled: bool,
|
||||
fonts_ready: bool,
|
||||
/// The interface language the fonts were installed for; `""` until the first frame.
|
||||
styled_language: &'static str,
|
||||
pub(crate) control_rx: Option<Receiver<ControlRequest>>,
|
||||
pub(crate) deferred: Vec<(ControlRequest, f64)>,
|
||||
pub(crate) synthetic: Vec<egui::Event>,
|
||||
@@ -298,6 +300,7 @@ impl EffectcraftApp {
|
||||
last_time: 0.0,
|
||||
styled: false,
|
||||
fonts_ready: false,
|
||||
styled_language: "",
|
||||
control_rx: None,
|
||||
deferred: vec![],
|
||||
synthetic: vec![],
|
||||
@@ -1568,10 +1571,16 @@ impl eframe::App for EffectcraftApp {
|
||||
|
||||
fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
self.apply_gpu_failure(ctx);
|
||||
if !self.styled {
|
||||
theme::install(ctx, &self.tokens, &self.session.prefs.general.language);
|
||||
fit_window(ctx);
|
||||
self.styled = true;
|
||||
// The CJK fallback fonts depend on the interface language, so they follow a change of
|
||||
// Settings ▸ General ▸ Language instead of only the first frame.
|
||||
let language = crate::i18n::language(self);
|
||||
if !self.styled || self.styled_language != language {
|
||||
theme::install(ctx, &self.tokens, language);
|
||||
self.styled_language = language;
|
||||
if !self.styled {
|
||||
fit_window(ctx);
|
||||
self.styled = true;
|
||||
}
|
||||
ctx.request_repaint();
|
||||
} else {
|
||||
self.fonts_ready = true;
|
||||
|
||||
Reference in New Issue
Block a user