Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge #490: i18n: Czech interface language

aionggf3f8162996f6
diff --cc crates/ui-egui/src/i18n.rs
index f4326c661,0f27e2b11..5f99765a4
--- a/crates/ui-egui/src/i18n.rs
+++ b/crates/ui-egui/src/i18n.rs
@@@ -3918,8 -3167,11 +3988,10 @@@ mod tests
assert_eq!(tr("cs", "Spread"), "Dvoustrana");
assert_eq!(tr("cs", "Bleed"), "Spadávka");
assert_eq!(tr("cs", "Leading"), "Proklad");
- assert_eq!(tr("cs", "Edit/Interface Language"), "Úpravy/Jazyk rozhraní");
assert_eq!(tr("cs", "Unknown label"), "Unknown label");
assert_eq!(tr_context("cs", "Group", "selection"), "Skupina");
+ assert_eq!(tr_context("cs", "Name", "contributors"), "Jméno");
+ assert_eq!(tr_context("cs", "Name", "unknown"), "Název");
assert_eq!(tr("cs", "Group"), "Seskupit");
assert_eq!(tr_context("cs", "Columns", "table"), tr("cs", "Columns"));
assert_eq!(style_name("cs", "[Basic Paragraph]"), "[Základní odstavec]");
diff --cc crates/ui-egui/src/lib.rs
index 00f9b396e,6bcbf8c51..c5144f8e0
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@@ -641,21 -585,12 +641,27 @@@ impl DesignApp
self.ui.status = s.into();
}
+ /// Did an IME composition end outside the IME this frame (a click, a tool switch)? egui's
+ /// `should_interrupt_composition` toggles winit's IME, which doesn't reach the macOS input
+ /// context: it keeps the marked text and types it again into the next composition, so the
+ /// host discards it there.
+ pub fn take_ime_discard(&mut self) -> bool {
+ std::mem::take(&mut self.ime_discard)
+ }
+
+ /// Did the canvas ask for the system IME in the last frame (a Type tool caret)? The web
+ /// build's hidden text input has the keyboard then, so text events hold what the browser
+ /// typed (see [`drop_key_name_text`]).
+ pub fn canvas_ime(&self) -> bool {
+ self.canvas_ime
+ }
+
+ /// "<feature>: <error>" in the status bar: the feature name is translated, the engine's own
+ /// error text stays as the engine wrote it.
+ pub fn status_error(&mut self, feature: &str, error: impl std::fmt::Display) {
+ self.ui.status = format!("{}: {error}", crate::i18n::tr(&self.ui.language, feature));
+ }
+
/// THE entry point for every action (menus, shortcuts, palette, panels, control channel).
pub fn run(&mut self, id: &str, params: Value) -> Result<Value, String> {
if let Some(r) = menus::run_ui(self, id, &params) {
@@@ -1547,30 -1274,16 +1556,40 @@@ mod tests
}
}
+ /// Files without an extension: dropped, a document opens and anything else is placed; asked
+ /// for by the operating system, they wait for the window and then open as documents.
+ #[test]
+ fn extensionless_documents_open_by_content() {
+ let path = std::env::temp_dir().join(format!("designcraft-ui-{}-Brochure", std::process::id()));
+ let mut app = DesignApp::new(Session::new(), Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let bytes = designcraft_engine::cmd::base64_decode(app.run("file.serialize", json!({})).unwrap()["base64"].as_str().unwrap());
+ std::fs::write(&path, bytes).unwrap();
+ let p = path.to_string_lossy().to_string();
+ app.open_dropped(&p).unwrap();
+ assert_eq!(app.session.documents().len(), 2, "a document opens, it isn't placed");
+ app.open_documents_later([p.clone()]);
+ assert_eq!(app.session.documents().len(), 2, "queued until the window is ready");
+ app.open_os_documents();
+ assert_eq!(app.session.documents().len(), 3);
+ assert_eq!(app.session.active().and_then(|d| d.path.clone()), Some(p));
+ let _ = std::fs::remove_file(&path);
+ let notes = unreadable_file("notes");
+ let e = app.open_dropped(&notes.to_string_lossy()).unwrap_err();
+ let _ = std::fs::remove_file(&notes);
+ assert_eq!(alert(&app), ("Can't Place the File".to_string(), e));
+ }
+
+ #[test]
+ fn status_messages_follow_the_interface_language_but_engine_errors_stay_english() {
+ let mut app = DesignApp::new(Session::new(), Services::default());
+ app.status_error("Table", "No table selected");
+ assert_eq!(app.ui.status, "Table: No table selected");
+ app.ui.language = "cs".into();
+ app.status_error("Table", "No table selected");
+ assert_eq!(app.ui.status, "Tabulka: No table selected");
+ }
+
#[test]
fn dropping_an_unreadable_file_alerts() {
// A document opens, so it says it can't be opened.
diff --cc crates/ui-egui/src/panels/glyphs.rs
index de9d52d12,5ca90b5ea..430268bad
--- a/crates/ui-egui/src/panels/glyphs.rs
+++ b/crates/ui-egui/src/panels/glyphs.rs
@@@ -63,64 -71,11 +63,64 @@@ pub fn show(app: &mut DesignApp, ui: &m
}
});
}
- let cols = ((ui.available_width() / CELL).floor() as u32).max(1);
+ let (picked, count) = grid(ui, &db, scope, &st.family, &st.style, &q, 320.0);
+ insert = insert.or(picked);
+ if let Some(c) = insert {
+ match app.run("text.insert", json!({"text": c.to_string(), "raw": true})) {
+ Ok(_) => {
+ st.recent.retain(|x| *x != c);
+ st.recent.insert(0, c);
+ st.recent.truncate(12);
+ }
- Err(e) => app.status(format!("Glyphs: {e}")),
++ Err(e) => app.status_error("Glyphs", e),
+ }
+ }
+ crate::rtl::label(
+ ui,
+ egui::RichText::new(
+ crate::i18n::tr(&app.ui.language, "{count} glyphs — click to insert at the text cursor").replace("{count}", &count.to_string()),
+ )
+ .size(10.5)
+ .color(t.text_dim),
+ );
+ ui.data_mut(|d| d.insert_temp(id, st));
+}
+
+/// The characters of font `family` `style` in a grid (those matching `query`, a character or
+/// U+code, when it isn't empty), at most `max_height` tall and scrolling: the character clicked,
+/// and how many are shown.
+pub fn grid(
+ ui: &mut egui::Ui,
+ db: &designcraft_fonts::ScopedFonts<'_>,
+ scope: u32,
+ family: &str,
+ style: &str,
+ query: &str,
+ max_height: f32,
+) -> (Option<char>, usize) {
+ let t = Tokens::get(ui.ctx());
+ let face = db.face(family, style);
+ let q = query.trim();
+ let code = q.strip_prefix("U+").or_else(|| q.strip_prefix("u+")).and_then(|h| u32::from_str_radix(h, 16).ok());
+ let mut chars: Vec<char> = face.chars().into_iter().map(|(c, _)| c).filter(|c| !c.is_control()).collect();
+ chars.sort();
+ chars.dedup();
+ if !q.is_empty() {
+ chars.retain(|c| Some(*c as u32) == code || q.contains(*c) || format!("{:04X}", *c as u32).contains(&q.to_ascii_uppercase()));
+ }
+ chars.truncate(MAX);
+ // The scroll bar floats over the grid's right edge: leave it room.
+ let scroll = &ui.spacing().scroll;
+ let bar = scroll.bar_inner_margin + scroll.bar_width + scroll.bar_outer_margin;
+ let cols = (((ui.available_width() - bar) / CELL).floor() as u32).max(1);
let ppp = ui.ctx().pixels_per_point();
- let cell_px = (CELL * ppp).round() as u32;
+ let cell_px = (CELL * ppp).round().max(1.0) as u32;
+ // The grid is one texture: no more rows than the GPU's largest texture holds (a narrow
+ // panel of a large CJK font ran past it).
+ let max_rows = (ui.ctx().input(|i| i.max_texture_side) as u32 / cell_px).max(1);
+ chars.truncate((max_rows * cols) as usize);
let ink = t.text_strong;
- let key = egui::Id::new(("glyph_grid", &st.family, &st.style, scope, &q, cols, cell_px, ink.to_array()));
+ let key = egui::Id::new(("glyph_grid", family, style, scope, q, cols, cell_px, ink.to_array()));
let tex: egui::TextureHandle = match ui.data(|d| d.get_temp::<egui::TextureHandle>(key)) {
Some(t) => t,
None => {
diff --cc crates/ui-egui/src/panels/table.rs
index 79b434a76,c1e80bd44..ba653364e
--- a/crates/ui-egui/src/panels/table.rs
+++ b/crates/ui-egui/src/panels/table.rs
@@@ -52,10 -52,10 +52,10 @@@ pub fn show(app: &mut DesignApp, ui: &m
("Col ←", "table.moveColumn", c0, c0.saturating_sub(1), c0 > 0),
("Col →", "table.moveColumn", c0, c0 + 1, c0 + 1 < nc),
] {
- if ui.add_enabled(ok, egui::Button::new(crate::rtl::widget(ui, label)).small()).clicked()
+ if ui.add_enabled(ok, egui::Button::new(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, label))).small()).clicked()
&& let Err(e) = app.run(id, json!({"from": from, "to": to}))
{
- app.status(format!("Table: {e}"));
+ app.status_error("Table", e);
}
}
});