>; 3]>, MobileError> {
- let failed = |e: String| file_error("reading the model's textures", e);
+ let failed = |e: String| file_error(crate::message!("reading the model's textures"), e);
let gpu = self.gpu.as_ref().ok_or_else(|| failed("the model is not shown yet".to_owned()))?;
let Some(scene) = self.scene.as_mut() else { return Ok(Vec::new()) };
let (current, painted) = (scene.current, scene.channel);
@@ -2450,7 +2458,7 @@ fn set_pixels(set: &mut TextureSet, gpu: Option<&procraft_gpu::Gpu>) -> Result 0 {
folder = folder.join(format!("c{channel}"));
}
- fs::create_dir_all(&folder).map_err(|e| file_error("making the folder", e))?;
+ fs::create_dir_all(&folder).map_err(|e| file_error(crate::message!("making the folder"), e))?;
for (id, rgba) in pixels {
let hash = pixels_hash(rgba);
let path = folder.join(format!("{}.png", id.0));
@@ -2625,10 +2636,11 @@ fn read_set_layers(folder: &Path, doc: &Document, side: u32) -> Pixels {
/// The model saved in the artwork folder `dir`, as `saved` describes it.
pub(crate) fn open_saved_model(dir: &Path, saved: &SavedModel) -> Result {
let extension = extension_of(&format!("model.{}", saved.extension));
- let bytes = fs::read(dir.join(format!("model.{extension}"))).map_err(|e| file_error("opening the model", e))?;
+ let bytes = fs::read(dir.join(format!("model.{extension}")))
+ .map_err(|e| file_error(crate::message!("opening the model"), e))?;
let mtl = fs::read_to_string(dir.join("model.mtl")).ok();
let mesh = read_model(&bytes, &extension, mtl.as_deref())
- .map_err(|e| file_error("opening the model", mesh_error_text(&e)))?;
+ .map_err(|e| file_error(crate::message!("opening the model"), mesh_error_text(&e)))?;
let side = saved.texture_size.clamp(64, MOST_TEXTURE_SIZE);
let waiting = saved
.sets
@@ -3906,8 +3918,8 @@ impl ModelInfo {
#[uniffi::export]
pub fn model_warning_name(warning: ModelWarning) -> String {
match warning {
- ModelWarning::OverlappingUvs => "Overlapping UV Coordinates",
- ModelWarning::RepeatingTextures => "Repeating Textures",
+ ModelWarning::OverlappingUvs => crate::tr("Overlapping UV Coordinates"),
+ ModelWarning::RepeatingTextures => crate::tr("Repeating Textures"),
}
.to_owned()
}
diff --git a/crates/core/src/selection.rs b/crates/core/src/selection.rs
index 85cacebe9..dc6231a7d 100644
--- a/crates/core/src/selection.rs
+++ b/crates/core/src/selection.rs
@@ -326,7 +326,7 @@ impl CanvasSession {
// the drag ends: one step from before it
st.join(shape, join, false);
st.selection_before = None;
- st.record_selection(before, "Automatic Selection");
+ st.record_selection(before, crate::message!("Automatic Selection"));
}
self.shared.frame(st);
}
@@ -359,7 +359,7 @@ impl CanvasSession {
st.feather_base = None;
m.invert();
st.selection = Some(m);
- st.record_selection(before, "invert");
+ st.record_selection(before, crate::message!("invert"));
self.shared.frame(st);
}
@@ -418,7 +418,7 @@ impl CanvasSession {
let st = &mut *guard;
let before = st.selection.take();
st.feather_base = None;
- st.record_selection(before, "clear selection");
+ st.record_selection(before, crate::message!("clear selection"));
self.shared.frame(st);
}
@@ -451,7 +451,7 @@ impl CanvasSession {
let before = st.selection.replace(m);
st.feather_base = None;
st.selection_outlines.clear();
- st.record_selection(before, "load selection");
+ st.record_selection(before, crate::message!("load selection"));
self.shared.frame(st);
true
}
diff --git a/crates/core/src/storage.rs b/crates/core/src/storage.rs
index 11ac5f30a..8f8d761e5 100644
--- a/crates/core/src/storage.rs
+++ b/crates/core/src/storage.rs
@@ -14,7 +14,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Mutex, MutexGuard, PoisonError};
/// What the apps say, once, when the storage is full.
-pub const NO_ROOM: &str = "Not enough storage: free some space to keep saving";
+pub const NO_ROOM: &str = crate::message!("Not enough storage: free some space to keep saving");
/// The system's numbers for a full storage: no space left, and a quota met.
#[cfg(windows)]
@@ -103,7 +103,11 @@ pub(crate) fn full_writes() -> u64 {
/// save works again; any other failure as [`crate::save_failure_said`] puts it.
#[uniffi::export]
pub fn save_failure_to_tell(reason: String) -> Option {
- if says_full(&reason) { tell_full().then(|| NO_ROOM.to_owned()) } else { Some(crate::save_failure_said(reason)) }
+ if says_full(&reason) {
+ tell_full().then(|| crate::tr(NO_ROOM).to_owned())
+ } else {
+ Some(crate::save_failure_said(reason))
+ }
}
/// What is asked when an artwork being left couldn't be saved for `reason` (the save's error),
@@ -111,14 +115,17 @@ pub fn save_failure_to_tell(reason: String) -> Option {
/// leaving without saving loses. The storage full says so first, plainly.
pub(crate) fn leave_unsaved_said(reason: &str, ever_saved: bool) -> (String, String) {
let loses = if ever_saved {
- "Leaving without saving loses the changes made since it was last saved."
+ crate::tr("Leaving without saving loses the changes made since it was last saved.")
} else {
- "Leaving without saving loses this artwork."
+ crate::tr("Leaving without saving loses this artwork.")
};
if says_full(reason) {
- ("Not enough storage".to_owned(), format!("Free some space to keep saving. {loses}"))
+ (
+ crate::tr("Not enough storage").to_owned(),
+ crate::trf("Free some space to keep saving. {0}", &[("0", &loses)]),
+ )
} else {
- ("This artwork couldn't be saved".to_owned(), loses.to_owned())
+ (crate::tr("This artwork couldn't be saved").to_owned(), loses.to_owned())
}
}
diff --git a/crates/core/src/studio.rs b/crates/core/src/studio.rs
index 43ffa042b..df22e9690 100644
--- a/crates/core/src/studio.rs
+++ b/crates/core/src/studio.rs
@@ -297,19 +297,29 @@ impl CanvasSession {
st.studio = Some((at, st.brush(st.tool).clone()));
st.studio_second = false;
}
- st.brush(st.tool).name.clone()
+ st.brush_display_name(at).unwrap_or_else(|| crate::i18n::stock_brush_name(&st.brush(st.tool).name, false))
}
/// Names the brush open in the studio (a dual brush's whole, not a part), as a set is named;
/// Cancel puts the old name back with the rest. Returns its name now: for a name of nothing
/// but spaces, which no brush has, the one it had when the studio opened.
pub fn set_studio_name(&self, name: String) -> String {
- let name = name.trim();
+ let name: String = name.trim().chars().take(256).collect();
let mut st = self.shared.lock();
- let Some(opened) = st.studio.as_ref().map(|(_, before)| before.name.clone()) else { return String::new() };
+ let Some(&(at, ref before)) = st.studio.as_ref() else { return String::new() };
+ let (opened_name, opened_stock_name) = (before.name.clone(), before.stock_name);
+ if st.brush_display_name(at).as_deref() == Some(name.as_str()) {
+ return name;
+ }
let Some(brush) = st.studio_whole() else { return String::new() };
- brush.name = if name.is_empty() { opened } else { name.chars().take(256).collect() };
- brush.name.clone()
+ if name.is_empty() {
+ brush.name = opened_name;
+ brush.stock_name = opened_stock_name;
+ } else {
+ brush.name = name;
+ brush.stock_name = Some(false);
+ }
+ st.brush_display_name(at).unwrap_or_default()
}
/// Whether the brush open in the studio is a dual brush.
@@ -611,10 +621,11 @@ impl CanvasSession {
let start = st.origin_brush(origin);
if let Some(brush) = st.studio_brush() {
let name = std::mem::take(&mut brush.name);
+ let stock_name = brush.stock_name;
let reset = brush.reset_point.take();
// back to its reset point, else to how it started
let back = reset.as_ref().map_or(start, |r| (*r.brush).clone());
- *brush = Brush { name, reset_point: reset, ..back };
+ *brush = Brush { name, stock_name, reset_point: reset, ..back };
}
}
@@ -788,8 +799,9 @@ impl CanvasSession {
let mut st = self.shared.lock();
for c in changes {
let Some(brush) = st.library.get_mut(c.set).and_then(|s| s.brushes.get_mut(c.index)) else { continue };
- if !c.name.is_empty() {
+ if !c.name.is_empty() && c.name != brush.name {
brush.name = c.name;
+ brush.stock_name = Some(false);
}
brush.set_settings(c.settings.iter().map(|(k, v)| (k.as_str(), *v)));
if c.curve.len() >= 2 {
diff --git a/crates/core/src/text.rs b/crates/core/src/text.rs
index 67206356d..42aff0289 100644
--- a/crates/core/src/text.rs
+++ b/crates/core/src/text.rs
@@ -472,7 +472,7 @@ impl CanvasSession {
let keep = keep && !(new && empty) && !unchanged;
if let Some(canvas) = st.canvas.as_mut() {
if keep {
- canvas.name_next_step("Text editing");
+ canvas.name_next_step(crate::message!("Text editing"));
}
canvas.release_layer(keep, keep.then(|| before.clone()));
}
@@ -601,7 +601,7 @@ impl CanvasSession {
/// Makes text layer `id` an ordinary layer, its pixels kept, as one undo step.
pub fn rasterize_layer(&self, id: u64) -> bool {
- self.change("rasterize", |d| d.rasterize(LayerId(id)).then_some(())).is_some()
+ self.change(crate::message!("rasterize"), |d| d.rasterize(LayerId(id)).then_some(())).is_some()
}
}
diff --git a/crates/core/src/text_draw.rs b/crates/core/src/text_draw.rs
index d0810aa4a..3da388cf8 100644
--- a/crates/core/src/text_draw.rs
+++ b/crates/core/src/text_draw.rs
@@ -762,6 +762,137 @@ pub fn draw_text(info: TextInfo, width: u32, height: u32) -> Vec {
out.rgba
}
+#[cfg(not(any(target_os = "android", target_os = "ios")))]
+pub struct InterfaceRun<'a> {
+ pub text: &'a str,
+ pub size: f32,
+ pub line_height: f32,
+ pub weight: u16,
+ pub colour: [u8; 4],
+}
+
+#[cfg(not(any(target_os = "android", target_os = "ios")))]
+pub struct InterfaceText {
+ pub size: [f32; 2],
+ pub pixels: [usize; 2],
+ pub rgba: Vec,
+}
+
+#[cfg(not(any(target_os = "android", target_os = "ios")))]
+pub fn draw_interface_text(
+ runs: &[InterfaceRun<'_>],
+ scale: f32,
+ width: Option,
+ centered: bool,
+ max_lines: usize,
+) -> Option {
+ use cosmic_text::{Color, Ellipsize, EllipsizeHeightLimit, Wrap};
+
+ let first = runs.first()?;
+ let metrics = |run: &InterfaceRun<'_>| Metrics::new(run.size * scale, run.line_height * scale);
+ let mut guard = fonts();
+ let Fonts { system, glyphs, .. } = &mut *guard;
+ let mut buffer = Buffer::new_empty(metrics(first));
+ let width = width.map(|w| (w * scale).max(1.0));
+ buffer.set_size(width, None);
+ buffer.set_wrap(if width.is_some() && max_lines != 1 { Wrap::WordOrGlyph } else { Wrap::None });
+ if max_lines != usize::MAX {
+ buffer.set_ellipsize(Ellipsize::End(EllipsizeHeightLimit::Lines(max_lines)));
+ }
+ let attrs = Attrs::new().family(Family::Name("Inter")); // i18n: literal
+ let runs = runs.iter().map(|run| {
+ let [r, g, b, a] = run.colour;
+ (run.text, attrs.clone().weight(Weight(run.weight)).metrics(metrics(run)).color(Color::rgba(r, g, b, a)))
+ });
+ buffer.set_rich_text(runs, &attrs, Shaping::Advanced, Some(Align::Left));
+ buffer.shape_until_scroll(system, false);
+ let mut wide: f32 = 0.0;
+ let mut tall: f32 = 0.0;
+ for line in buffer.layout_runs() {
+ wide = wide.max(line.line_w);
+ tall = line.line_top + line.line_height;
+ }
+ let w = wide.ceil() as u32;
+ let h = tall.ceil() as u32;
+ if w == 0 || h == 0 || w > 4092 || h > 4092 || w * h > 2_000_000 {
+ return None;
+ }
+ let mut out = Picture::new(w + 4, h + 4);
+ for line in buffer.layout_runs() {
+ let x = if centered { (wide - line.line_w) * 0.5 } else { 0.0 };
+ for glyph in line.glyphs {
+ let physical = glyph.physical((x + 2.0, line.line_y + 2.0), 1.0);
+ let Some(image) = glyphs.get_image(system, physical.cache_key) else { continue };
+ let [r, g, b, a] = glyph.color_opt.unwrap_or(Color::rgb(255, 255, 255)).as_rgba();
+ let ink = [r, g, b].map(|c| f32::from(c) / 255.0);
+ let alpha = f32::from(a) / 255.0;
+ each_pixel(image, physical.x, physical.y, |x, y, coverage| out.over(x, y, ink, coverage * alpha));
+ }
+ }
+ Some(InterfaceText {
+ size: [wide / scale, tall / scale],
+ pixels: [(w + 4) as usize, (h + 4) as usize],
+ rgba: out.rgba,
+ })
+}
+
+#[cfg(all(test, target_os = "windows"))]
+mod interface_text_tests {
+ use super::*;
+
+ #[test]
+ fn bengali_interface_joins_conjuncts() {
+ add_text_font(include_bytes!("../../../android/app/src/main/assets/fonts/Inter-Regular.ttf").to_vec());
+ add_system_text_fonts();
+ let label =
+ InterfaceRun {
+ text: "স্তর", size: 18.0, line_height: 24.0, weight: 400, colour: [255, 255, 255, 255]
+ };
+ let separate = InterfaceRun { text: "স্\u{200c}তর", ..label };
+ let ligature = draw_interface_text(&[label], 2.0, None, false, 1).unwrap();
+ let separated = draw_interface_text(&[separate], 2.0, None, false, 1).unwrap();
+ assert!(ligature.rgba.iter().any(|channel| *channel != 0));
+ assert_ne!(ligature.rgba, separated.rgba);
+ }
+
+ #[test]
+ fn devanagari_interface_joins_conjuncts() {
+ add_text_font(include_bytes!("../../../android/app/src/main/assets/fonts/Inter-Regular.ttf").to_vec());
+ add_system_text_fonts();
+ let label = InterfaceRun {
+ text: "क्षेत्र", size: 18.0, line_height: 24.0, weight: 400, colour: [255; 4]
+ };
+ let separate = InterfaceRun { text: "क्\u{200c}षेत्र", ..label };
+ let joined = draw_interface_text(&[label], 2.0, None, false, 1).unwrap();
+ let separated = draw_interface_text(&[separate], 2.0, None, false, 1).unwrap();
+ assert!(joined.rgba.iter().any(|channel| *channel != 0));
+ assert_ne!(joined.rgba, separated.rgba);
+ }
+
+ #[test]
+ fn arabic_interface_places_the_filename_left_of_the_arabic_label() {
+ add_text_font(include_bytes!("../../../android/app/src/main/assets/fonts/Inter-Regular.ttf").to_vec());
+ add_system_text_fonts();
+ let label =
+ InterfaceRun { text: "طبقة ", size: 16.0, line_height: 20.0, weight: 400, colour: [255, 0, 0, 255] };
+ let filename = InterfaceRun { text: "123.png", colour: [0, 255, 0, 255], ..label };
+ let image = draw_interface_text(&[label, filename], 2.0, None, false, 1).unwrap();
+ let mut first_arabic = usize::MAX;
+ let mut last_latin = None;
+ for (index, pixel) in image.rgba.as_chunks::<4>().0.iter().enumerate() {
+ let x = index % image.pixels[0];
+ if pixel[0] > 32 {
+ first_arabic = first_arabic.min(x);
+ }
+ if pixel[1] > 32 {
+ last_latin = Some(last_latin.map_or(x, |last: usize| last.max(x)));
+ }
+ }
+ assert_ne!(first_arabic, usize::MAX);
+ assert!(last_latin.unwrap() < first_arabic);
+ }
+}
+
/// The letters (and underlines) laid out as `laid`, each in its run's look, drawn into `out` with
/// the box's top left at `at`, where `inside` lets them.
fn letters(f: &mut Fonts, laid: &Laid, out: &mut Picture, at: (f32, f32), inside: impl Fn(i32, i32) -> bool) {
diff --git a/crates/core/src/timelapse.rs b/crates/core/src/timelapse.rs
index e27bb6029..1fe71ff5e 100644
--- a/crates/core/src/timelapse.rs
+++ b/crates/core/src/timelapse.rs
@@ -213,7 +213,12 @@ pub fn time_lapse_bits_per_pixel(s: TimeLapseSettings) -> u32 {
/// codec (Good, 1080p, H.264).
#[uniffi::export]
pub fn time_lapse_setting_names(s: TimeLapseSettings) -> Vec {
- let quality = ["Low", "Good", "Studio", "Lossless"].get(s.quality as usize).copied().unwrap_or("Good");
+ let quality = match s.quality {
+ 0 => crate::tr("Low"),
+ 2 => crate::tr("Studio"),
+ 3 => crate::tr("Lossless"),
+ _ => crate::tr("Good"),
+ };
let resolution = ["1080p", "2K", "4K"].get(s.resolution as usize).copied().unwrap_or("1080p");
let codec = if s.hevc { "HEVC" } else { "H.264" };
vec![quality.to_owned(), resolution.to_owned(), codec.to_owned()]
@@ -263,8 +268,9 @@ enum Problem {
}
/// What [`TimeLapse::take_problem`] says.
-const PROBLEM_TEXT: &str =
- "The time-lapse couldn't be kept. The disk may be full: replay and export leave out what wasn't kept.";
+const PROBLEM_TEXT: &str = crate::message!(
+ "The time-lapse couldn't be kept. The disk may be full: replay and export leave out what wasn't kept."
+);
struct State {
/// Frames kept so far, and the last picture's hash (a picture the same as it isn't kept).
@@ -329,7 +335,7 @@ impl TimeLapse {
let json = serde_json::json!({ "resolution": s.resolution, "quality": s.quality, "hevc": s.hevc });
let written = fs::create_dir_all(&self.dir).map_err(|e| e.to_string()).and_then(|()| {
write_atomically(&self.dir.join("settings.json"), |p| {
- crate::storage::write(p, json.to_string()).map_err(|e| file_error("saving", e))
+ crate::storage::write(p, json.to_string()).map_err(|e| file_error(crate::message!("saving"), e))
})
.map_err(|e| e.to_string())
});
@@ -587,12 +593,12 @@ impl TimeLapse {
let told = Problem::Told as u8;
if self.problem.compare_exchange(Problem::UntoldFull as u8, told, Relaxed, Relaxed).is_ok() {
// the storage full is told once, by this or a save, whichever meets it first
- return crate::storage::tell_full().then(|| crate::storage::NO_ROOM.to_owned());
+ return crate::storage::tell_full().then(|| crate::tr(crate::storage::NO_ROOM).to_owned());
}
self.problem
.compare_exchange(Problem::Untold as u8, told, Relaxed, Relaxed)
.is_ok()
- .then(|| PROBLEM_TEXT.to_owned())
+ .then(|| crate::tr(PROBLEM_TEXT).to_owned())
}
/// Frame `i`, straight RGBA (opaque); none if there is no such frame.
@@ -1146,7 +1152,7 @@ impl TimeLapse {
let plan = serde_json::json!({ "moves": moves, "placing": false, "videos": videos, "note": after });
log::info!("a time-lapse's {m} videos set aside, {total} frames made before it, put back in front of it");
let kept = write_atomically(&self.dir.join(RENUMBERING), |p| {
- crate::storage::write(p, plan.to_string()).map_err(|e| file_error("saving", e))
+ crate::storage::write(p, plan.to_string()).map_err(|e| file_error(crate::message!("saving"), e))
});
if kept.is_err() || !self.finish_renumbering() {
return;
@@ -1259,7 +1265,7 @@ impl TimeLapse {
let moves: Vec<(u32, u32)> = pictures.iter().zip(from..).map(|(&(_, was), now)| (was, now)).collect();
let plan = serde_json::json!({ "moves": moves, "placing": false });
let written = write_atomically(&self.dir.join(RENUMBERING), |p| {
- crate::storage::write(p, plan.to_string()).map_err(|e| file_error("saving", e))
+ crate::storage::write(p, plan.to_string()).map_err(|e| file_error(crate::message!("saving"), e))
});
if let Err(e) = written {
log::warn!("numbering a time-lapse's pictures again: {e}");
@@ -1291,7 +1297,7 @@ impl TimeLapse {
p.insert("placing".to_owned(), serde_json::Value::Bool(true));
}
let written = write_atomically(¬e, |p| {
- crate::storage::write(p, placing.to_string()).map_err(|e| file_error("saving", e))
+ crate::storage::write(p, placing.to_string()).map_err(|e| file_error(crate::message!("saving"), e))
});
if written.is_err() {
return false;
@@ -1314,7 +1320,7 @@ impl TimeLapse {
}
if let Some(after) = plan.get("note") {
let kept = write_atomically(&self.dir.join("segments.json"), |p| {
- crate::storage::write(p, after.to_string()).map_err(|e| file_error("saving", e))
+ crate::storage::write(p, after.to_string()).map_err(|e| file_error(crate::message!("saving"), e))
});
if kept.is_err() {
return false;
@@ -1329,7 +1335,7 @@ impl TimeLapse {
fn write_segments(&self, k: &Segments) {
let written = serde_json::to_string(k).map_err(|e| e.to_string()).and_then(|text| {
write_atomically(&self.dir.join("segments.json"), |p| {
- crate::storage::write(p, text).map_err(|e| file_error("saving", e))
+ crate::storage::write(p, text).map_err(|e| file_error(crate::message!("saving"), e))
})
.map_err(|e| e.to_string())
});
diff --git a/crates/core/src/transform.rs b/crates/core/src/transform.rs
index 65a5293fe..c09322d45 100644
--- a/crates/core/src/transform.rs
+++ b/crates/core/src/transform.rs
@@ -401,10 +401,10 @@ impl State {
{
if commit {
canvas.name_next_step(match self.transform_mode {
- procraft_engine::transform::TransformMode::Freeform => "non-uniform transform",
- procraft_engine::transform::TransformMode::Uniform => "uniform transform",
- procraft_engine::transform::TransformMode::Distort => "distort transform",
- procraft_engine::transform::TransformMode::Warp => "warp transform",
+ procraft_engine::transform::TransformMode::Freeform => crate::message!("non-uniform transform"),
+ procraft_engine::transform::TransformMode::Uniform => crate::message!("uniform transform"),
+ procraft_engine::transform::TransformMode::Distort => crate::message!("distort transform"),
+ procraft_engine::transform::TransformMode::Warp => crate::message!("warp transform"),
});
}
match within {
diff --git a/crates/core/src/tween.rs b/crates/core/src/tween.rs
index 586c8c830..fdde4cf03 100644
--- a/crates/core/src/tween.rs
+++ b/crates/core/src/tween.rs
@@ -57,7 +57,7 @@ impl CanvasSession {
let n = animation::frames(&st.doc).len();
st.doc.rename(made, &format!("Frame {n}"));
if let Some(canvas) = st.canvas.as_mut() {
- canvas.name_next_step("in-between");
+ canvas.name_next_step(crate::message!("in-between"));
canvas.write_layer_parts_and_document(vec![(made, within, part)], before);
}
st.revision += 1;
diff --git a/crates/engine/src/brush.rs b/crates/engine/src/brush.rs
index 82108582f..ec52edf20 100644
--- a/crates/engine/src/brush.rs
+++ b/crates/engine/src/brush.rs
@@ -535,7 +535,7 @@ pub fn grain_blends() -> Vec<(u32, &'static str)> {
.iter()
.map(|m| (m.id(), m.name()))
.collect();
- modes.extend([(GRAIN_HEIGHT, "Height"), (GRAIN_LINEAR_HEIGHT, "Linear Height")]);
+ modes.extend([(GRAIN_HEIGHT, crate::message!("Height")), (GRAIN_LINEAR_HEIGHT, crate::message!("Linear Height"))]);
modes
}
@@ -558,7 +558,7 @@ pub fn combine_modes() -> Vec<(u32, &'static str)> {
]
.iter()
.map(|m| (m.id(), m.name()))
- .chain([(GRAIN_LINEAR_HEIGHT, "Linear Height")])
+ .chain([(GRAIN_LINEAR_HEIGHT, crate::message!("Linear Height"))])
.collect()
}
@@ -571,7 +571,7 @@ pub const BRUSH_BEHIND: u32 = 29;
pub fn brush_blends() -> Vec<(u32, &'static str)> {
let mut modes: Vec<(u32, &'static str)> =
crate::document::BlendMode::ALL.iter().map(|m| (m.id(), m.name())).collect();
- modes.push((BRUSH_BEHIND, "Behind"));
+ modes.push((BRUSH_BEHIND, crate::message!("Behind")));
modes
}
@@ -748,6 +748,7 @@ const TILT_SPAN_HIGH: f32 = 0.80901;
#[derive(Clone, Debug, PartialEq)]
pub struct Brush {
pub name: String,
+ pub stock_name: Option,
/// Distance between stamps, as a fraction of the stamp diameter.
pub spacing: f32,
/// Smoothing of the stroke's path, 0..1.
@@ -941,6 +942,7 @@ impl Brush {
pub fn round_pen() -> Brush {
Brush {
name: "Round Pen".to_owned(),
+ stock_name: None,
spacing: 0.08,
streamline: 0.015,
pressure_smoothing: 0.0,
diff --git a/crates/engine/src/document.rs b/crates/engine/src/document.rs
index 33ec04538..41a2aa390 100644
--- a/crates/engine/src/document.rs
+++ b/crates/engine/src/document.rs
@@ -117,33 +117,33 @@ impl BlendMode {
pub fn name(self) -> &'static str {
match self {
- BlendMode::Normal => "Normal",
- BlendMode::Multiply => "Multiply",
- BlendMode::Darken => "Darken",
- BlendMode::Shade => "Shade",
- BlendMode::ColorBurn => "Color Burn",
- BlendMode::LinearBurn => "Linear Burn",
- BlendMode::DarkerColor => "Darker Color",
- BlendMode::Lighten => "Lighten",
- BlendMode::Screen => "Screen",
- BlendMode::ColorDodge => "Color Dodge",
- BlendMode::Add => "Add",
- BlendMode::LighterColor => "Lighter Color",
- BlendMode::Overlay => "Overlay",
- BlendMode::SoftLight => "Soft Light",
- BlendMode::HardLight => "Hard Light",
- BlendMode::VividLight => "Vivid Light",
- BlendMode::LinearLight => "Linear Light",
- BlendMode::PinLight => "Pin Light",
- BlendMode::HardMix => "Hard Mix",
- BlendMode::Difference => "Difference",
- BlendMode::Exclusion => "Exclusion",
- BlendMode::Subtract => "Subtract",
- BlendMode::Divide => "Divide",
- BlendMode::Hue => "Hue",
- BlendMode::Saturation => "Saturation",
- BlendMode::Color => "Color",
- BlendMode::Luminosity => "Luminosity",
+ BlendMode::Normal => crate::message!("Normal"),
+ BlendMode::Multiply => crate::message!("Multiply"),
+ BlendMode::Darken => crate::message!("Darken"),
+ BlendMode::Shade => crate::message!("Shade"),
+ BlendMode::ColorBurn => crate::message!("Color Burn"),
+ BlendMode::LinearBurn => crate::message!("Linear Burn"),
+ BlendMode::DarkerColor => crate::message!("Darker Color"),
+ BlendMode::Lighten => crate::message!("Lighten"),
+ BlendMode::Screen => crate::message!("Screen"),
+ BlendMode::ColorDodge => crate::message!("Color Dodge"),
+ BlendMode::Add => crate::message!("Add"),
+ BlendMode::LighterColor => crate::message!("Lighter Color"),
+ BlendMode::Overlay => crate::message!("Overlay"),
+ BlendMode::SoftLight => crate::message!("Soft Light"),
+ BlendMode::HardLight => crate::message!("Hard Light"),
+ BlendMode::VividLight => crate::message!("Vivid Light"),
+ BlendMode::LinearLight => crate::message!("Linear Light"),
+ BlendMode::PinLight => crate::message!("Pin Light"),
+ BlendMode::HardMix => crate::message!("Hard Mix"),
+ BlendMode::Difference => crate::message!("Difference"),
+ BlendMode::Exclusion => crate::message!("Exclusion"),
+ BlendMode::Subtract => crate::message!("Subtract"),
+ BlendMode::Divide => crate::message!("Divide"),
+ BlendMode::Hue => crate::message!("Hue"),
+ BlendMode::Saturation => crate::message!("Saturation"),
+ BlendMode::Color => crate::message!("Color"),
+ BlendMode::Luminosity => crate::message!("Luminosity"),
}
}
}
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 83daf9944..c0c53f717 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -2,6 +2,14 @@
//! view. No GPU and no platform code: `procraft-gpu` draws what this crate describes, and the app
//! feeds it input.
+/// Marks fallback text kept in a table or passed to the app for display.
+#[macro_export]
+macro_rules! message {
+ ($source:literal) => {
+ $source
+ };
+}
+
pub mod abr;
pub mod animation;
pub mod applz4;
diff --git a/desktop/Cargo.toml b/desktop/Cargo.toml
index 1be1c21af..22f68b799 100644
--- a/desktop/Cargo.toml
+++ b/desktop/Cargo.toml
@@ -54,6 +54,7 @@ objc2-foundation = { version = "0.3", default-features = false, features = [
"NSDictionary",
"NSEnumerator",
"NSError",
+ "NSLocale",
"NSObject",
"NSProcessInfo",
"NSString",
@@ -84,7 +85,6 @@ objc2-core-foundation = { version = "0.3", default-features = false, features =
] }
# The fonts for other scripts found by family (Core Text), and their faces in a collection
objc2-core-text = { version = "0.3", default-features = false, features = ["std", "CTFont", "CTFontDescriptor"] }
-swash = "0.2"
# A PDF's pages drawn by the system's renderer (Core Graphics)
objc2-core-graphics = { version = "0.3", default-features = false, features = [
"std",
@@ -130,6 +130,7 @@ windows = { version = "0.62", features = [
"Win32_Foundation",
"Win32_Graphics_Dxgi",
"Win32_Graphics_Gdi",
+ "Win32_Globalization",
"Win32_Media_Audio",
"Win32_Media_MediaFoundation",
"Win32_System_Com",
@@ -151,6 +152,7 @@ clipboard-win = "5.4"
# unwinder; the version the workspace already has)
[target.'cfg(unix)'.dependencies]
libc = "0.2"
+swash = "0.2"
# A tablet's pen under X11, which winit gives as the mouse: its pressure, lean and eraser end from
# its own XInput 2 events
diff --git a/desktop/src/actions.rs b/desktop/src/actions.rs
index 806802c80..d05d3eed0 100644
--- a/desktop/src/actions.rs
+++ b/desktop/src/actions.rs
@@ -3,6 +3,8 @@
//! Smoothing). Rows the desktop can't do yet show dimmed, as the Android app's own rows still to
//! come do. Share writes the artwork to a file.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use std::collections::HashMap;
use std::time::Instant;
@@ -188,50 +190,50 @@ fn model_groups(tab: usize, showing: &Showing) -> Vec> {
match tab {
0 => vec![
vec![
- Button("Insert a file", None, Some(Act::InsertFile)),
- Button("Insert a photo", None, Some(Act::InsertPhoto)),
- Button("Take a photo", None, None),
+ Button(tr("Insert a file"), None, Some(Act::InsertFile)),
+ Button(tr("Insert a photo"), None, Some(Act::InsertPhoto)),
+ Button(tr("Take a photo"), None, None),
],
vec![
- Button("Cut", None, Some(Act::Cut)),
- Button("Copy", None, Some(Act::Copy)),
- Button("Copy canvas", None, Some(Act::CopyCanvas)),
- Button("Paste", None, showing.can_paste.then_some(Act::Paste)),
+ Button(tr("Cut"), None, Some(Act::Cut)),
+ Button(tr("Copy"), None, Some(Act::Copy)),
+ Button(tr("Copy canvas"), None, Some(Act::CopyCanvas)),
+ Button(tr("Paste"), None, showing.can_paste.then_some(Act::Paste)),
],
],
1 => vec![
- vec![Switch("Reference", showing.reference, Some(Act::Reference))],
- vec![Button("Canvas information", None, Some(Act::CanvasInfo))],
+ vec![Switch(tr("Reference"), showing.reference, Some(Act::Reference))],
+ vec![Button(tr("Canvas information"), None, Some(Act::CanvasInfo))],
],
2 => vec![
vec![
- Heading("Share Model"),
+ Heading(tr("Share Model")),
// ours comes back whole in another copy of the app; the other package holds no
// model yet
- Button("ProCraft", None, Some(Act::Share(Format::ModelArtwork))),
- Button("Procreate", None, None),
- Button("USDZ", None, Some(Act::Share(Format::ModelUsdz))),
- Button("OBJ", None, Some(Act::Share(Format::ModelObj))),
+ Button(tr("ProCraft"), None, Some(Act::Share(Format::ModelArtwork))),
+ Button(tr("Procreate"), None, None),
+ Button(tr("USDZ"), None, Some(Act::Share(Format::ModelUsdz))),
+ Button(tr("OBJ"), None, Some(Act::Share(Format::ModelObj))),
],
vec![
- Heading("Share Image"),
- Button("JPEG", None, Some(Act::Share(Format::ModelJpeg))),
- Button("PNG", None, Some(Act::Share(Format::ModelRender))),
- Button("TIFF", None, Some(Act::Share(Format::ModelTiff))),
- Button("Animated GIF", None, Some(Act::ModelAnimated(Animated::Gif))),
- Button("Animated PNG", None, Some(Act::ModelAnimated(Animated::Png))),
- Button("Animated MP4", None, Some(Act::ModelAnimated(Animated::Mp4))),
- Button("Animated HEVC", None, Some(Act::ModelAnimated(Animated::Hevc))),
+ Heading(tr("Share Image")),
+ Button(tr("JPEG"), None, Some(Act::Share(Format::ModelJpeg))),
+ Button(tr("PNG"), None, Some(Act::Share(Format::ModelRender))),
+ Button(tr("TIFF"), None, Some(Act::Share(Format::ModelTiff))),
+ Button(tr("Animated GIF"), None, Some(Act::ModelAnimated(Animated::Gif))),
+ Button(tr("Animated PNG"), None, Some(Act::ModelAnimated(Animated::Png))),
+ Button(tr("Animated MP4"), None, Some(Act::ModelAnimated(Animated::Mp4))),
+ Button(tr("Animated HEVC"), None, Some(Act::ModelAnimated(Animated::Hevc))),
],
- vec![Heading("Share Textures"), Button("PNG", None, Some(Act::Share(Format::ModelTextures)))],
+ vec![Heading(tr("Share Textures")), Button(tr("PNG"), None, Some(Act::Share(Format::ModelTextures)))],
],
_ => vec![
vec![
- Switch("Show 2D texture", showing.model_flat, Some(Act::ModelFlat)),
- Switch("Paint through mesh", showing.paint_through, shown.then_some(Act::PaintThrough)),
- Button("Edit lighting & environment", None, shown.then_some(Act::LightingStudio)),
+ Switch(tr("Show 2D texture"), showing.model_flat, Some(Act::ModelFlat)),
+ Switch(tr("Paint through mesh"), showing.paint_through, shown.then_some(Act::PaintThrough)),
+ Button(tr("Edit lighting & environment"), None, shown.then_some(Act::LightingStudio)),
],
- vec![Button("View in AR", None, None)],
+ vec![Button(tr("View in AR"), None, None)],
],
}
}
@@ -244,22 +246,22 @@ enum Tapped {
}
const TABS: [(&str, &icons::Icon); 6] = [
- ("Add", &icons::TAB_ADD),
- ("Canvas", &icons::TAB_CANVAS),
- ("Share", &icons::TAB_SHARE),
- ("Video", &icons::TAB_VIDEO),
- ("Prefs", &icons::TAB_PREFS),
- ("Help", &icons::TAB_HELP),
+ (procraft_core::message!("Add"), &icons::TAB_ADD),
+ (procraft_core::message!("Canvas"), &icons::TAB_CANVAS),
+ (procraft_core::message!("Share"), &icons::TAB_SHARE),
+ (procraft_core::message!("Video"), &icons::TAB_VIDEO),
+ (procraft_core::message!("Prefs"), &icons::TAB_PREFS),
+ (procraft_core::message!("Help"), &icons::TAB_HELP),
];
/// On a model, its own tab takes Video's place.
const MODEL_TABS: [(&str, &icons::Icon); 6] = [
- ("Add", &icons::TAB_ADD),
- ("Canvas", &icons::TAB_CANVAS),
- ("Share", &icons::TAB_SHARE),
- ("3D", &icons::TAB3_D),
- ("Prefs", &icons::TAB_PREFS),
- ("Help", &icons::TAB_HELP),
+ (procraft_core::message!("Add"), &icons::TAB_ADD),
+ (procraft_core::message!("Canvas"), &icons::TAB_CANVAS),
+ (procraft_core::message!("Share"), &icons::TAB_SHARE),
+ (procraft_core::message!("3D"), &icons::TAB3_D),
+ (procraft_core::message!("Prefs"), &icons::TAB_PREFS),
+ (procraft_core::message!("Help"), &icons::TAB_HELP),
];
/// What the rows show besides the settings: something to paste, and Animation or Page Assist,
@@ -353,63 +355,68 @@ fn groups(tab: usize, showing: &Showing, prefs: &Prefs) -> Vec> {
vec![
// swiped to the left, the first three and Paste put what they bring on a private
// layer
- Private("Insert a file", "Insert a private file", Some(Act::InsertFile), Some(Act::InsertPrivateFile)),
Private(
- "Insert a photo",
- "Insert a private photo",
+ tr("Insert a file"),
+ tr("Insert a private file"),
+ Some(Act::InsertFile),
+ Some(Act::InsertPrivateFile),
+ ),
+ Private(
+ tr("Insert a photo"),
+ tr("Insert a private photo"),
Some(Act::InsertPhoto),
Some(Act::InsertPrivatePhoto),
),
- Private("Take a photo", "Take a private photo", None, None),
- Button("Add text", None, Some(Act::AddText)),
+ Private(tr("Take a photo"), tr("Take a private photo"), None, None),
+ Button(tr("Add text"), None, Some(Act::AddText)),
],
vec![
- Button("Cut", None, Some(Act::Cut)),
- Button("Copy", None, Some(Act::Copy)),
- Button("Copy canvas", None, Some(Act::CopyCanvas)),
+ Button(tr("Cut"), None, Some(Act::Cut)),
+ Button(tr("Copy"), None, Some(Act::Copy)),
+ Button(tr("Copy canvas"), None, Some(Act::CopyCanvas)),
Private(
- "Paste",
- "Paste Private",
+ tr("Paste"),
+ tr("Paste Private"),
showing.can_paste.then_some(Act::Paste),
showing.can_paste.then_some(Act::PastePrivate),
),
],
],
1 => vec![
- vec![Button("Crop & Resize", None, Some(Act::Crop))],
+ vec![Button(tr("Crop & Resize"), None, Some(Act::Crop))],
vec![
- Switch("Animation Assist", showing.animation, Some(Act::AnimationAssist)),
- Switch("Page Assist", showing.pages, Some(Act::PageAssist)),
- Switch("Drawing Guide", showing.guide, Some(Act::DrawingGuide)),
+ Switch(tr("Animation Assist"), showing.animation, Some(Act::AnimationAssist)),
+ Switch(tr("Page Assist"), showing.pages, Some(Act::PageAssist)),
+ Switch(tr("Drawing Guide"), showing.guide, Some(Act::DrawingGuide)),
// greyed until the guide is on
- Button("Edit Drawing Guide", None, showing.guide.then_some(Act::EditGuide)),
+ Button(tr("Edit Drawing Guide"), None, showing.guide.then_some(Act::EditGuide)),
],
- vec![Switch("Reference", showing.reference, Some(Act::Reference))],
+ vec![Switch(tr("Reference"), showing.reference, Some(Act::Reference))],
vec![
- Button("Flip horizontal", None, Some(Act::Flip { horizontal: true })),
- Button("Flip vertical", None, Some(Act::Flip { horizontal: false })),
+ Button(tr("Flip horizontal"), None, Some(Act::Flip { horizontal: true })),
+ Button(tr("Flip vertical"), None, Some(Act::Flip { horizontal: false })),
],
- vec![Button("Canvas information", None, Some(Act::CanvasInfo))],
+ vec![Button(tr("Canvas information"), None, Some(Act::CanvasInfo))],
]
.into_iter()
// what plugins put here
.chain(Some(plugin_placed_rows(showing)).filter(|rows| !rows.is_empty()))
// and Edit Layout, while a plugin lets the bars move
- .chain(showing.edit_layout.then(|| vec![Button("Edit Layout", None, Some(Act::EditLayout))]))
+ .chain(showing.edit_layout.then(|| vec![Button(tr(tr("Edit Layout")), None, Some(Act::EditLayout))]))
.collect(),
2 => vec![
vec![
- Heading("Share Image"),
- Button("ProCraft", None, Some(Act::Share(Format::Procraft))),
- Button("Procreate", None, Some(Act::Share(Format::Package))),
- Button("PSD", None, Some(Act::Share(Format::Psd))),
- Button("PDF", None, Some(Act::Share(Format::Pdf))),
- Button("JPEG", None, Some(Act::Share(Format::Jpeg))),
- Button("PNG", None, Some(Act::Share(Format::Png))),
- Button("TIFF", None, Some(Act::Share(Format::Tiff))),
+ Heading(tr("Share Image")),
+ Button(tr("ProCraft"), None, Some(Act::Share(Format::Procraft))),
+ Button(tr("Procreate"), None, Some(Act::Share(Format::Package))),
+ Button(tr("PSD"), None, Some(Act::Share(Format::Psd))),
+ Button(tr("PDF"), None, Some(Act::Share(Format::Pdf))),
+ Button(tr("JPEG"), None, Some(Act::Share(Format::Jpeg))),
+ Button(tr("PNG"), None, Some(Act::Share(Format::Png))),
+ Button(tr("TIFF"), None, Some(Act::Share(Format::Tiff))),
]
.into_iter()
- .chain(showing.svg.then_some(Button("SVG", None, Some(Act::Share(Format::Svg)))))
+ .chain(showing.svg.then_some(Button(tr("SVG"), None, Some(Act::Share(Format::Svg)))))
// files plugins make of the artwork's layers, under their own names
.chain(
showing
@@ -421,68 +428,75 @@ fn groups(tab: usize, showing: &Showing, prefs: &Prefs) -> Vec> {
)
.collect(),
vec![
- Heading("Share Layers"),
- Button("PDF", None, Some(Act::Share(Format::LayersPdf))),
- Button("PNG Files", None, Some(Act::Share(Format::LayerPngs))),
- Button("Animated GIF", None, Some(Act::AnimatedExport(Animated::Gif))),
- Button("Animated PNG", None, Some(Act::AnimatedExport(Animated::Png))),
- Button("Animated MP4", None, Some(Act::AnimatedExport(Animated::Mp4))),
- Button("Animated HEVC", None, Some(Act::AnimatedExport(Animated::Hevc))),
+ Heading(tr("Share Layers")),
+ Button(tr("PDF"), None, Some(Act::Share(Format::LayersPdf))),
+ Button(tr("PNG Files"), None, Some(Act::Share(Format::LayerPngs))),
+ Button(tr("Animated GIF"), None, Some(Act::AnimatedExport(Animated::Gif))),
+ Button(tr("Animated PNG"), None, Some(Act::AnimatedExport(Animated::Png))),
+ Button(tr("Animated MP4"), None, Some(Act::AnimatedExport(Animated::Mp4))),
+ Button(tr("Animated HEVC"), None, Some(Act::AnimatedExport(Animated::Hevc))),
],
],
3 => vec![
vec![
- Button("Time-lapse Replay", None, showing.time_lapse_recorded.then_some(Act::TimeLapseReplay)),
- Switch("Time-lapse Recording", showing.time_lapse, Some(Act::TimeLapseRecording)),
+ Button(tr("Time-lapse Replay"), None, showing.time_lapse_recorded.then_some(Act::TimeLapseReplay)),
+ Switch(tr("Time-lapse Recording"), showing.time_lapse, Some(Act::TimeLapseRecording)),
],
- vec![Button("Export time-lapse video", None, showing.time_lapse_recorded.then_some(Act::ExportTimeLapse))],
+ vec![Button(
+ tr("Export time-lapse video"),
+ None,
+ showing.time_lapse_recorded.then_some(Act::ExportTimeLapse),
+ )],
],
4 => {
let delay = prefs.rapid_undo_delay;
let visibility = prefs.selection_visibility;
vec![
vec![
- Switch("Light interface", prefs.light_interface, Some(Act::LightInterface)),
- Switch("Right-hand interface", prefs.right_handed, Some(Act::RightHanded)),
+ Switch(tr("Light interface"), prefs.light_interface, Some(Act::LightInterface)),
+ Switch(tr("Right-hand interface"), prefs.right_handed, Some(Act::RightHanded)),
Button(
- "Brush scaling",
+ tr("Brush scaling"),
Some(if prefs.brush_on_screen { "Screen" } else { "Canvas" }),
Some(Act::ScalingMenu),
),
- Switch("Project canvas", prefs.project_canvas, Some(Act::ProjectCanvas)),
- Switch("Brush cursor", prefs.brush_cursor, Some(Act::BrushCursor)),
- Button("Advanced cursor settings", None, Some(Act::Page(Page::Cursor))),
+ Switch(tr("Project canvas"), prefs.project_canvas, Some(Act::ProjectCanvas)),
+ Switch(tr("Brush cursor"), prefs.brush_cursor, Some(Act::BrushCursor)),
+ Button(tr("Advanced cursor settings"), None, Some(Act::Page(Page::Cursor))),
],
vec![
- Button("Pen buttons", None, Some(Act::Page(Page::PenButtons))),
- Button("Pressure and Smoothing", None, Some(Act::Page(Page::Pressure))),
- Button("Gesture controls", None, Some(Act::GestureControls)),
- Button("Plugins", None, Some(Act::Page(Page::Plugins))),
+ Button(tr(tr("Pen buttons")), None, Some(Act::Page(Page::PenButtons))),
+ Button(tr("Pressure and Smoothing"), None, Some(Act::Page(Page::Pressure))),
+ Button(tr(tr("Gesture controls")), None, Some(Act::GestureControls)),
+ Button(tr("Plugins"), None, Some(Act::Page(Page::Plugins))),
],
vec![
Slide(
- "Rapid undo delay",
+ tr("Rapid undo delay"),
format!("{delay:.2}s"),
(delay - RAPID_UNDO_MIN_S) / (RAPID_UNDO_MAX_S - RAPID_UNDO_MIN_S),
SLIDE_HEIGHT,
Slid::RapidUndo,
),
Slide(
- "Selection mask visibility",
+ tr("Selection mask visibility"),
format!("{:.1}%", visibility * 100.0),
visibility,
SLIDE_HEIGHT,
Slid::SelectionVisibility,
),
],
- vec![Switch("Size & Opacity sidebar", showing.side_bar, Some(Act::SideBar))],
+ vec![Switch(tr("Size & Opacity sidebar"), showing.side_bar, Some(Act::SideBar))],
]
}
_ => vec![
- vec![Button("About ProCraft", None, Some(Act::About)), Button("Licences", None, Some(Act::Licences))],
vec![
- Button("Keyboard shortcuts", None, Some(Act::Shortcuts)),
- Button("Advanced settings", None, Some(Act::AdvancedSettings)),
+ Button(tr("About ProCraft"), None, Some(Act::About)),
+ Button(tr("Licences"), None, Some(Act::Licences)),
+ ],
+ vec![
+ Button(tr("Keyboard shortcuts"), None, Some(Act::Shortcuts)),
+ Button(tr("Advanced settings"), None, Some(Act::AdvancedSettings)),
],
],
}
@@ -490,18 +504,18 @@ fn groups(tab: usize, showing: &Showing, prefs: &Prefs) -> Vec> {
/// Pressure and Smoothing's sliders.
fn smoothing_rows(prefs: &Prefs) -> Vec {
- let percent = |v: f32| if v <= 0.0 { "None".to_owned() } else { format!("{:.1}%", v * 100.0) };
+ let percent = |v: f32| if v <= 0.0 { tr("None").to_owned() } else { format!("{:.1}%", v * 100.0) };
vec![
- Row::Slide("Stabilization", percent(prefs.stabilization), prefs.stabilization, 64.0, Slid::Stabilization),
+ Row::Slide(tr("Stabilization"), percent(prefs.stabilization), prefs.stabilization, 64.0, Slid::Stabilization),
Row::Slide(
- "Motion Filtering",
+ tr("Motion Filtering"),
percent(prefs.motion_filtering),
prefs.motion_filtering,
64.0,
Slid::MotionFiltering,
),
Row::Slide(
- "Motion Filtering Expression",
+ tr("Motion Filtering Expression"),
percent(prefs.motion_expression),
prefs.motion_expression,
64.0,
@@ -949,7 +963,7 @@ impl Actions {
ui.painter(),
pos2(body.left() + 24.0, body.top() + 22.0),
Align2::LEFT_TOP,
- "Actions",
+ tr("Actions"),
24.0,
Weight::Bold,
argb(PANEL_TITLE),
@@ -969,7 +983,7 @@ impl Actions {
look.icon(ui, icon, pos2(cell.center().x, cell.top() + 24.0), 50.0, tint);
let ink = if lit { argb(pc::TEXT) } else { argb(TAB_IDLE) };
let at = pos2(cell.center().x, cell.top() + 41.0);
- text(ui.painter(), at, Align2::CENTER_TOP, label, 12.0, Weight::Medium, ink);
+ text(ui.painter(), at, Align2::CENTER_TOP, tr(label), 12.0, Weight::Medium, ink);
}
let list = Rect::from_min_max(
pos2(body.left() + 12.0, tabs_top + 60.0 + 20.0),
@@ -1018,7 +1032,7 @@ impl Actions {
self.scaling.close();
return false;
};
- let labels = ["Relative to canvas", "Relative to screen"];
+ let labels = [tr("Relative to canvas"), tr("Relative to screen")];
let chosen = usize::from(prefs.brush_on_screen);
let Some(picked) = choice_menu(&mut self.scaling, ctx, look, backdrops, "brush scaling", row, &labels, chosen)
else {
@@ -1067,7 +1081,7 @@ impl Actions {
if prefs.plugins.remove(id).is_some() {
return true;
}
- crate::files::say("This couldn't be removed.");
+ crate::files::say(tr("This couldn't be removed."));
false
}
Some(_) => {
@@ -1081,8 +1095,8 @@ impl Actions {
/// Asks before `plugin` goes, its name in the question.
fn ask_remove(&mut self, plugin: &PluginInfo) {
self.remove_what = Some(plugin.id.clone());
- let message = format!("\u{201c}{}\u{201d} goes, and its settings with it.", plugin.name);
- self.removing.open("Remove this plugin?", &message, "Remove", Some(&icons::TRASH));
+ let message = procraft_core::trf("\u{201c}{0}\u{201d} goes, and its settings with it.", &[("0", &plugin.name)]);
+ self.removing.open(tr("Remove this plugin?"), &message, tr("Remove"), Some(&icons::TRASH));
}
/// Follows the press on a plugin card's head: moved first, it is left to the list; held still,
@@ -1137,12 +1151,12 @@ impl Actions {
/// The plugins, a card each, drawn from what the list says of them. A slider's value goes in as
/// it lets go, unless it is live: what it sets may move the slider.
fn plugins_page(&mut self, ui: &mut Ui, look: &mut Look, body: Rect, prefs: &mut Prefs) -> Option {
- if self.page_header(ui, look, body, "Plugins") {
+ if self.page_header(ui, look, body, tr("Plugins")) {
return None;
}
let button = Rect::from_min_size(pos2(body.right() - 12.0 - 72.0, body.top() + 12.0 + 5.0), vec2(72.0, 34.0));
let at = pos2(button.right() - 4.0, button.center().y);
- text(ui.painter(), at, Align2::RIGHT_CENTER, "Import", 17.0, Weight::Regular, argb(pc::ACCENT));
+ text(ui.painter(), at, Align2::RIGHT_CENTER, tr("Import"), 17.0, Weight::Regular, argb(pc::ACCENT));
let import = ui.interact(button, ui.scope_id().with("import plugin"), Sense::click()).clicked();
let list = Rect::from_min_max(
pos2(body.left() + 12.0, body.top() + 12.0 + 44.0 + 8.0),
@@ -1169,10 +1183,15 @@ impl Actions {
if shown.is_empty() {
let width = ui.available_width();
let (area, _) = ui.allocate_exact_size(vec2(width, PLUGINS_EMPTY), Sense::hover());
- let words = "Nothing imported yet. Import a .procraft-plugin file to add one.";
+ let words = tr("Nothing imported yet. Import a .procraft-plugin file to add one.");
let inside = width - 2.0 * PLUGIN_INSET;
let said = wrapped(ui.painter(), words, 15.0, Weight::Regular, argb(ACTIONS_ROW), inside);
- ui.painter().galley(area.min + vec2(PLUGIN_INSET, 8.0), said, argb(ACTIONS_ROW));
+ crate::look::draw_layout(
+ ui.painter(),
+ area.min + vec2(PLUGIN_INSET, 8.0),
+ said,
+ argb(ACTIONS_ROW),
+ );
}
for (g, plugin) in shown.iter().enumerate() {
if g > 0 {
@@ -1232,7 +1251,7 @@ impl Actions {
text(&painter, name_at, Align2::LEFT_TOP, &plugin.name, 17.0, Weight::SemiBold, Color32::WHITE);
let inside = at.width() - 2.0 * PLUGIN_INSET;
let said = wrapped(&painter, &plugin.description, 14.0, Weight::Regular, Color32::WHITE, inside);
- painter.galley(pos2(left, at.top() + PLUGIN_HEAD), said, Color32::WHITE);
+ crate::look::draw_layout(&painter, pos2(left, at.top() + PLUGIN_HEAD), said, Color32::WHITE);
}
});
self.card_rects = card_rects;
@@ -1259,12 +1278,12 @@ impl Actions {
/// blue; a choice tapped sets it and comes back.
fn pen_buttons_page(&mut self, ui: &mut Ui, look: &mut Look, body: Rect, prefs: &mut Prefs) -> Option {
let label = |a: Option| {
- a.map_or("Gesture controls".to_owned(), procraft_core::quick_action_label)
+ a.map_or(tr("Gesture controls").to_owned(), procraft_core::quick_action_label)
};
let title = match self.pen_picking {
- None => "Pen buttons",
- Some(false) => "Pen button",
- Some(true) => "Pen second button",
+ None => tr("Pen buttons"),
+ Some(false) => tr("Pen button"),
+ Some(true) => tr("Pen second button"),
};
// the plugins' actions a button can run, of those on: after the app's own, by their labels
let plugin_actions = prefs.plugins.actions_in(procraft_core::PluginPlace::Pen);
@@ -1283,7 +1302,7 @@ impl Actions {
let top = body.top() + 12.0 + 44.0 + 8.0;
let Some(second) = self.pen_picking else {
let mut y = top;
- for (k, heading) in ["Pen button", "Pen second button"].into_iter().enumerate() {
+ for (k, heading) in [tr("Pen button"), tr("Pen second button")].into_iter().enumerate() {
y += 6.0;
text(
ui.painter(),
@@ -1352,21 +1371,21 @@ impl Actions {
/// Advanced cursor settings: when the brush cursor shows, and how it is drawn.
fn cursor_page(&mut self, ui: &mut Ui, look: &mut Look, body: Rect, prefs: &mut Prefs) -> Option {
- if self.page_header(ui, look, body, "Advanced cursor") {
+ if self.page_header(ui, look, body, tr("Advanced cursor")) {
return None;
}
let (left, right) = (body.left() + 12.0, body.right() - 12.0);
let mut y = body.top() + 12.0 + 44.0 + 8.0;
let mut changed = false;
- for (k, heading) in ["Brush cursor visibility", "Brush outline style"].into_iter().enumerate() {
+ for (k, heading) in [tr("Brush cursor visibility"), tr("Brush outline style")].into_iter().enumerate() {
y += if k == 0 { 6.0 } else { 28.0 };
let ink = argb(CURSOR_HEADING);
text(ui.painter(), pos2(left + 14.0, y), Align2::LEFT_TOP, heading, 17.0, Weight::Bold, ink);
y += 21.0 + 8.0;
let (labels, chosen) = if k == 0 {
- (["Show while hovering", "Show while painting", "Show both"], prefs.cursor_shows as usize)
+ ([tr("Show while hovering"), tr("Show while painting"), tr("Show both")], prefs.cursor_shows as usize)
} else {
- (["High contrast", "Active color", "Per brush"], prefs.cursor_style as usize)
+ ([tr("High contrast"), tr("Active color"), tr("Per brush")], prefs.cursor_style as usize)
};
let group = Rect::from_min_size(pos2(left, y), vec2(right - left, choices_height(3, chosen)));
if let Some(i) = choice_group(ui, group, &labels, chosen, k) {
@@ -1393,7 +1412,7 @@ impl Actions {
/// Pressure and Smoothing: the app's stabilization, motion filtering and its expression, Tip
/// Attachment, the pressure curve every stroke goes through, and Reset all.
fn pressure_page(&mut self, ui: &mut Ui, look: &mut Look, body: Rect, prefs: &mut Prefs) -> Option {
- if self.page_header(ui, look, body, "Pressure & Smoothing") {
+ if self.page_header(ui, look, body, tr("Pressure & Smoothing")) {
return None;
}
let list = Rect::from_min_max(
@@ -1413,7 +1432,7 @@ impl Actions {
ui.add_space(16.0);
// with no filtering it has nothing to do
let can = (prefs.motion_filtering > 0.0).then_some(Act::TipAttachment);
- let tip = [Row::Switch("Tip Attachment", prefs.tip_attached, can)];
+ let tip = [Row::Switch(tr("Tip Attachment"), prefs.tip_attached, can)];
tapped = tapped.or(group_view(ui, &tip, 1, &mut self.swipes).0);
ui.add_space(24.0);
let (label, _) = ui.allocate_exact_size(vec2(width, 19.0), Sense::hover());
@@ -1421,7 +1440,7 @@ impl Actions {
ui.painter(),
pos2(label.left() + 13.0, label.center().y),
Align2::LEFT_CENTER,
- "App Pressure Sensitivity",
+ tr("App Pressure Sensitivity"),
13.0,
Weight::SemiBold,
argb(SLIDE_LABEL),
@@ -1432,7 +1451,7 @@ impl Actions {
tapped = Some(Tapped::Act(Act::Prefs));
}
ui.add_space(27.0);
- let reset = [Row::Button("Reset all", None, Some(Act::ResetInput))];
+ let reset = [Row::Button(tr("Reset all"), None, Some(Act::ResetInput))];
let (t, _) = group_view(ui, &reset, 2, &mut self.swipes);
tapped = tapped.or(t);
ui.add_space(13.0);
@@ -1551,7 +1570,7 @@ fn plugin_card(
let inside = width - 2.0 * PLUGIN_INSET;
let said = wrapped(&painter, &plugin.description, 14.0, Weight::Regular, argb(ACTIONS_ROW), inside);
let said_height = said.size().y;
- painter.galley(pos2(left, area.top() + PLUGIN_HEAD), said, argb(ACTIONS_ROW));
+ crate::look::draw_layout(&painter, pos2(left, area.top() + PLUGIN_HEAD), said, argb(ACTIONS_ROW));
let mut y = area.top() + PLUGIN_HEAD + said_height;
if let Some(problem) = &plugin.problem {
let at = pos2(left, y + PLUGIN_PROBLEM / 2.0 + 2.0);
@@ -1588,7 +1607,12 @@ fn plugin_card(
argb(ACTIONS_ROW),
width - FEATURE_ROOM,
);
- painter.galley(pos2(cell.left() + 16.0, name_at.y + FEATURE_NAME + 4.0), said, argb(ACTIONS_ROW));
+ crate::look::draw_layout(
+ &painter,
+ pos2(cell.left() + 16.0, name_at.y + FEATURE_NAME + 4.0),
+ said,
+ argb(ACTIONS_ROW),
+ );
}
let switch_at = pos2(cell.right() - 8.0 - 63.0, cell.center().y - 14.0);
crate::transform::switch(ui, switch_at, switch.on, &switch.key);
@@ -1628,9 +1652,9 @@ fn plugin_card(
let cell = Rect::from_min_size(pos2(area.left(), y + 1.0), vec2(width, ROW_HEIGHT));
let (label, ink) = match row {
CardRow::Action(i) => (plugin.actions.get(i).map_or("", |a| a.label.as_str()), argb(pc::ACCENT)),
- CardRow::TurnOn => ("Turn on", argb(ACTIONS_ROW)),
- CardRow::TurnOff => ("Turn off", argb(ACTIONS_ROW)),
- CardRow::Remove => ("Remove", argb(ACTIONS_ROW)),
+ CardRow::TurnOn => (tr("Turn on"), argb(ACTIONS_ROW)),
+ CardRow::TurnOff => (tr("Turn off"), argb(ACTIONS_ROW)),
+ CardRow::Remove => (tr("Remove"), argb(ACTIONS_ROW)),
};
let at = pos2(cell.left() + 16.0, cell.center().y);
text(&painter, at, Align2::LEFT_CENTER, label, 17.0, Weight::Regular, ink);
@@ -1729,7 +1753,7 @@ fn card_control(
let right = pos2(cell.right() - 16.0, cell.center().y);
let clear = control.chosen.as_ref().map(|chosen| {
let clear =
- text(painter, right, Align2::RIGHT_CENTER, "Clear", 17.0, Weight::Regular, argb(pc::ACCENT));
+ text(painter, right, Align2::RIGHT_CENTER, tr("Clear"), 17.0, Weight::Regular, argb(pc::ACCENT));
let shown: String = if chosen.chars().count() > 28 {
chosen.chars().take(27).chain(['\u{2026}']).collect()
} else {
@@ -1740,7 +1764,7 @@ fn card_control(
clear
});
if clear.is_none() {
- text(painter, right, Align2::RIGHT_CENTER, "Choose", 17.0, Weight::Regular, argb(pc::ACCENT));
+ text(painter, right, Align2::RIGHT_CENTER, tr("Choose"), 17.0, Weight::Regular, argb(pc::ACCENT));
}
let response = ui.interact(cell, ui.scope_id().with(("plugin folder", g, i)), Sense::click());
if response.clicked() {
@@ -1752,7 +1776,7 @@ fn card_control(
if plugins.set_folder(control.key.clone(), location, name) {
changed = true;
} else {
- crate::files::say("This folder couldn't be used.");
+ crate::files::say(tr("This folder couldn't be used."));
}
}
}
@@ -1766,7 +1790,7 @@ fn card_control(
let right = pos2(cell.right() - 16.0, cell.center().y);
let clear = control.chosen.as_ref().map(|chosen| {
let clear =
- text(painter, right, Align2::RIGHT_CENTER, "Clear", 17.0, Weight::Regular, argb(pc::ACCENT));
+ text(painter, right, Align2::RIGHT_CENTER, tr("Clear"), 17.0, Weight::Regular, argb(pc::ACCENT));
let shown: String = if chosen.chars().count() > 28 {
chosen.chars().take(27).chain(['\u{2026}']).collect()
} else {
@@ -1777,7 +1801,7 @@ fn card_control(
clear
});
if clear.is_none() {
- text(painter, right, Align2::RIGHT_CENTER, "Import", 17.0, Weight::Regular, argb(pc::ACCENT));
+ text(painter, right, Align2::RIGHT_CENTER, tr("Import"), 17.0, Weight::Regular, argb(pc::ACCENT));
}
let response = ui.interact(cell, ui.scope_id().with(("plugin file", g, i)), Sense::click());
if response.clicked() {
@@ -1790,14 +1814,14 @@ fn card_control(
if plugins.set_picture_file(control.key.clone(), name, bytes) {
changed = true;
} else {
- crate::files::say("This picture couldn't be used. Pick a PNG or a JPEG.");
+ crate::files::say(tr("This picture couldn't be used. Pick a PNG or a JPEG."));
}
}
} else if let Some((bytes, name)) = crate::files::pick_sound(&control.label) {
if plugins.set_sound_file(control.key.clone(), name, bytes) {
changed = true;
} else {
- crate::files::say("This sound couldn't be used. On the computer, pick a WAV file.");
+ crate::files::say(tr("This sound couldn't be used. On the computer, pick a WAV file."));
}
}
}
@@ -1993,7 +2017,7 @@ pub fn plugin_panel(
let title_at = pos2(rect.left() + 24.0, rect.top() + 22.5);
text(&painter, title_at, Align2::LEFT_TOP, &panel.title, 22.0, Weight::Bold, argb(crate::panel::PANEL_TITLE));
let done_at = pos2(rect.right() - 24.0, rect.top() + 33.0);
- let done = text(&painter, done_at, Align2::RIGHT_CENTER, "Done", 17.0, Weight::Regular, argb(pc::ACCENT));
+ let done = text(&painter, done_at, Align2::RIGHT_CENTER, tr("Done"), 17.0, Weight::Regular, argb(pc::ACCENT));
if ui.interact(done.expand(8.0), ui.scope_id().with("plugin panel done"), Sense::click()).clicked() {
asked = Some(PanelTouch::Close);
}
@@ -2032,7 +2056,12 @@ pub fn plugin_panel(
argb(ACTIONS_ROW),
cell.width() - 32.0,
);
- painter.galley(pos2(cell.left() + 16.0, cell.top() + 11.0), said, argb(ACTIONS_ROW));
+ crate::look::draw_layout(
+ &painter,
+ pos2(cell.left() + 16.0, cell.top() + 11.0),
+ said,
+ argb(ACTIONS_ROW),
+ );
}
PanelRow::Slider { label, least, most, step, value, unit } => {
let shown = held.filter(|(at, _)| *at == i).map_or(*value, |(_, v)| v);
diff --git a/desktop/src/adjust_panels.rs b/desktop/src/adjust_panels.rs
index 07e5de3c6..af83f36c5 100644
--- a/desktop/src/adjust_panels.rs
+++ b/desktop/src/adjust_panels.rs
@@ -3,6 +3,8 @@
//! side by side where the window is wide, stacked where it is narrow. Their kinds switch along the
//! top; their sliders change the adjustment at once (adjusting.rs).
+use procraft_core::tr;
+
use egui::{Align2, Color32, Id, Order, Pos2, Rect, Sense, Stroke, Ui, pos2, vec2};
use procraft_core::{AdjustShown, CanvasSession, ChromaticKind, GlitchKind, HalftoneKind, NoiseKind, PerspectiveKind};
@@ -35,43 +37,44 @@ const CURVE_NODE: u32 = 0xFF0171EA;
/// The Delete pill over a tapped curve point.
const CURVE_MENU_FILL: Themed = Themed(0xFF262626, 0xFFF0F0F0);
const BALANCE_PAIRS: [(&str, &str, [u32; 3]); 3] = [
- ("Cyan", "Red", [0xFF00FFFF, 0xFF808080, 0xFFFF0000]),
- ("Magenta", "Green", [0xFFFF00FF, 0xFF808080, 0xFF00FF00]),
- ("Yellow", "Blue", [0xFFFFFF00, 0xFF808080, 0xFF0000FF]),
+ (procraft_core::message!("Cyan"), procraft_core::message!("Red"), [0xFF00FFFF, 0xFF808080, 0xFFFF0000]),
+ (procraft_core::message!("Magenta"), procraft_core::message!("Green"), [0xFFFF00FF, 0xFF808080, 0xFF00FF00]),
+ (procraft_core::message!("Yellow"), procraft_core::message!("Blue"), [0xFFFFFF00, 0xFF808080, 0xFF0000FF]),
];
-const BALANCE_TONES: [&str; 3] = ["Shadows", "Midtones", "Highlights"];
+const BALANCE_TONES: [&str; 3] =
+ [procraft_core::message!("Shadows"), procraft_core::message!("Midtones"), procraft_core::message!("Highlights")];
const GLITCH_KINDS: [(GlitchKind, &str, f32, &Icon); 4] = [
- (GlitchKind::Artifact, "Artifact", 111.0, &icons::GLITCH_ARTIFACT),
- (GlitchKind::Wave, "Wave", 99.0, &icons::GLITCH_WAVE),
- (GlitchKind::Signal, "Signal", 104.0, &icons::GLITCH_SIGNAL),
- (GlitchKind::Diverge, "Diverge", 113.0, &icons::GLITCH_DIVERGE),
+ (GlitchKind::Artifact, procraft_core::message!("Artifact"), 111.0, &icons::GLITCH_ARTIFACT),
+ (GlitchKind::Wave, procraft_core::message!("Wave"), 99.0, &icons::GLITCH_WAVE),
+ (GlitchKind::Signal, procraft_core::message!("Signal"), 104.0, &icons::GLITCH_SIGNAL),
+ (GlitchKind::Diverge, procraft_core::message!("Diverge"), 113.0, &icons::GLITCH_DIVERGE),
];
const NOISE_KINDS: [(NoiseKind, &str, f32, &Icon); 3] = [
- (NoiseKind::Clouds, "Clouds", 149.0, &icons::NOISE_CLOUDS),
- (NoiseKind::Billows, "Billows", 149.0, &icons::NOISE_BILLOWS),
- (NoiseKind::Ridges, "Ridges", 148.0, &icons::NOISE_RIDGES),
+ (NoiseKind::Clouds, procraft_core::message!("Clouds"), 149.0, &icons::NOISE_CLOUDS),
+ (NoiseKind::Billows, procraft_core::message!("Billows"), 149.0, &icons::NOISE_BILLOWS),
+ (NoiseKind::Ridges, procraft_core::message!("Ridges"), 148.0, &icons::NOISE_RIDGES),
];
const HALFTONE_KINDS: [(HalftoneKind, &str, f32, &Icon); 3] = [
- (HalftoneKind::FullColor, "Full Color", 140.0, &icons::HALFTONE_FULL),
- (HalftoneKind::ScreenPrint, "Screen Print", 157.0, &icons::HALFTONE_SCREEN),
- (HalftoneKind::Newspaper, "Newspaper", 151.0, &icons::HALFTONE_NEWS),
+ (HalftoneKind::FullColor, procraft_core::message!("Full Color"), 140.0, &icons::HALFTONE_FULL),
+ (HalftoneKind::ScreenPrint, procraft_core::message!("Screen Print"), 157.0, &icons::HALFTONE_SCREEN),
+ (HalftoneKind::Newspaper, procraft_core::message!("Newspaper"), 151.0, &icons::HALFTONE_NEWS),
];
const CHROMA_KINDS: [(ChromaticKind, &str, f32, &Icon); 2] = [
- (ChromaticKind::Perspective, "Perspective", 204.0, &icons::CHROMA_PERSPECTIVE),
- (ChromaticKind::Displace, "Displace", 204.0, &icons::CHROMA_DISPLACE),
+ (ChromaticKind::Perspective, procraft_core::message!("Perspective"), 204.0, &icons::CHROMA_PERSPECTIVE),
+ (ChromaticKind::Displace, procraft_core::message!("Displace"), 204.0, &icons::CHROMA_DISPLACE),
];
const PERSPECTIVE_KINDS: [(PerspectiveKind, &str, f32, &Icon); 2] = [
- (PerspectiveKind::Positional, "Positional", 205.0, &icons::PERSPECTIVE_POSITIONAL),
- (PerspectiveKind::Directional, "Directional", 211.5, &icons::PERSPECTIVE_DIRECTIONAL),
+ (PerspectiveKind::Positional, procraft_core::message!("Positional"), 205.0, &icons::PERSPECTIVE_POSITIONAL),
+ (PerspectiveKind::Directional, procraft_core::message!("Directional"), 211.5, &icons::PERSPECTIVE_DIRECTIONAL),
];
/// A slider's value as shown: None at nothing, Max at all (`max`), else a percentage.
pub(crate) fn shown(v: f32, max: bool) -> String {
if v <= 0.0 {
- "None".into()
+ tr("None").into()
} else if max && v >= 1.0 {
- "Max".into()
+ tr("Max").into()
} else {
format!("{}%", (v * 100.0).round() as i32)
}
@@ -120,7 +123,7 @@ pub(crate) fn kinds_switch(
ui.painter().rect_filled(cell, 15, argb(pc::ACCENT));
}
let ink = if on { Color32::WHITE } else { argb(MODES_TEXT) };
- let words = ui.painter().layout_no_wrap(label.into(), Weight::Regular.font(14.0), ink).size().x;
+ let words = crate::look::layout_no_wrap(ui.painter(), label.into(), Weight::Regular.font(14.0), ink).size().x;
let left = cell.center().x - (30.0 + 2.0 + words) / 2.0;
look.icon(ui, glyph, pos2(left + 15.0, cell.center().y), 30.0, ink);
text(ui.painter(), pos2(left + 32.0, cell.center().y), Align2::LEFT_CENTER, label, 14.0, Weight::Regular, ink);
@@ -201,7 +204,7 @@ pub(crate) fn recolor_toolbar(ctx: &egui::Context, threshold: f32) -> Option = NOISE_KINDS.iter().map(|k| (k.1, k.2, k.3)).collect();
+ let kinds: Vec<(&str, f32, &Icon)> = NOISE_KINDS.iter().map(|k| (tr(k.1), k.2, k.3)).collect();
let chosen = NOISE_KINDS.iter().position(|k| k.0 == shown.noise_kind).unwrap_or(0);
let top = rect.top() + if wide { 8.0 } else { 10.0 };
if let Some(i) = kinds_switch(ui, look, pos2(rect.center().x, top), 472.0, &kinds, chosen) {
session.adjustment_noise_kind(NOISE_KINDS.get(i).map_or(NoiseKind::Clouds, |k| k.0));
}
- let names = ["Scale", "Octaves", "Turbulence"];
+ let names = [tr("Scale"), tr("Octaves"), tr("Turbulence")];
for (i, name) in names.iter().enumerate() {
let v = shown.noise.get(i).copied().unwrap_or(0.0);
let at = if wide {
@@ -304,7 +307,7 @@ impl Toolbars {
// single or multi, and additive, under the sliders
let row =
Rect::from_min_size(pos2(rect.center().x - 246.0, rect.bottom() - 10.0 - 40.0), vec2(492.0, 40.0));
- for (k, (multi, label)) in [(false, "Single"), (true, "Multi")].into_iter().enumerate() {
+ for (k, (multi, label)) in [(false, tr("Single")), (true, tr("Multi"))].into_iter().enumerate() {
let b = Rect::from_min_size(pos2(row.left() + k as f32 * 167.0, row.top()), vec2(160.0, 40.0));
let on = shown.noise_multi == multi;
ui.painter().rect_filled(b, 20, if on { argb(pc::ACCENT) } else { argb(NOISE_BUTTON) });
@@ -316,7 +319,15 @@ impl Toolbars {
}
let switch_at = pos2(row.right() - 63.0, row.center().y - 14.0);
let words = pos2((row.left() + 334.0 + switch_at.x) / 2.0, row.center().y);
- text(ui.painter(), words, Align2::CENTER_CENTER, "Additive", 16.0, Weight::Regular, argb(MODES_TEXT));
+ text(
+ ui.painter(),
+ words,
+ Align2::CENTER_CENTER,
+ tr("Additive"),
+ 16.0,
+ Weight::Regular,
+ argb(MODES_TEXT),
+ );
switch(ui, switch_at, shown.noise_added, "additive");
let hit = Rect::from_min_size(switch_at, vec2(63.0, 28.0));
if ui.interact(hit, ui.scope_id().with("additive"), Sense::click()).clicked() {
@@ -355,7 +366,7 @@ impl Toolbars {
let top = rect.top() + 16.0 + k as f32 * 63.0;
Rect::from_min_size(pos2(rect.left() + 26.0, top), vec2(rect.width() - 52.0, 55.0))
};
- if let Some(v) = balance_row(ui, row, left, right, v, colours) {
+ if let Some(v) = balance_row(ui, row, tr(left), tr(right), v, colours) {
session.adjustment_balance(k as u32, v);
}
}
@@ -375,7 +386,7 @@ impl Toolbars {
let chosen = tone == i;
ui.painter().rect_filled(b, 20, if chosen { argb(pc::ACCENT) } else { argb(PANEL_BUTTON) });
let ink = if chosen { Color32::WHITE } else { argb(PANEL_BUTTON_TEXT) };
- text(ui.painter(), b.center(), Align2::CENTER_CENTER, name, 15.0, Weight::Regular, ink);
+ text(ui.painter(), b.center(), Align2::CENTER_CENTER, tr(name), 15.0, Weight::Regular, ink);
if ui.interact(b, ui.scope_id().with(("tone", i)), Sense::click()).clicked() {
session.adjustment_balance_tone(i as u32);
}
@@ -383,8 +394,8 @@ impl Toolbars {
}
});
if let (true, Some(button)) = (self.more_open, more) {
- options_menu(ctx, &mut self.more_open, button, "Color Balance", 3.0 * 41.0 - 1.0, |ui, inner| {
- if let Some(i) = options_choices(ui, look, inner, 40.0, &BALANCE_TONES, tone) {
+ options_menu(ctx, &mut self.more_open, button, tr("Color Balance"), 3.0 * 41.0 - 1.0, |ui, inner| {
+ if let Some(i) = options_choices(ui, look, inner, 40.0, &BALANCE_TONES.map(tr), tone) {
session.adjustment_balance_tone(i as u32);
}
});
@@ -480,7 +491,7 @@ impl Toolbars {
}
// the channels (a filter layer's curves have alpha too)
let column = Rect::from_min_max(pos2(inner.right() - 111.0, inner.top()), inner.max);
- let names = ["Gamma", "Red", "Green", "Blue", "Alpha"];
+ let names = [tr("Gamma"), tr("Red"), tr("Green"), tr("Blue"), tr("Alpha")];
let count = (shown.curve_channels as usize).clamp(1, names.len());
let h = (column.height() - (count as f32 - 1.0)) / count as f32;
for (i, name) in names.iter().take(count).enumerate() {
@@ -505,7 +516,7 @@ impl Toolbars {
ui.painter(),
pill.center(),
Align2::CENTER_CENTER,
- "Delete",
+ tr("Delete"),
17.0,
Weight::Regular,
Color32::WHITE,
@@ -529,7 +540,7 @@ impl Toolbars {
button: Rect,
) {
let height = 44.0 + 12.0 + 89.0;
- options_menu(ctx, &mut self.more_open, button, "Channel", height, |ui, inner| {
+ options_menu(ctx, &mut self.more_open, button, tr("Channel"), height, |ui, inner| {
let ink = argb(MENU_TEXT);
let additive = Rect::from_min_size(inner.min, vec2(inner.width(), 44.0));
ui.painter().rect_filled(additive, 16, argb(OPTIONS_GROUP_FILL));
@@ -537,7 +548,7 @@ impl Toolbars {
ui.painter(),
pos2(additive.left() + 12.0, additive.center().y),
Align2::LEFT_CENTER,
- "Additive",
+ tr("Additive"),
15.0,
Weight::Regular,
ink,
@@ -549,7 +560,7 @@ impl Toolbars {
}
let group = Rect::from_min_size(pos2(inner.left(), additive.bottom() + 12.0), vec2(inner.width(), 89.0));
let chosen = usize::from(shown.noise_multi);
- if let Some(k) = options_choices(ui, look, group, 44.0, &["Single", "Multi"], chosen) {
+ if let Some(k) = options_choices(ui, look, group, 44.0, &[tr("Single"), tr("Multi")], chosen) {
session.adjustment_noise_ways(k == 1, shown.noise_added);
}
});
@@ -688,15 +699,15 @@ fn glitch(
) {
let rect = if wide { panel_rect(ctx, screen, 973.0, 120.0) } else { panel_rect(ctx, screen, 640.0, 167.0) };
panel(ctx, "glitch toolbar", rect, |ui| {
- let kinds: Vec<(&str, f32, &Icon)> = GLITCH_KINDS.iter().map(|k| (k.1, k.2, k.3)).collect();
+ let kinds: Vec<(&str, f32, &Icon)> = GLITCH_KINDS.iter().map(|k| (tr(k.1), k.2, k.3)).collect();
let chosen = GLITCH_KINDS.iter().position(|k| k.0 == shown.glitch_kind).unwrap_or(0);
if let Some(i) = kinds_switch(ui, look, pos2(rect.center().x, rect.top() + 8.0), 466.0, &kinds, chosen) {
session.adjustment_glitch_kind(GLITCH_KINDS.get(i).map_or(GlitchKind::Artifact, |k| k.0));
}
let names: &[&str] = match shown.glitch_kind {
- GlitchKind::Artifact | GlitchKind::Signal => &["Amount", "Block Size", "Zoom"],
- GlitchKind::Wave => &["Amplitude", "Frequency", "Zoom"],
- GlitchKind::Diverge => &["Red shift", "Green shift", "Blue shift", "Zoom"],
+ GlitchKind::Artifact | GlitchKind::Signal => &[tr("Amount"), tr("Block Size"), tr("Zoom")],
+ GlitchKind::Wave => &[tr("Amplitude"), tr("Frequency"), tr("Zoom")],
+ GlitchKind::Diverge => &[tr("Red shift"), tr("Green shift"), tr("Blue shift"), tr("Zoom")],
};
let top = rect.top() + 8.0 + 34.0 + 12.0;
for (k, name) in names.iter().enumerate() {
@@ -723,7 +734,7 @@ fn glitch(
fn bloom(ctx: &egui::Context, session: &CanvasSession, shown: &AdjustShown, screen: Rect, wide: bool) {
let rect = if wide { panel_rect(ctx, screen, 1013.0, 95.0) } else { panel_rect(ctx, screen, 532.0, 220.0) };
panel(ctx, "bloom toolbar", rect, |ui| {
- for (i, name) in ["Transition", "Size", "Burn"].iter().enumerate() {
+ for (i, name) in [tr("Transition"), tr("Size"), tr("Burn")].iter().enumerate() {
let v = shown.bloom.get(i).copied().unwrap_or(0.0);
let (at, w) = if wide {
// side by side, 301 wide and 39 apart
@@ -784,7 +795,7 @@ fn plugin_filter(ctx: &egui::Context, session: &CanvasSession, shown: &AdjustSho
fn halftone(ctx: &egui::Context, look: &mut Look, session: &CanvasSession, shown: &AdjustShown, screen: Rect) {
let rect = panel_rect(ctx, screen, 507.0, 66.0);
panel(ctx, "halftone toolbar", rect, |ui| {
- let kinds: Vec<(&str, f32, &Icon)> = HALFTONE_KINDS.iter().map(|k| (k.1, k.2, k.3)).collect();
+ let kinds: Vec<(&str, f32, &Icon)> = HALFTONE_KINDS.iter().map(|k| (tr(k.1), k.2, k.3)).collect();
let chosen = HALFTONE_KINDS.iter().position(|k| k.0 == shown.halftone_kind).unwrap_or(0);
if let Some(i) = kinds_switch(ui, look, pos2(rect.center().x, rect.top() + 16.0), 475.0, &kinds, chosen) {
session.adjustment_halftone_kind(HALFTONE_KINDS.get(i).map_or(HalftoneKind::FullColor, |k| k.0));
@@ -796,15 +807,15 @@ fn halftone(ctx: &egui::Context, look: &mut Look, session: &CanvasSession, shown
fn chromatic(ctx: &egui::Context, look: &mut Look, session: &CanvasSession, shown: &AdjustShown, screen: Rect) {
let rect = panel_rect(ctx, screen, 668.0, 120.0);
panel(ctx, "chromatic toolbar", rect, |ui| {
- let kinds: Vec<(&str, f32, &Icon)> = CHROMA_KINDS.iter().map(|k| (k.1, k.2, k.3)).collect();
+ let kinds: Vec<(&str, f32, &Icon)> = CHROMA_KINDS.iter().map(|k| (tr(k.1), k.2, k.3)).collect();
let chosen = CHROMA_KINDS.iter().position(|k| k.0 == shown.chroma_kind).unwrap_or(0);
if let Some(i) = kinds_switch(ui, look, pos2(rect.center().x, rect.top() + 8.0), 428.0, &kinds, chosen) {
session.adjustment_chroma_kind(CHROMA_KINDS.get(i).map_or(ChromaticKind::Perspective, |k| k.0));
}
let names = if shown.chroma_kind == ChromaticKind::Perspective {
- ["Transition", "Fall off"]
+ [tr("Transition"), tr("Fall off")]
} else {
- ["Blur", "Transparency"]
+ [tr("Blur"), tr("Transparency")]
};
for (k, name) in names.iter().enumerate() {
let v = shown.chroma.get(k).copied().unwrap_or(0.0);
@@ -820,7 +831,7 @@ fn chromatic(ctx: &egui::Context, look: &mut Look, session: &CanvasSession, show
fn perspective(ctx: &egui::Context, look: &mut Look, session: &CanvasSession, shown: &AdjustShown, screen: Rect) {
let rect = panel_rect(ctx, screen, 492.0, 66.0);
panel(ctx, "perspective toolbar", rect, |ui| {
- let kinds: Vec<(&str, f32, &Icon)> = PERSPECTIVE_KINDS.iter().map(|k| (k.1, k.2, k.3)).collect();
+ let kinds: Vec<(&str, f32, &Icon)> = PERSPECTIVE_KINDS.iter().map(|k| (tr(k.1), k.2, k.3)).collect();
let chosen = PERSPECTIVE_KINDS.iter().position(|k| k.0 == shown.perspective_kind).unwrap_or(0);
if let Some(i) = kinds_switch(ui, look, pos2(rect.center().x, rect.top() + 16.0), 460.0, &kinds, chosen) {
session.adjustment_perspective_kind(PERSPECTIVE_KINDS.get(i).map_or(PerspectiveKind::Positional, |k| k.0));
diff --git a/desktop/src/adjustments.rs b/desktop/src/adjustments.rs
index 97f2746f8..0eb38eafe 100644
--- a/desktop/src/adjustments.rs
+++ b/desktop/src/adjustments.rs
@@ -4,6 +4,8 @@
//! adjustment's own panel rising from the foot of the window. What each does is the core's
//! (adjusting.rs); the touches swipe its amount.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use egui::{Align2, Color32, Id, LayerId, Order, Pos2, Rect, Sense, Stroke, Ui, UiBuilder, pos2, vec2};
use procraft_core::{
@@ -132,13 +134,21 @@ pub fn menu(
let back = menu_back(body);
look.icon(ui, &icons::CHEVRON_LEFT, back.center(), 22.0, argb(panel::PANEL_TITLE));
let at = pos2(back.right(), back.center().y);
- text(ui.painter(), at, Align2::LEFT_CENTER, "Plugins", 22.0, Weight::Bold, argb(panel::PANEL_TITLE));
+ text(ui.painter(), at, Align2::LEFT_CENTER, tr("Plugins"), 22.0, Weight::Bold, argb(panel::PANEL_TITLE));
if ui.interact(back, ui.scope_id().with("back"), Sense::click()).clicked() {
tapped = Some(MenuRow::Back);
}
} else {
let title = pos2(body.left() + 24.0, body.top() + 22.5);
- text(ui.painter(), title, Align2::LEFT_TOP, "Adjustments", 24.0, Weight::Bold, argb(panel::PANEL_TITLE));
+ text(
+ ui.painter(),
+ title,
+ Align2::LEFT_TOP,
+ tr("Adjustments"),
+ 24.0,
+ Weight::Bold,
+ argb(panel::PANEL_TITLE),
+ );
}
let list = Rect::from_min_max(pos2(body.left() + 10.0, body.top() + 52.0 + 8.0), body.max - vec2(10.0, 10.0));
ui.scope_builder(UiBuilder::new().max_rect(list), |ui| {
@@ -268,11 +278,11 @@ impl Adjustments {
egui::Area::new(Id::unique("adjustment pie")).fixed_pos(screen.min).order(Order::Foreground).show(ctx, |ui| {
close = ui.allocate_rect(screen, Sense::click()).clicked();
let items = [
- (&icons::APPLY, "Apply", (0.0, -1.0), Some(Asked::Apply)),
- (&icons::PIE_UNDO, "Undo", (-1.0, 0.0), Some(Asked::Undo)),
- (&icons::PREVIEW, "Preview", (0.0, 0.0), None),
- (&icons::CANCEL_ADJUST, "Cancel", (1.0, 0.0), Some(Asked::Cancel)),
- (&icons::PIE_RESET, "Reset", (0.0, 1.0), Some(Asked::Reset)),
+ (&icons::APPLY, tr("Apply"), (0.0, -1.0), Some(Asked::Apply)),
+ (&icons::PIE_UNDO, tr("Undo"), (-1.0, 0.0), Some(Asked::Undo)),
+ (&icons::PREVIEW, tr("Preview"), (0.0, 0.0), None),
+ (&icons::CANCEL_ADJUST, tr("Cancel"), (1.0, 0.0), Some(Asked::Cancel)),
+ (&icons::PIE_RESET, tr("Reset"), (0.0, 1.0), Some(Asked::Reset)),
];
for (glyph, label, (dx, dy), what) in items {
let centre = at + vec2(PIE_STEP * dx, PIE_STEP * dy);
@@ -414,7 +424,8 @@ fn bar_in(ui: &Ui, look: &mut Look, shown: &AdjustShown, a: Adjustment, band: Re
let swiped = procraft_core::adjustment_swiped(a);
let paintable = procraft_core::adjustment_paintable(a);
let amount = format!("{}%", (shown.amount * 100.0).round() as i32);
- let measure = |s: &str, size: f32, w: Weight| painter.layout_no_wrap(s.into(), w.font(size), ink).size().x;
+ let measure =
+ |s: &str, size: f32, w: Weight| crate::look::layout_no_wrap(painter, s.into(), w.font(size), ink).size().x;
let width = 33.0
+ measure(&label, 17.0, Weight::Bold)
+ if swiped { 3.0 + measure(&amount, 14.0, Weight::Regular) } else { 0.0 }
@@ -449,12 +460,21 @@ pub(crate) fn layer_opacity_bar(ctx: &egui::Context, opacity: f32, top: f32) {
painter.rect_filled(band, 0, argb(MODE_BAR));
let ink = argb(MODE_TEXT);
let amount = format!("{}%", (opacity * 100.0).round() as i32);
- let measure = |s: &str, size: f32, w: Weight| painter.layout_no_wrap(s.into(), w.font(size), ink).size().x;
+ let measure = |s: &str, size: f32, w: Weight| {
+ crate::look::layout_no_wrap(painter, s.into(), w.font(size), ink).size().x
+ };
let width = 33.0 + measure("Opacity", 17.0, Weight::Bold) + 3.0 + measure(&amount, 14.0, Weight::Regular);
let x = band.center().x - width / 2.0;
opacity_glyph(painter, pos2(x + 16.5, band.center().y), ink, argb(MODE_BAR));
- let x =
- text(painter, pos2(x + 33.0, band.center().y), Align2::LEFT_CENTER, "Opacity", 17.0, Weight::Bold, ink);
+ let x = text(
+ painter,
+ pos2(x + 33.0, band.center().y),
+ Align2::LEFT_CENTER,
+ tr("Opacity"),
+ 17.0,
+ Weight::Bold,
+ ink,
+ );
text(
painter,
pos2(x.right() + 3.0, band.center().y),
@@ -541,8 +561,11 @@ fn hsb_panel(ctx: &egui::Context, session: &CanvasSession, shown: &AdjustShown)
egui::Area::new(Id::unique("hsb panel")).fixed_pos(rect.min).order(Order::Foreground).show(ctx, |ui| {
ui.allocate_rect(rect, Sense::click());
ui.painter().rect_filled(rect, 33, argb(PANEL_FILL));
- let rows: [(&str, f32, Track); 3] =
- [("Hue", h, Track::Hue), ("Saturation", s, Track::Saturation), ("Brightness", b, Track::Brightness)];
+ let rows: [(&str, f32, Track); 3] = [
+ (tr("Hue"), h, Track::Hue),
+ (tr("Saturation"), s, Track::Saturation),
+ (tr("Brightness"), b, Track::Brightness),
+ ];
for (i, (label, value, track)) in rows.into_iter().enumerate() {
let row = if wide {
// side by side, 13 apart
diff --git a/desktop/src/alert.rs b/desktop/src/alert.rs
index 1702879a9..e026d4fee 100644
--- a/desktop/src/alert.rs
+++ b/desktop/src/alert.rs
@@ -3,6 +3,8 @@
//! Cancel beside the action, red when it destroys (an extra choice, blue, can sit between them,
//! the panel widening for it). A tap beside the panel cancels.
+use procraft_core::tr;
+
use std::time::Instant;
use egui::emath::TSTransform;
@@ -43,13 +45,13 @@ const PAGE: Icon = Icon {
/// 85 or exactly); a tap beside the panel makes none.
pub fn pdf_quality() -> Asking {
Asking {
- title: "PDF quality".into(),
+ title: tr("PDF quality").into(),
message: String::new(),
- action: "Best".into(),
+ action: tr("Best").into(),
icon: Some(&PAGE),
destructive: false,
- extra: Some("Better".into()),
- first: Some("Good".into()),
+ extra: Some(tr("Better").into()),
+ first: Some(tr("Good").into()),
alone: false,
}
}
@@ -119,7 +121,7 @@ impl Alert {
self.ask(Asking {
title: title.into(),
message: message.into(),
- action: "OK".into(),
+ action: tr("OK").into(),
icon,
destructive: false,
extra: None,
@@ -189,7 +191,7 @@ impl Alert {
let need = BUTTON_WIDTH * buttons + BUTTON_GAP * (buttons - 1.0) + SIDE * 2.0;
let widest = |s: &str, size: f32, weight: Weight| {
s.lines()
- .map(|l| measure.layout_no_wrap(l.to_owned(), weight.font(size), argb(INK)).size().x)
+ .map(|l| crate::look::layout_no_wrap(&measure, l.to_owned(), weight.font(size), argb(INK)).size().x)
.fold(0.0, f32::max)
};
let title = widest(&asking.title, 26.0, Weight::Bold) + if asking.icon.is_some() { 24.0 + 8.0 } else { 0.0 };
@@ -227,7 +229,8 @@ impl Alert {
let ink = argb(INK);
// the title, after its icon, centred
let title_y = panel.top() + 21.0 + 31.0 / 2.0;
- let words = painter.layout_no_wrap(asking.title.clone(), Weight::Bold.font(26.0), ink).size().x;
+ let words =
+ crate::look::layout_no_wrap(painter, asking.title.clone(), Weight::Bold.font(26.0), ink).size().x;
let icon_w = if asking.icon.is_some() { 24.0 + 8.0 } else { 0.0 };
let left = panel.center().x - (icon_w + words) / 2.0;
if let Some(icon) = asking.icon {
@@ -243,7 +246,12 @@ impl Alert {
ink,
);
if !asking.message.is_empty() {
- ui.painter().galley(pos2(panel.center().x, panel.top() + 21.0 + 31.0 + 13.0), wrapped.clone(), ink);
+ crate::look::draw_layout(
+ ui.painter(),
+ pos2(panel.center().x, panel.top() + 21.0 + 31.0 + 13.0),
+ wrapped.clone(),
+ ink,
+ );
}
let top = panel.bottom() - 16.0 - BUTTON_HEIGHT;
let action_fill = if asking.destructive { DESTROY_FILL } else { pc::ACCENT.into() };
diff --git a/desktop/src/animated_export.rs b/desktop/src/animated_export.rs
index 5fe7520fb..3f63dd837 100644
--- a/desktop/src/animated_export.rs
+++ b/desktop/src/animated_export.rs
@@ -6,6 +6,8 @@
//! ease, and the environment behind it; its file made once Done is pressed. While Done waits for
//! the file, the export card shows how far it has come.
+use procraft_core::tr;
+
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};
@@ -65,10 +67,10 @@ pub enum Animated {
impl Animated {
pub fn title(self) -> &'static str {
match self {
- Animated::Gif => "Animated GIF",
- Animated::Png => "Animated PNG",
- Animated::Mp4 => "Animated MP4",
- Animated::Hevc => "Animated HEVC",
+ Animated::Gif => tr("Animated GIF"),
+ Animated::Png => tr("Animated PNG"),
+ Animated::Mp4 => tr("Animated MP4"),
+ Animated::Hevc => tr("Animated HEVC"),
}
}
@@ -388,9 +390,9 @@ impl AnimatedExport {
argb(TITLE_INK),
);
let at = pos2(button.left() + 60.0, button.center().y - 14.5);
- text(ui.painter(), at, Align2::LEFT_CENTER, "Export", 24.0, Weight::Bold, argb(TITLE_INK));
+ text(ui.painter(), at, Align2::LEFT_CENTER, tr("Export"), 24.0, Weight::Bold, argb(TITLE_INK));
let at = pos2(button.left() + 60.0, button.center().y + 14.5);
- text(ui.painter(), at, Align2::LEFT_CENTER, "Settings", 24.0, Weight::Bold, argb(TITLE_INK));
+ text(ui.painter(), at, Align2::LEFT_CENTER, tr("Settings"), 24.0, Weight::Bold, argb(TITLE_INK));
if ui.interact(button, ui.scope_id().with("export settings"), Sense::click()).clicked() {
self.settings_open = !self.settings_open;
}
@@ -398,14 +400,19 @@ impl AnimatedExport {
// Cancel and Done at the top right
let done_rect =
Rect::from_min_size(pos2(screen.right() - 16.0 - 44.0, screen.top() + 16.0), vec2(44.0, 45.0));
- let galley = ui.painter().layout_no_wrap("Cancel".to_owned(), Weight::Regular.font(17.0), argb(CANCEL_INK));
+ let galley = crate::look::layout_no_wrap(
+ ui.painter(),
+ tr("Cancel").to_owned(),
+ Weight::Regular.font(17.0),
+ argb(CANCEL_INK),
+ );
let capsule = Rect::from_min_size(
pos2(done_rect.left() - 13.0 - galley.size().x - 26.0, done_rect.center().y - 21.5),
vec2(galley.size().x + 26.0, 43.0),
);
ui.painter().rect_filled(capsule, 21.5, argb(CAPSULE_FILL));
ui.painter().rect_stroke(capsule, 21.5, Stroke::new(1.0, argb(CAPSULE_EDGE)), egui::StrokeKind::Inside);
- ui.painter().galley(capsule.center() - galley.size() / 2.0, galley, argb(CANCEL_INK));
+ crate::look::draw_layout(ui.painter(), capsule.center() - galley.size() / 2.0, galley, argb(CANCEL_INK));
cancel = ui.interact(capsule, ui.scope_id().with("cancel"), Sense::click()).clicked();
ui.painter().circle_filled(done_rect.center(), 22.0, argb(DONE_BLUE));
// while it is made the export card over the screen shows how far it has come
@@ -436,7 +443,7 @@ impl AnimatedExport {
let track = Rect::from_min_size(pos2(panel.left() + 7.5, y), vec2(384.0, 34.0));
ui.painter().rect_filled(track, 17, argb(SEGMENT_TRACK));
let item = (track.width() - 4.0 - 12.0) / 2.0;
- for (i, label) in ["Max Resolution", "Web Ready"].into_iter().enumerate() {
+ for (i, label) in [tr("Max Resolution"), tr("Web Ready")].into_iter().enumerate() {
let cell =
Rect::from_min_size(track.min + vec2(2.0 + (item + 12.0) * i as f32, 2.0), vec2(item, 30.0));
let chosen = self.web_ready == (i == 1);
@@ -453,16 +460,16 @@ impl AnimatedExport {
y = track.bottom() + FPS_ROW_HEIGHT;
let mut rows = Vec::new();
if self.format == Animated::Gif {
- rows.push(("Dithering", self.dither));
- rows.push(("Per frame color palette", self.per_frame_palette));
+ rows.push((procraft_core::message!("Dithering"), self.dither));
+ rows.push((procraft_core::message!("Per frame color palette"), self.per_frame_palette));
}
if self.can_transparent() {
- rows.push(("Transparent background", self.transparent));
+ rows.push((procraft_core::message!("Transparent background"), self.transparent));
}
for (label, on) in rows {
let row = Rect::from_min_size(pos2(panel.left(), y), vec2(PANEL_WIDTH, 52.0));
let at = pos2(row.left() + 16.0, row.center().y);
- text(ui.painter(), at, Align2::LEFT_CENTER, label, 17.0, Weight::Regular, argb(ROW_INK));
+ text(ui.painter(), at, Align2::LEFT_CENTER, tr(label), 17.0, Weight::Regular, argb(ROW_INK));
crate::transform::switch(ui, pos2(row.left() + 16.0 + 307.0, row.center().y - 14.0), on, label);
if ui.interact(row, ui.scope_id().with(label), Sense::click()).clicked() {
match label {
@@ -527,7 +534,7 @@ impl AnimatedExport {
let fraction = self.fps_at.unwrap_or(0.0);
// the name's and the value's caps at y 132.5, the value's ink 24 in from the panel's right
let label_at = pos2(panel.left() + FPS_LABEL_X, top + FPS_LABEL_Y);
- text(ui.painter(), label_at, Align2::LEFT_TOP, "Frames per second", 17.0, Weight::Regular, argb(ROW_INK));
+ text(ui.painter(), label_at, Align2::LEFT_TOP, tr("Frames per second"), 17.0, Weight::Regular, argb(ROW_INK));
let value = procraft_core::export_fps_label(self.fps());
let value_at = pos2(panel.right() - FPS_VALUE_RIGHT, top + FPS_LABEL_Y);
text(ui.painter(), value_at, Align2::RIGHT_TOP, &value, 17.0, Weight::Regular, argb(ROW_INK));
@@ -578,7 +585,9 @@ impl AnimatedExport {
// rotate or swing, the chosen one blue with a tick
let group = Rect::from_min_size(pos2(panel.left() + 16.0, y), vec2(PANEL_WIDTH - 32.0, 80.0));
ui.painter().rect_filled(group, 14, argb(CHOICE_FILL));
- for (i, (label, swing)) in [("Animated rotate", false), ("Animated swing", true)].into_iter().enumerate() {
+ for (i, (label, swing)) in
+ [(tr("Animated rotate"), false), (tr("Animated swing"), true)].into_iter().enumerate()
+ {
let row = Rect::from_min_size(pos2(group.left(), group.top() + 40.0 * i as f32), vec2(group.width(), 40.0));
let chosen = t.swing == swing;
if chosen {
@@ -613,9 +622,9 @@ impl AnimatedExport {
y = group.bottom() + 26.0;
let seconds = if t.seconds < 1.0 { format!("{:.1}", t.seconds) } else { format!("{}", t.seconds.round()) };
let rows: [(&str, String, f32); 3] = [
- ("Animation duration", seconds, (t.seconds - 0.5) / 4.5),
- ("Zoom distance", format!("{}%", (t.zoom * 100.0).round()), t.zoom),
- ("Ease", format!("{}%", (t.ease * 100.0).round()), t.ease),
+ (tr("Animation duration"), seconds, (t.seconds - 0.5) / 4.5),
+ (tr("Zoom distance"), format!("{}%", (t.zoom * 100.0).round()), t.zoom),
+ (tr("Ease"), format!("{}%", (t.ease * 100.0).round()), t.ease),
];
for (k, (label, value, fraction)) in rows.into_iter().enumerate() {
let row = Rect::from_min_size(pos2(panel.left() + 8.0, y), vec2(PANEL_WIDTH - 16.0, 66.0));
@@ -663,7 +672,7 @@ impl AnimatedExport {
y += 10.0;
let row = Rect::from_min_size(pos2(panel.left(), y), vec2(PANEL_WIDTH, 52.0));
let at = pos2(row.left() + 16.0, row.center().y);
- text(ui.painter(), at, Align2::LEFT_CENTER, "Show environment", 17.0, Weight::Regular, argb(ROW_INK));
+ text(ui.painter(), at, Align2::LEFT_CENTER, tr("Show environment"), 17.0, Weight::Regular, argb(ROW_INK));
crate::transform::switch(
ui,
pos2(row.left() + 16.0 + 307.0, row.center().y - 14.0),
@@ -710,7 +719,7 @@ fn ui_escape(ctx: &egui::Context) -> bool {
/// The artwork's name, or "Untitled Artwork".
fn title_of(session: &CanvasSession) -> String {
let name = session.name();
- if name.trim().is_empty() { "Untitled Artwork".to_owned() } else { name.trim().to_owned() }
+ if name.trim().is_empty() { tr("Untitled Artwork").to_owned() } else { name.trim().to_owned() }
}
/// A file's size as the screen shows it: "1.3 MB", "850 KB".
@@ -726,7 +735,7 @@ fn file_size(bytes: u64) -> String {
fn save_as(made: &std::path::Path, format: Animated) -> bool {
let name = made.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
let Some(to) = crate::files::dialog()
- .set_title(format!("Share as {}", format.title()))
+ .set_title(procraft_core::trf("Share as {0}", &[("0", &format.title())]))
.set_file_name(name)
.add_filter(format.title(), &[format.extension()])
.save_file()
@@ -736,7 +745,7 @@ fn save_as(made: &std::path::Path, format: Animated) -> bool {
match crate::files::copy_whole(made, &to) {
Ok(()) => true,
Err(e) => {
- crate::files::tell("Can't export", &e.to_string());
+ crate::files::tell(tr("Can't export"), &e.to_string());
false
}
}
diff --git a/desktop/src/animation.rs b/desktop/src/animation.rs
index de6dacbee..906d55edc 100644
--- a/desktop/src/animation.rs
+++ b/desktop/src/animation.rs
@@ -3,6 +3,8 @@
//! second, onion skins, the onion skins' colours) or the current frame's options stand on it.
//! Page Assist shows the same bar with pages.
+use procraft_core::tr;
+
use std::collections::HashMap;
use std::time::{Duration, Instant};
@@ -176,11 +178,11 @@ impl AnimationBar {
let y = bar.top() + 8.0 + 15.0;
let ink = argb(BAR_INK);
let play = if pages {
- "Page Assist"
+ tr("Page Assist")
} else if self.playing.is_some() {
- "Pause"
+ tr("Pause")
} else {
- "Play"
+ tr("Play")
};
let shown =
text(ui.painter(), pos2(bar.left() + BAR_INSET, y), Align2::LEFT_CENTER, play, 17.0, Weight::Bold, ink);
@@ -199,7 +201,7 @@ impl AnimationBar {
ui.painter(),
pos2(bar.right() - BAR_INSET, y),
Align2::RIGHT_CENTER,
- if pages { "New Page" } else { "Add Frame" },
+ if pages { tr("New Page") } else { tr("Add Frame") },
17.0,
Weight::Regular,
ink,
@@ -213,7 +215,7 @@ impl AnimationBar {
}
if !pages {
let at = pos2(add.left() - 23.0, y);
- let s = text(ui.painter(), at, Align2::RIGHT_CENTER, "Settings", 17.0, Weight::Regular, ink);
+ let s = text(ui.painter(), at, Align2::RIGHT_CENTER, tr("Settings"), 17.0, Weight::Regular, ink);
settings_at = s.center().x - bar.left();
if tapped(ui, s, "settings") {
self.settings_open = !self.settings_open;
@@ -526,12 +528,12 @@ impl AnimationBar {
let back = Rect::from_min_size(pos2(rect.left(), y), vec2(44.0, 34.0));
look.icon(ui, &icons::CHEVRON_LEFT, back.center(), 34.0, argb(SLIDE_VALUE));
let title = pos2(back.right(), y + 17.0);
- text(ui.painter(), title, Align2::LEFT_CENTER, "Colors", 23.0, Weight::Bold, argb(PANEL_TITLE));
+ text(ui.painter(), title, Align2::LEFT_CENTER, tr("Colors"), 23.0, Weight::Bold, argb(PANEL_TITLE));
let reset = text(
ui.painter(),
pos2(right, y + 17.0),
Align2::RIGHT_CENTER,
- "Reset",
+ tr("Reset"),
17.0,
Weight::Regular,
argb(SLIDE_VALUE),
@@ -592,7 +594,7 @@ impl AnimationBar {
ui.painter(),
pos2(left + 14.0, y + 11.0),
Align2::LEFT_TOP,
- "Settings",
+ tr("Settings"),
23.0,
Weight::Bold,
argb(PANEL_TITLE),
@@ -600,9 +602,9 @@ impl AnimationBar {
y += 11.0 + TITLE_LINE + 21.0;
// the playback: Loop, Ping-Pong, One Shot, the chosen one blue
let modes = [
- (AnimationPlayback::Loop, "Loop"),
- (AnimationPlayback::PingPong, "Ping-Pong"),
- (AnimationPlayback::OneShot, "One Shot"),
+ (AnimationPlayback::Loop, tr("Loop")),
+ (AnimationPlayback::PingPong, tr("Ping-Pong")),
+ (AnimationPlayback::OneShot, tr("One Shot")),
];
let group = Rect::from_min_max(pos2(left, y), pos2(right, y + 3.0 * 40.0 + 4.0));
ui.painter().rect_filled(group, 18, argb(GROUP));
@@ -655,14 +657,14 @@ impl AnimationBar {
y += 8.0;
let onion = a.onion_frames;
let onion_shown = match onion {
- 0 => "None".to_owned(),
- MAX_ONION => "Max".to_owned(),
+ 0 => tr("None").to_owned(),
+ MAX_ONION => tr("Max").to_owned(),
n => n.to_string(),
};
let rows: [(&str, String, f32); 3] = [
- ("Frames Per Second", a.fps.to_string(), (a.fps as f32 - 1.0) / 59.0),
- ("Onion skin frames", onion_shown, onion as f32 / MAX_ONION as f32),
- ("Onion skin opacity", format!("{} %", (a.onion_opacity * 100.0).round()), a.onion_opacity),
+ (tr("Frames Per Second"), a.fps.to_string(), (a.fps as f32 - 1.0) / 59.0),
+ (tr("Onion skin frames"), onion_shown, onion as f32 / MAX_ONION as f32),
+ (tr("Onion skin opacity"), format!("{} %", (a.onion_opacity * 100.0).round()), a.onion_opacity),
];
for (i, (label, value, fraction)) in rows.into_iter().enumerate() {
let row = Rect::from_min_max(pos2(left, y), pos2(right, y + 55.0));
@@ -679,7 +681,7 @@ impl AnimationBar {
let group = Rect::from_min_max(pos2(left, y), pos2(right, y + 44.5 * 2.0 + 2.0));
ui.painter().rect_filled(group, 18, argb(GROUP));
let blend = Rect::from_min_max(pos2(left, y), pos2(right, y + 44.5));
- if toggle_row(ui, blend, "Blend primary frame", a.blend_primary) {
+ if toggle_row(ui, blend, tr("Blend primary frame"), a.blend_primary) {
changed.blend_primary = !a.blend_primary;
}
y += 44.5;
@@ -691,7 +693,7 @@ impl AnimationBar {
ui.painter(),
at,
Align2::LEFT_CENTER,
- "Onion skin colors",
+ tr("Onion skin colors"),
17.0,
Weight::Regular,
argb(PANEL_TITLE),
@@ -734,7 +736,11 @@ impl AnimationBar {
let hold_rows = if a.pages { 0.0 } else { 4.0 + 55.0 + 10.0 };
// a plugin's in-betweens: a frame drawn between this one and the next
let inbetween = self.tweens && !a.pages && place == 0 && index + 1 < frames.len();
- let own: &[&str] = if inbetween { &["Duplicate", "Delete", "In-between"] } else { &["Duplicate", "Delete"] };
+ let own: &[&str] = if inbetween {
+ &[tr("Duplicate"), tr("Delete"), tr("In-between")]
+ } else {
+ &[tr("Duplicate"), tr("Delete")]
+ };
// a plugin's actions for the frame, after the app's own
let mut actions: Vec<&str> = own.to_vec();
actions.extend(self.frame_actions.iter().map(|a| a.label.as_str()));
@@ -748,7 +754,7 @@ impl AnimationBar {
down_popover(ui, rect, 130.0);
let (left, right) = (rect.left() + 8.0, rect.right() - 8.0);
let mut y = rect.top() + 8.0;
- let title = if a.pages { "Page options" } else { "Frame options" };
+ let title = if a.pages { tr("Page options") } else { tr("Frame options") };
text(
ui.painter(),
pos2(left + 14.0, y + 11.0),
@@ -764,9 +770,9 @@ impl AnimationBar {
let group = Rect::from_min_max(pos2(left, y), pos2(right, y + 4.0 + 55.0));
ui.painter().rect_filled(group, 18, argb(GROUP));
let row = Rect::from_min_max(pos2(left, y + 4.0), pos2(right, y + 4.0 + 55.0));
- let shown = if hold == 0 { "None".to_owned() } else { hold.to_string() };
+ let shown = if hold == 0 { tr("None").to_owned() } else { hold.to_string() };
if let Some(v) =
- value_slider(ui, row, "Hold duration", &shown, hold as f32 / MAX_HOLD as f32, ("hold", 0))
+ value_slider(ui, row, tr("Hold duration"), &shown, hold as f32 / MAX_HOLD as f32, ("hold", 0))
{
self.holding = true;
session.change_frame_hold(id, ((v * MAX_HOLD as f32).round() as u32).min(MAX_HOLD), false);
@@ -795,9 +801,9 @@ impl AnimationBar {
}
(2, _) => {
if session.add_inbetween(id).is_none() {
- crate::files::say(
+ crate::files::say(tr(
"An in-between goes between two frames of one layer each, with something drawn.",
- );
+ ));
}
}
(0, 0) => _ = session.duplicate_layer(id),
@@ -822,7 +828,7 @@ impl AnimationBar {
ui.painter().rect_filled(group, 18, argb(GROUP));
if foreground {
let row = Rect::from_min_max(pos2(left, y), pos2(right, y + 44.0));
- if toggle_row(ui, row, "Foreground", a.foreground) {
+ if toggle_row(ui, row, tr("Foreground"), a.foreground) {
changed.foreground = !a.foreground;
}
y += 44.0;
@@ -837,7 +843,7 @@ impl AnimationBar {
}
if background {
let row = Rect::from_min_max(pos2(left, y), pos2(right, y + 44.0));
- if toggle_row(ui, row, "Background", a.background) {
+ if toggle_row(ui, row, tr("Background"), a.background) {
changed.background = !a.background;
}
}
diff --git a/desktop/src/canvas_info.rs b/desktop/src/canvas_info.rs
index 56f1dea35..7f7536fc6 100644
--- a/desktop/src/canvas_info.rs
+++ b/desktop/src/canvas_info.rs
@@ -3,6 +3,8 @@
//! card at the left (a rail of icons on an upright window), the artwork's name to edit as the
//! title, Cancel and Done. About keeps the author's photo and signature in the artwork's folder.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use std::path::Path;
@@ -38,12 +40,12 @@ const WIDE_START: f32 = 358.0;
const WIDE_END: f32 = 28.0;
const PAGES: [(&str, &Icon, f32); 6] = [
- ("About this artwork", &icons::INFO_ABOUT, 39.0),
- ("Dimensions", &icons::INFO_DIMENSIONS, 51.0),
- ("Layers", &icons::INFO_LAYERS, 35.0),
- ("Color profile", &icons::INFO_PROFILE, 33.0),
- ("Video settings", &icons::INFO_VIDEO, 55.0),
- ("Statistics", &icons::INFO_STATISTICS, 35.0),
+ (procraft_core::message!("About this artwork"), &icons::INFO_ABOUT, 39.0),
+ (procraft_core::message!("Dimensions"), &icons::INFO_DIMENSIONS, 51.0),
+ (procraft_core::message!("Layers"), &icons::INFO_LAYERS, 35.0),
+ (procraft_core::message!("Color profile"), &icons::INFO_PROFILE, 33.0),
+ (procraft_core::message!("Video settings"), &icons::INFO_VIDEO, 55.0),
+ (procraft_core::message!("Statistics"), &icons::INFO_STATISTICS, 35.0),
];
/// How Canvas information ended.
@@ -126,12 +128,12 @@ impl CanvasInfo {
.and_then(|()| write_photo(dir.clone(), jpeg).map_err(|e| e.to_string()));
if let Err(e) = written {
log::warn!("keeping the author's photo: {e}");
- self.failure = Some("The photo couldn't be kept.");
+ self.failure = Some(tr("The photo couldn't be kept."));
}
}
if let Err(e) = write_signature(dir.clone(), self.signature.clone()) {
log::warn!("keeping the signature: {e}");
- self.failure = self.failure.or(Some("The signature couldn't be kept."));
+ self.failure = self.failure.or(Some(tr("The signature couldn't be kept.")));
}
}
@@ -161,8 +163,9 @@ impl CanvasInfo {
);
painter.rect_filled(card, 20.0, argb(RAIL));
painter.rect_stroke(card, 20.0, Stroke::new(1.0, argb(CARD_EDGE)), egui::StrokeKind::Inside);
- text(&painter, card.min + vec2(24.0, 19.0), Align2::LEFT_TOP, "Canvas Info", 24.0, Weight::Bold, ink);
+ text(&painter, card.min + vec2(24.0, 19.0), Align2::LEFT_TOP, tr("Canvas Info"), 24.0, Weight::Bold, ink);
for (i, (label, icon, size)) in PAGES.into_iter().enumerate() {
+ let label = tr(label);
let row = Rect::from_min_size(
pos2(card.left() + 8.0, card.top() + 65.0 + 56.0 * i as f32),
vec2(304.0, 53.0),
@@ -226,7 +229,11 @@ impl CanvasInfo {
.show(&mut ui.new_child(UiBuilder::new().max_rect(field)));
// Cancel, Import before it on the colour profile page, and Done
let done = Rect::from_min_size(pos2(screen.right() - 20.0 - 44.0, screen.top() + 20.0), vec2(44.0, 45.0));
- let words: &[&str] = if self.page == 3 { &["Import", "Cancel"] } else { &["Cancel"] };
+ let words: &[&str] = if self.page == 3 {
+ &[procraft_core::message!("Import"), procraft_core::message!("Cancel")]
+ } else {
+ &[procraft_core::message!("Cancel")]
+ };
match crate::custom_canvas::capsule_words(ui, done.left() - 13.0, screen.top() + 21.0, words, CAPSULE_INK) {
Some("Cancel") => ended = Some(Ended::Cancel),
// a profile of the canvas's kind is picked to change to
@@ -247,13 +254,13 @@ impl CanvasInfo {
// another profile is asked about first, as measured (a time-lapse recorded or not)
if changed.is_some() {
self.asking.ask(crate::alert::Asking {
- title: "Change color profile?".into(),
- message: "Its colours keep their values and look as the new profile shows them, in the time-lapse recording too.".into(),
- action: "Change".into(),
+ title: tr("Change color profile?").into(),
+ message: tr("Its colours keep their values and look as the new profile shows them, in the time-lapse recording too.").into(),
+ action: tr("Change").into(),
icon: None,
destructive: false,
extra: None,
- first: Some("Don't change".into()),
+ first: Some(tr("Don't change").into()),
alone: false,
});
} else {
@@ -297,7 +304,7 @@ impl CanvasInfo {
let created = Some(self.info.created_ms as i64).filter(|&ms| ms > 0).or(changed_ms);
let modified = changed_ms.or(created);
let shown = |ms: Option| ms.map_or_else(|| "\u{2014}".to_owned(), date_text);
- rows(ui, width, &[("Date created", shown(created)), ("Date modified", shown(modified))], 50.0);
+ rows(ui, width, &[(tr("Date created"), shown(created)), (tr("Date modified"), shown(modified))], 50.0);
}
1 => {
let c = session.info();
@@ -306,18 +313,18 @@ impl CanvasInfo {
rows(
ui,
width,
- &[("Pixel width", format!("{}px", c.width)), ("Pixel height", format!("{}px", c.height))],
+ &[(tr("Pixel width"), format!("{}px", c.width)), (tr("Pixel height"), format!("{}px", c.height))],
50.0,
);
ui.add_space(21.0);
- rows(ui, width, &[("Physical width", mm(c.width)), ("Physical height", mm(c.height))], 50.0);
+ rows(ui, width, &[(tr("Physical width"), mm(c.width)), (tr("Physical height"), mm(c.height))], 50.0);
ui.add_space(21.0);
let shown = if dpi.fract() == 0.0 { format!("{}", dpi as i64) } else { format!("{dpi:.1}") };
rows(ui, width, &[("DPI", shown)], 50.0);
}
2 => {
let l = session.layer_stats();
- rows(ui, width, &[("Maximum layers", l.maximum.to_string())], 50.0);
+ rows(ui, width, &[(tr("Maximum layers"), l.maximum.to_string())], 50.0);
ui.add_space(21.0);
let available = l.maximum.saturating_sub(l.used);
let sets = session.texture_set_stats();
@@ -325,7 +332,7 @@ impl CanvasInfo {
rows(
ui,
width,
- &[("Layers used", l.used.to_string()), ("Layers available", available.to_string())],
+ &[(tr("Layers used"), l.used.to_string()), (tr("Layers available"), available.to_string())],
50.0,
);
} else {
@@ -336,10 +343,10 @@ impl CanvasInfo {
}
ui.add_space(21.0);
let kinds = [
- ("Assisted layers", l.assisted.to_string()),
- ("Clipping layers", l.clipping.to_string()),
- ("Layer masks", l.masks.to_string()),
- ("Layer groups", l.groups.to_string()),
+ (tr("Assisted layers"), l.assisted.to_string()),
+ (tr("Clipping layers"), l.clipping.to_string()),
+ (tr("Layer masks"), l.masks.to_string()),
+ (tr("Layer groups"), l.groups.to_string()),
];
// a model has no drawing guide to assist with
let shown = usize::from(session.model_info().is_some());
@@ -347,14 +354,14 @@ impl CanvasInfo {
}
3 => {
let current = session.profile();
- rows(ui, width, &[("Current color profile", current.clone())], 44.0);
+ rows(ui, width, &[(tr("Current color profile"), current.clone())], 44.0);
ui.add_space(32.0);
let (heading, _) = ui.allocate_exact_size(vec2(width, 22.0), Sense::hover());
text(
ui.painter(),
heading.left_center() + vec2(16.0, 0.0),
Align2::LEFT_CENTER,
- "Available color profiles",
+ tr("Available color profiles"),
17.0,
Weight::Regular,
argb(INK),
@@ -404,11 +411,11 @@ impl CanvasInfo {
let (frames, bytes) = self.lapse;
let seconds = frames / procraft_core::TIME_LAPSE_FPS;
let video = [
- ("Video length", format!("{:02}:{:02}:{:02}", seconds / 3600, seconds / 60 % 60, seconds % 60)),
- ("Video quality", self.video.first().cloned().unwrap_or_default()),
- ("Video resolution", self.video.get(1).cloned().unwrap_or_default()),
- ("Video file size", megabytes(bytes)),
- ("Video codec", self.video.get(2).cloned().unwrap_or_default()),
+ (tr("Video length"), format!("{:02}:{:02}:{:02}", seconds / 3600, seconds / 60 % 60, seconds % 60)),
+ (tr("Video quality"), self.video.first().cloned().unwrap_or_default()),
+ (tr("Video resolution"), self.video.get(1).cloned().unwrap_or_default()),
+ (tr("Video file size"), megabytes(bytes)),
+ (tr("Video codec"), self.video.get(2).cloned().unwrap_or_default()),
];
rows(ui, width, &video, 50.0);
}
@@ -416,9 +423,9 @@ impl CanvasInfo {
let minutes = self.info.tracked_ms / 60_000;
let size = self.dir.as_ref().map_or(0, |d| folder_size(Path::new(d)));
let stats = [
- ("Total strokes made", self.info.strokes.to_string()),
- ("Tracked time", format!("{}h {}m", minutes / 60, minutes % 60)),
- ("Total file size", megabytes(size)),
+ (tr("Total strokes made"), self.info.strokes.to_string()),
+ (tr("Tracked time"), format!("{}h {}m", minutes / 60, minutes % 60)),
+ (tr("Total file size"), megabytes(size)),
];
rows(ui, width, &stats, 50.0);
}
@@ -444,8 +451,8 @@ impl CanvasInfo {
}
if ui.interact(photo, ui.scope_id().with("photo"), Sense::click()).clicked()
&& let Some(path) = crate::files::dialog()
- .set_title("Photo")
- .add_filter("Pictures", &["png", "jpg", "jpeg", "webp", "gif", "bmp"])
+ .set_title(tr("Photo"))
+ .add_filter(tr("Pictures"), &["png", "jpg", "jpeg", "webp", "gif", "bmp"])
.pick_file()
&& let Ok(picture) = image::open(path)
{
@@ -456,13 +463,14 @@ impl CanvasInfo {
// "Made by" and the name, centred together
let field_width =
if self.author.is_empty() { 60.0 } else { (self.author.chars().count() as f32 * 12.0 + 16.0).min(260.0) };
- let made_by = ui.painter().layout_no_wrap("Made by ".into(), Weight::Regular.font(21.0), argb(INK));
+ let made_by =
+ crate::look::layout_no_wrap(ui.painter(), tr("Made by ").into(), Weight::Regular.font(21.0), argb(INK));
let left = card.center().x - (made_by.size().x + field_width) / 2.0;
let line_top = card.top() + 146.0;
- painter.galley(pos2(left, line_top), made_by.clone(), argb(INK));
+ crate::look::draw_layout(&painter, pos2(left, line_top), made_by.clone(), argb(INK));
let field = Rect::from_min_size(pos2(left + made_by.size().x, line_top), vec2(field_width, made_by.size().y));
if self.author.is_empty() {
- text(&painter, field.left_top(), Align2::LEFT_TOP, "Name", 21.0, Weight::Regular, argb(PLACEHOLDER));
+ text(&painter, field.left_top(), Align2::LEFT_TOP, tr("Name"), 21.0, Weight::Regular, argb(PLACEHOLDER));
}
egui::TextEdit::singleline(&mut self.author)
.font(Weight::Regular.font(21.0))
@@ -516,7 +524,7 @@ impl CanvasInfo {
&painter,
sign.min + vec2(50.0, 90.0),
Align2::LEFT_TOP,
- "Sign here",
+ tr("Sign here"),
11.0,
Weight::Regular,
argb(SIGN_INK),
@@ -582,11 +590,29 @@ fn crop_uv([w, h]: [usize; 2]) -> Rect {
/// A moment as the page shows it: "October 30, 2026 at 3:15 PM", in local time.
fn date_text(ms: i64) -> String {
- use chrono::TimeZone;
- chrono::Local
- .timestamp_millis_opt(ms)
- .single()
- .map_or_else(String::new, |t| t.format("%B %-d, %Y at %-I:%M %p").to_string())
+ use chrono::{Datelike, TimeZone, Timelike};
+ use procraft_core::{message, trf};
+ const MONTHS: [&str; 12] = [
+ message!("January"),
+ message!("February"),
+ message!("March"),
+ message!("April"),
+ message!("May"),
+ message!("June"),
+ message!("July"),
+ message!("August"),
+ message!("September"),
+ message!("October"),
+ message!("November"),
+ message!("December"),
+ ];
+ let Some(time) = chrono::Local.timestamp_millis_opt(ms).single() else { return String::new() };
+ let month = MONTHS.get(time.month0() as usize).map_or("", |month| tr(month));
+ let period = if time.hour() < 12 { tr("AM") } else { tr("PM") };
+ trf(
+ "{0} {1}, {2} at {3} {4}",
+ &[("0", &month), ("1", &time.day()), ("2", &time.year()), ("3", &time.format("%-I:%M")), ("4", &period)],
+ )
}
fn megabytes(bytes: u64) -> String {
diff --git a/desktop/src/chrome.rs b/desktop/src/chrome.rs
index dc5d33e21..1e2d0004f 100644
--- a/desktop/src/chrome.rs
+++ b/desktop/src/chrome.rs
@@ -2,6 +2,8 @@
//! action buttons, the tools, Layers and the colour) and the side bar (brush size, the modify
//! button, opacity, undo and redo, and a slider's panel).
+use procraft_core::tr;
+
use std::sync::Arc;
use egui::emath::TSTransform;
@@ -63,6 +65,12 @@ impl Bar {
/// The colour button's brightness under which it is ringed on the dark bar.
const DARK_RING_BELOW: f32 = 0.35;
+fn gallery_text_size(painter: &egui::Painter, label: &str) -> f32 {
+ let size = 18.0;
+ let width = crate::look::text_width(painter, label, size, Weight::Medium);
+ size * pc::GALLERY_WIDTH / width.max(pc::GALLERY_WIDTH)
+}
+
/// Adds `rect` (points, its corners `corner`) to `glass`: frost, or a window (window pixels: left,
/// top, right, bottom, corner, how much shows).
pub fn frost(glass: &mut Vec, rect: Rect, corner: f32, ppp: f32) {
@@ -109,12 +117,13 @@ pub fn top_bar(ui: &mut Ui, look: &mut Look, tool: ToolKind, colour: Color32, br
let mut x = r.left() + pc::BAR_MARGIN;
let gallery = button(x, pc::GALLERY_WIDTH);
tap(ui, BarButton::Gallery, gallery);
+ let label = tr("Gallery");
text(
ui.painter(),
pos2(gallery.left(), cy - 1.0),
Align2::LEFT_CENTER,
- "Gallery",
- 18.0,
+ label,
+ gallery_text_size(ui.painter(), label),
Weight::Medium,
argb(pc::BAR_TEXT),
);
@@ -309,22 +318,21 @@ pub fn top_bar_halves(
let gallery = next(pc::GALLERY_WIDTH);
tap(ui, BarButton::Gallery, gallery);
let ink = argb(pc::BAR_TEXT);
+ let label = tr("Gallery");
+ let size = gallery_text_size(ui.painter(), label);
if place.vertical {
// reading up the column
- let galley =
- crate::look::wrapped(ui.painter(), "Gallery", 18.0, Weight::Medium, ink, f32::INFINITY);
+ let galley = crate::look::wrapped(ui.painter(), label, size, Weight::Medium, ink, f32::INFINITY);
let size = galley.size();
let corner = pos2(gallery.center().x - size.y / 2.0, gallery.center().y + size.x / 2.0);
- let shape =
- egui::epaint::TextShape::new(corner, galley, ink).with_angle(-std::f32::consts::FRAC_PI_2);
- ui.painter().add(shape);
+ crate::look::draw_layout_rotated(ui.painter(), corner, galley, ink, -std::f32::consts::FRAC_PI_2);
} else {
text(
ui.painter(),
pos2(gallery.left(), gallery.center().y - 1.0),
Align2::LEFT_CENTER,
- "Gallery",
- 18.0,
+ label,
+ size,
Weight::Medium,
ink,
);
@@ -971,8 +979,8 @@ fn slider_panel(
// a hairline rim
painter.rect_stroke(rect, corner, Stroke::new(1.0, argb(pc::GLASS_MENU_EDGE)), egui::StrokeKind::Inside);
let (name, value) = match which {
- Slider::Size => ("Size", info.size),
- Slider::Opacity => ("Opacity", info.opacity),
+ Slider::Size => (tr("Size"), info.size),
+ Slider::Opacity => (tr("Opacity"), info.opacity),
};
let shown = format!(" {}%", side_slider_shown_percent(which == Slider::Size, value));
let line = pos2(rect.left() + 16.0, rect.top() + 6.0 + 16.0);
diff --git a/desktop/src/colour_drop.rs b/desktop/src/colour_drop.rs
index c66451b68..e29442aca 100644
--- a/desktop/src/colour_drop.rs
+++ b/desktop/src/colour_drop.rs
@@ -8,6 +8,8 @@
//! colour button that lets go and follows as a ball. Its fill spreads in (the core's
//! `pour_drop`).
+use procraft_core::tr;
+
use std::sync::Arc;
use std::time::{Duration, Instant};
@@ -371,10 +373,19 @@ impl ColourDrop {
let ink = argb(INK);
let blue = argb(pc::ACCENT);
// "ColorDrop", then the tick that ends filling or the offer to continue
- let name = painter.layout_no_wrap("ColorDrop".into(), Weight::Bold.font(16.5), ink).size().x;
+ let name =
+ crate::look::layout_no_wrap(painter, tr("ColorDrop").into(), Weight::Bold.font(16.5), ink).size().x;
let button = vec2(if what == Band::Filling { 20.0 } else { 101.0 }, 20.0);
let left = band.center().x - (name + 13.0 + button.x) / 2.0;
- text(painter, pos2(left, band.center().y), Align2::LEFT_CENTER, "ColorDrop", 16.5, Weight::Bold, ink);
+ text(
+ painter,
+ pos2(left, band.center().y),
+ Align2::LEFT_CENTER,
+ tr("ColorDrop"),
+ 16.5,
+ Weight::Bold,
+ ink,
+ );
let button = Rect::from_min_size(pos2(left + name + 13.0, band.center().y - button.y / 2.0), button);
if what == Band::Filling {
painter.circle_filled(button.center(), 10.0, blue);
@@ -391,7 +402,7 @@ impl ColourDrop {
painter,
button.center(),
Align2::CENTER_CENTER,
- "Continue filling",
+ tr("Continue filling"),
11.7,
Weight::Regular,
Color32::WHITE,
@@ -408,7 +419,8 @@ impl ColourDrop {
if self.sliding {
let row = Rect::from_min_size(pos2(window.left(), below), vec2(window.width(), ROW_HEIGHT));
ui.painter().rect_filled(row, 0, argb(ROW_FILL));
- let reading = format!("Threshold {}%", (self.threshold * 100.0).round() as i32);
+ let reading =
+ procraft_core::trf("Threshold {0}%", &[("0", &((self.threshold * 100.0).round() as i32))]);
text(ui.painter(), row.center(), Align2::CENTER_CENTER, &reading, 14.4, Weight::Regular, ink);
below = row.bottom();
}
diff --git a/desktop/src/colours.rs b/desktop/src/colours.rs
index b517d94d9..4da53ab88 100644
--- a/desktop/src/colours.rs
+++ b/desktop/src/colours.rs
@@ -4,6 +4,8 @@
//! colour's companions; Value: number sliders and the hex code), the history, the default
//! palette's swatches and the mode tabs.
+use procraft_core::tr;
+
use crate::scroll::{ScrollArea, ScrollOffset};
use egui::{Align2, Color32, Pos2, Rect, Sense, TextureHandle, TextureOptions, Ui, UiBuilder, pos2, vec2};
use std::sync::Arc;
@@ -221,11 +223,11 @@ impl HarmonyKind {
fn label(self) -> &'static str {
match self {
- HarmonyKind::Complementary => "Complementary",
- HarmonyKind::SplitComplementary => "Split Complementary",
- HarmonyKind::Analogous => "Analogous",
- HarmonyKind::Triadic => "Triadic",
- HarmonyKind::Tetradic => "Tetradic",
+ HarmonyKind::Complementary => tr("Complementary"),
+ HarmonyKind::SplitComplementary => tr("Split Complementary"),
+ HarmonyKind::Analogous => tr("Analogous"),
+ HarmonyKind::Triadic => tr("Triadic"),
+ HarmonyKind::Tetradic => tr("Tetradic"),
}
}
@@ -742,7 +744,7 @@ impl Colours {
self.background_done = true;
}
} else if self.mode == Mode::Palettes {
- panel::header(ui, look, body, "Palettes", 20.0, false, false);
+ panel::header(ui, look, body, tr("Palettes"), 20.0, false, false);
// the plus: a new palette, from a file or a picture, or the examples back
let plus = Rect::from_min_size(pos2(body.right() - 17.0 - 40.0, body.top() + 12.0), vec2(40.0, 41.0));
look.icon(ui, &icons::PLUS_MEDIUM, plus.center(), 41.0, argb(panel::PANEL_GLYPH));
@@ -751,7 +753,7 @@ impl Colours {
self.new_palette_menu.open();
}
} else {
- panel::header(ui, look, body, "Colors", 20.0, false, false);
+ panel::header(ui, look, body, tr("Colors"), 20.0, false, false);
}
// the current colour (edged) and the second, which swaps with it when tapped
let swatch = vec2(43.0, 25.0);
@@ -861,7 +863,7 @@ impl Colours {
let band = if history { 44.0 } else { 34.0 };
if history {
let at = pos2(body.left() + 21.0, y + 13.0);
- text(ui.painter(), at, Align2::LEFT_TOP, "History", 14.0, Weight::SemiBold, argb(PANEL_TITLE));
+ text(ui.painter(), at, Align2::LEFT_TOP, tr("History"), 14.0, Weight::SemiBold, argb(PANEL_TITLE));
self.history_strip(ui, session, body, y + band);
} else {
let at = pos2(body.left() + 21.0, y + 8.0);
@@ -887,7 +889,7 @@ impl Colours {
ui.painter(),
pos2(body.left() + 21.0, y + 13.0),
Align2::LEFT_TOP,
- "History",
+ tr("History"),
14.0,
Weight::SemiBold,
ink,
@@ -898,7 +900,7 @@ impl Colours {
ui.painter(),
clear.center(),
Align2::CENTER_CENTER,
- "Clear",
+ tr("Clear"),
13.0,
Weight::Regular,
argb(CLEAR_TEXT),
@@ -1038,7 +1040,8 @@ impl Colours {
};
let mut chosen = None;
self.short_menu.show(ctx, "short colour menu", rect, rect.right_top(), glass, backdrops, |ui| {
- for (i, (label, on)) in [("Color history", true), ("Active palette", false)].into_iter().enumerate() {
+ for (i, (label, on)) in [(tr("Color history"), true), (tr("Active palette"), false)].into_iter().enumerate()
+ {
let row = Rect::from_min_size(
pos2(rect.left(), rect.top() + 6.0 + 40.0 * i as f32),
vec2(rect.width(), 40.0),
@@ -1061,7 +1064,7 @@ impl Colours {
// a 41 frame centred 29.5 in
look.icon(ui, &icons::SWEEP, pos2(row.left() + 29.5, row.center().y), 41.0, danger);
let at = pos2(row.left() + 9.0 + 41.0 + 2.0, row.center().y);
- text(ui.painter(), at, Align2::LEFT_CENTER, "Clear history", 18.0, Weight::Regular, danger);
+ text(ui.painter(), at, Align2::LEFT_CENTER, tr("Clear history"), 18.0, Weight::Regular, danger);
if ui.interact(row, ui.scope_id().with("short clear"), Sense::click()).clicked() {
chosen = Some(None);
}
@@ -1629,7 +1632,7 @@ pub(crate) fn hex_row(
ui.painter(),
pos2(row.left() + 13.0, row.center().y),
Align2::LEFT_CENTER,
- "Hexadecimal",
+ tr("Hexadecimal"),
16.0,
Weight::Regular,
ink,
@@ -1762,7 +1765,7 @@ impl Colours {
}
let ink = if on { Color32::WHITE } else { argb(PANEL_TITLE) };
let weight = if on { Weight::SemiBold } else { Weight::Regular };
- let words = ui.painter().layout_no_wrap(label.into(), weight.font(15.0), ink).size().x;
+ let words = crate::look::layout_no_wrap(ui.painter(), label.into(), weight.font(15.0), ink).size().x;
let left = cell.center().x - (21.0 + 6.0 + words) / 2.0;
look.icon(ui, icon, pos2(left + 10.5, cell.center().y), 21.0, ink);
text(ui.painter(), pos2(left + 27.0, cell.center().y), Align2::LEFT_CENTER, label, 15.0, weight, ink);
@@ -1887,9 +1890,14 @@ impl Colours {
},
);
job.wrap.max_width = PALETTE_TILE - 16.0;
- let galley = painter.layout_job(job);
+ let galley = crate::look::layout_job(&painter, job);
// its baseline 11.5 above the bottom, as measured
- painter.galley(pos2(tile.left() + 8.0, tile.bottom() - 8.0 - galley.size().y), galley, lettering);
+ crate::look::draw_layout(
+ &painter,
+ pos2(tile.left() + 8.0, tile.bottom() - 8.0 - galley.size().y),
+ galley,
+ lettering,
+ );
self.swatch_touch(ui, session, tile, i, slot, Some(rgb));
}
} else {
@@ -1956,13 +1964,21 @@ impl Colours {
let ink = crate::menu::INK;
let mut entries = Vec::new();
if self.palettes.default_palette() != i {
- entries.push(crate::menu::Entry::Item(&icons::MENU_CHECK_CIRCLE, "Set as active", ink));
+ entries.push(crate::menu::Entry::Item(
+ &icons::MENU_CHECK_CIRCLE,
+ procraft_core::message!("Set as active"),
+ ink,
+ ));
}
- entries.push(crate::menu::Entry::Item(&icons::MENU_DUPLICATE, "Duplicate", ink));
- entries.push(crate::menu::Entry::Item(&icons::MENU_SHARE, "Share", ink));
+ entries.push(crate::menu::Entry::Item(&icons::MENU_DUPLICATE, procraft_core::message!("Duplicate"), ink));
+ entries.push(crate::menu::Entry::Item(&icons::MENU_SHARE, procraft_core::message!("Share"), ink));
if self.palettes.list().len() > 1 {
entries.push(crate::menu::DIVIDER);
- entries.push(crate::menu::Entry::Item(&icons::MENU_TRASH, "Delete", crate::menu::DANGER));
+ entries.push(crate::menu::Entry::Item(
+ &icons::MENU_TRASH,
+ procraft_core::message!("Delete"),
+ crate::menu::DANGER,
+ ));
}
let size = vec2(crate::menu::LIBRARY_WIDTH, crate::menu::entries_height(&entries));
let rect = Rect::from_min_size(pos2(button.left() - 5.0 - size.x, button.top() + 25.0), size);
@@ -1986,7 +2002,7 @@ impl Colours {
"Share" => {
let name = self.palettes.list().get(i as usize).map(|p| p.name.clone()).unwrap_or_default();
if let Some(bytes) = self.palettes.swatches_file(i) {
- crate::files::save_file(&bytes, &name, "swatches", "Palette");
+ crate::files::save_file(&bytes, &name, "swatches", tr("Palette"));
}
}
_ => self.palettes.delete(i),
@@ -1999,11 +2015,11 @@ impl Colours {
fn new_palette_menu(&mut self, ctx: &egui::Context, look: &mut Look, backdrops: &mut Vec) {
let ink = crate::menu::INK;
let entries = [
- crate::menu::Entry::Item(&MENU_GRID, "Create new palette", ink),
- crate::menu::Entry::Item(&icons::MENU_FOLDER, "New from file", ink),
- crate::menu::Entry::Item(&icons::MENU_PHOTO, "New from photos", ink),
+ crate::menu::Entry::Item(&MENU_GRID, procraft_core::message!("Create new palette"), ink),
+ crate::menu::Entry::Item(&icons::MENU_FOLDER, procraft_core::message!("New from file"), ink),
+ crate::menu::Entry::Item(&icons::MENU_PHOTO, procraft_core::message!("New from photos"), ink),
crate::menu::DIVIDER,
- crate::menu::Entry::Item(&icons::MENU_RESTORE, "Restore example palettes", ink),
+ crate::menu::Entry::Item(&icons::MENU_RESTORE, procraft_core::message!("Restore example palettes"), ink),
];
let plus = self.new_palette_button;
let size = vec2(crate::menu::LIBRARY_WIDTH, crate::menu::entries_height(&entries));
@@ -2025,13 +2041,13 @@ impl Colours {
match i {
0 => self.palettes.add(),
1 => {
- let Some((bytes, name)) = crate::files::pick_file("New palette from a file") else { return };
+ let Some((bytes, name)) = crate::files::pick_file(tr("New palette from a file")) else { return };
if !self.palettes.import_file(bytes.clone(), Some(name)) {
self.palette_from_picture(&bytes);
}
}
2 => {
- let Some((bytes, _)) = crate::files::pick_file("New palette from a picture") else { return };
+ let Some((bytes, _)) = crate::files::pick_file(tr("New palette from a picture")) else { return };
self.palette_from_picture(&bytes);
}
_ => self.palettes.restore_examples(),
@@ -2041,11 +2057,11 @@ impl Colours {
/// A palette of a picture's main colours (a PNG's), light to dark, added at the end.
fn palette_from_picture(&mut self, bytes: &[u8]) {
let Some(pixels) = crate::files::picture_pixels(bytes) else {
- crate::files::say("This picture can't be read.");
+ crate::files::say(tr("This picture can't be read."));
return;
};
if !self.palettes.add_from_pixels(pixels) {
- crate::files::say("This picture can't be read.");
+ crate::files::say(tr("This picture can't be read."));
}
}
}
diff --git a/desktop/src/colours/floating.rs b/desktop/src/colours/floating.rs
index c3833daf9..f95fc0999 100644
--- a/desktop/src/colours/floating.rs
+++ b/desktop/src/colours/floating.rs
@@ -448,8 +448,13 @@ fn floating_tiles(ui: &Ui, n: usize, filled: &[(usize, u32)], at: Rect) -> Optio
},
);
job.wrap.max_width = PALETTE_TILE - 16.0;
- let galley = ui.painter().layout_job(job);
- ui.painter().galley(pos2(tile.left() + 8.0, tile.bottom() - 10.0 - galley.size().y), galley, lettering);
+ let galley = crate::look::layout_job(ui.painter(), job);
+ crate::look::draw_layout(
+ ui.painter(),
+ pos2(tile.left() + 8.0, tile.bottom() - 10.0 - galley.size().y),
+ galley,
+ lettering,
+ );
if ui.interact(tile, ui.scope_id().with(("floating tile", n, slot)), Sense::click()).clicked() {
taken = Some(rgb);
}
diff --git a/desktop/src/compact_colours.rs b/desktop/src/compact_colours.rs
index 39faa02fe..a765e43fb 100644
--- a/desktop/src/compact_colours.rs
+++ b/desktop/src/compact_colours.rs
@@ -3,6 +3,8 @@
//! mode and the modes as icons, 260 wide; no swatches, history or palette. It edits a colour of its
//! own, which the screen that opened it takes as it changes.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use egui::{Align2, Color32, Rect, Sense, Ui, UiBuilder, Vec2, pos2, vec2};
use procraft_core::{HueControl, Palettes, SLIDER_HUES, hue_at, hue_position};
@@ -120,7 +122,7 @@ impl CompactColours {
ui.painter(),
pos2(body.left() + 18.0, body.top() + 9.0),
Align2::LEFT_TOP,
- "Colors",
+ tr("Colors"),
23.0,
Weight::Bold,
argb(PANEL_TITLE),
diff --git a/desktop/src/companion.rs b/desktop/src/companion.rs
index f275951f0..28886f06c 100644
--- a/desktop/src/companion.rs
+++ b/desktop/src/companion.rs
@@ -3,6 +3,8 @@
//! Undo, redo, Zoom and Move (while one is on, a press dragged on the canvas zooms it, up zooming
//! in about where it started, or moves it), and Fit Canvas. Dragged by its top edge.
+use procraft_core::tr;
+
use egui::{Align2, Color32, Id, Order, Pos2, Rect, Sense, pos2, vec2};
use crate::icons::{self, Icon};
@@ -72,11 +74,11 @@ impl Companion {
self.at = Some(keep(at + grab.drag_delta()));
}
let buttons: [(&Icon, &str, f32, Option); 5] = [
- (&icons::UNDO, "Undo", 30.0, None),
- (&icons::REDO, "Redo", 30.0, None),
- (&icons::ZOOM, "Zoom", 22.0, Some(Mode::Zoom)),
- (&icons::MOVE_CANVAS, "Move", 22.0, Some(Mode::Move)),
- (&icons::FIT_CANVAS, "Fit Canvas", 22.0, None),
+ (&icons::UNDO, tr("Undo"), 30.0, None),
+ (&icons::REDO, tr("Redo"), 30.0, None),
+ (&icons::ZOOM, tr("Zoom"), 22.0, Some(Mode::Zoom)),
+ (&icons::MOVE_CANVAS, tr("Move"), 22.0, Some(Mode::Move)),
+ (&icons::FIT_CANVAS, tr("Fit Canvas"), 22.0, None),
];
for (k, (icon, label, size, mode)) in buttons.into_iter().enumerate() {
let cell = Rect::from_min_size(
diff --git a/desktop/src/copy_paste.rs b/desktop/src/copy_paste.rs
index 6f4248258..7d0c6b2dd 100644
--- a/desktop/src/copy_paste.rs
+++ b/desktop/src/copy_paste.rs
@@ -2,6 +2,8 @@
//! down: Cut, Copy, Copy All, Duplicate, Cut & Paste and Paste, a little below the middle of the
//! window; a tap off it or its ✕ closes it.
+use procraft_core::tr;
+
use egui::{Align2, Id, Order, Rect, Sense, pos2, vec2};
use crate::icons::{self, Icon};
@@ -52,7 +54,7 @@ pub fn show(ctx: &egui::Context, look: &mut Look, can_paste: bool) -> Option Option {
session.crop_end(false);
ended = true;
@@ -143,7 +145,8 @@ impl Crop {
// each row's name from its left half, its value to the right; 8 either side of the
// middle
let field = rect.shrink2(vec2(10.0, 0.0));
- for (name, value, y) in [("Width", r.width, rect.top() + 11.0), ("Height", r.height, rect.top() + 43.0)]
+ for (name, value, y) in
+ [(tr("Width"), r.width, rect.top() + 11.0), (tr("Height"), r.height, rect.top() + 43.0)]
{
text(painter, pos2(field.left() + 4.0, y), Align2::LEFT_CENTER, name, 13.0, Weight::Bold, ink);
let at = pos2(field.right() - 4.0, y);
@@ -169,7 +172,7 @@ impl Crop {
ui.painter(),
pos2(inner.left() + 14.0, inner.top() + 20.0),
Align2::LEFT_CENTER,
- "Settings",
+ tr("Settings"),
22.0,
Weight::Bold,
ink,
@@ -211,7 +214,7 @@ impl Crop {
ui.painter(),
pos2(dpi_row.left() + 12.0, dpi_row.center().y),
Align2::LEFT_CENTER,
- "DPI",
+ tr("DPI"),
17.0,
Weight::Regular,
ink,
@@ -224,7 +227,7 @@ impl Crop {
session.crop_set_dpi(dpi);
}
for (k, (label, on)) in
- [("Resample canvas", shown.resample), ("Snapping", shown.snapping)].into_iter().enumerate()
+ [(tr("Resample canvas"), shown.resample), (tr("Snapping"), shown.snapping)].into_iter().enumerate()
{
let switch_row = row_at(1.0 + k as f32);
text(
@@ -255,7 +258,15 @@ impl Crop {
ui.painter().rect_filled(turn, 14.0, argb(GROUP));
let degrees = shown.angle.to_degrees();
let top = turn.top() + 8.0;
- text(ui.painter(), pos2(turn.left() + 10.0, top), Align2::LEFT_TOP, "Rotation", 17.0, Weight::Regular, ink);
+ text(
+ ui.painter(),
+ pos2(turn.left() + 10.0, top),
+ Align2::LEFT_TOP,
+ tr("Rotation"),
+ 17.0,
+ Weight::Regular,
+ ink,
+ );
text(
ui.painter(),
pos2(turn.right() - 10.0, top),
@@ -335,8 +346,10 @@ fn number_field(
ui.painter().rect_filled(rect, rect.height() / 2.0, argb(FIELD));
let mut value = typed.clone().unwrap_or_else(|| shown.to_owned());
let unit_text = unit.map(|u| format!(" {u}")).unwrap_or_default();
- let galley = ui.painter().layout_no_wrap(format!("{value}{unit_text}"), Weight::Regular.font(17.0), argb(INK));
- let unit_galley = ui.painter().layout_no_wrap(unit_text.clone(), Weight::Regular.font(17.0), argb(INK));
+ let galley =
+ crate::look::layout_no_wrap(ui.painter(), format!("{value}{unit_text}"), Weight::Regular.font(17.0), argb(INK));
+ let unit_galley =
+ crate::look::layout_no_wrap(ui.painter(), unit_text.clone(), Weight::Regular.font(17.0), argb(INK));
let value_width = galley.size().x - unit_galley.size().x + 2.0;
let left = rect.center().x - galley.size().x / 2.0;
let field = Rect::from_min_size(pos2(left, rect.center().y - 11.0), vec2(value_width.max(8.0), 22.0));
diff --git a/desktop/src/custom_canvas.rs b/desktop/src/custom_canvas.rs
index a6385e9c4..31aa3e7d9 100644
--- a/desktop/src/custom_canvas.rs
+++ b/desktop/src/custom_canvas.rs
@@ -4,6 +4,8 @@
//! its own (or the keyboard), in millimetres, centimetres, inches or pixels; the background's colour
//! is picked on the compact picker.
+use procraft_core::tr;
+
use egui::{Align2, Color32, Id, Order, Pos2, Rect, Sense, Stroke, UiBuilder, pos2, vec2};
use procraft_core::{
CanvasPreset, Palettes, SRGB, cmyk_profiles, color_profiles, is_cmyk_profile, layers_for, per_inch, preset_height,
@@ -41,14 +43,18 @@ const PAGE_TOP: f32 = 120.0;
const TYPED_BOTTOM: f32 = PAGE_TOP + ROW * 2.0 + 1.0 + 24.0 + ROW;
/// The units sizes are typed in: the key's name, the unit's (as presets keep it) and its mark.
-const UNITS: [(&str, &str, &str); 4] =
- [("Millimeters", "mm", "mm"), ("Centimeters", "cm", "cm"), ("Inches", "in", "\u{2033}"), ("Pixels", "px", "px")];
+const UNITS: [(&str, &str, &str); 4] = [
+ (procraft_core::message!("Millimeters"), "mm", "mm"),
+ (procraft_core::message!("Centimeters"), "cm", "cm"),
+ (procraft_core::message!("Inches"), "in", "\u{2033}"),
+ (procraft_core::message!("Pixels"), "px", "px"),
+];
const SECTIONS: [(&str, &Icon, f32); 4] = [
- ("Dimensions", &icons::INFO_DIMENSIONS, 50.0),
- ("Color profile", &icons::INFO_PROFILE, 35.0),
- ("Time-lapse settings", &icons::INFO_VIDEO, 60.0),
- ("Canvas properties", &icons::TAB_CANVAS, 40.0),
+ (procraft_core::message!("Dimensions"), &icons::INFO_DIMENSIONS, 50.0),
+ (procraft_core::message!("Color profile"), &icons::INFO_PROFILE, 35.0),
+ (procraft_core::message!("Time-lapse settings"), &icons::INFO_VIDEO, 60.0),
+ (procraft_core::message!("Canvas properties"), &icons::TAB_CANVAS, 40.0),
];
/// The fields the keypad types into.
@@ -99,7 +105,7 @@ impl CustomCanvas {
None => (
None,
CanvasPreset {
- name: "Untitled Canvas".into(),
+ name: tr("Untitled Canvas").into(),
unit: "px".into(),
size_width: 1080.0,
size_height: 1080.0,
@@ -135,7 +141,8 @@ impl CustomCanvas {
}
fn preset(&self) -> CanvasPreset {
- let name = if self.name.trim().is_empty() { "Untitled Canvas".to_owned() } else { self.name.trim().to_owned() };
+ let name =
+ if self.name.trim().is_empty() { tr("Untitled Canvas").to_owned() } else { self.name.trim().to_owned() };
CanvasPreset {
name,
unit: UNITS.get(self.unit).map_or("px", |u| u.1).to_owned(),
@@ -225,7 +232,7 @@ impl CustomCanvas {
let rail =
Rect::from_min_max(screen.min + vec2(10.0, 10.0), pos2(screen.left() + 329.0, screen.bottom() - 10.0));
painter.rect_filled(rail, 20.0, argb(PANEL));
- text(&painter, rail.min + vec2(24.0, 16.0), Align2::LEFT_TOP, "Custom Canvas", 22.0, Weight::Bold, ink);
+ text(&painter, rail.min + vec2(24.0, 16.0), Align2::LEFT_TOP, tr("Custom Canvas"), 22.0, Weight::Bold, ink);
for (i, (label, icon, size)) in SECTIONS.into_iter().enumerate() {
let row = Rect::from_min_size(
pos2(rail.left() + 8.0, rail.top() + 59.0 + 62.0 * i as f32),
@@ -242,7 +249,7 @@ impl CustomCanvas {
&painter,
pos2(rail.left() + 69.0, row.center().y),
Align2::LEFT_CENTER,
- label,
+ tr(label),
15.0,
Weight::Regular,
colour,
@@ -276,7 +283,11 @@ impl CustomCanvas {
name_focused = edit.response.has_focus();
// Cancel, and Import beside it on the colour profile page, then Done
let tick = Rect::from_min_size(pos2(screen.right() - 20.0 - 44.0, screen.top() + 20.0), vec2(44.0, 45.0));
- let words: &[&str] = if self.section == 1 { &["Cancel", "Import"] } else { &["Cancel"] };
+ let words: &[&str] = if self.section == 1 {
+ &[procraft_core::message!("Cancel"), procraft_core::message!("Import")]
+ } else {
+ &[procraft_core::message!("Cancel")]
+ };
match capsule_words(ui, tick.left() - 13.0, screen.top() + 21.0, words, CAPSULE_INK.into()) {
Some("Cancel") => done = Some(Done::Cancel),
Some(_) => {
@@ -354,15 +365,15 @@ impl CustomCanvas {
};
let first = group(ui, page.left_top(), page.width(), 2);
let rows = [
- ("Width", shown(self, Field::Width, preset_number(self.width)), mark, Some(Field::Width)),
- ("Height", shown(self, Field::Height, preset_number(self.height)), mark, Some(Field::Height)),
+ (tr("Width"), shown(self, Field::Width, preset_number(self.width)), mark, Some(Field::Width)),
+ (tr("Height"), shown(self, Field::Height, preset_number(self.height)), mark, Some(Field::Height)),
];
let second_top = first.bottom() + 24.0;
let p = self.preset();
let layers = layers_for(preset_width(p.clone()), preset_height(p)).to_string();
let more = [
("DPI", shown(self, Field::Dpi, format!("{}", self.dpi.round() as i64)), "", Some(Field::Dpi)),
- ("Maximum Layers", layers, "", None),
+ (tr("Maximum Layers"), layers, "", None),
];
group(ui, pos2(page.left(), second_top), page.width(), 2);
for (k, (label, value, unit, f)) in rows.into_iter().chain(more).enumerate() {
@@ -477,7 +488,7 @@ impl CustomCanvas {
}
}
let top = page.top() + (ROW + 1.0) * 3.0 - 1.0 + 24.0;
- let qualities = ["Low quality", "Good quality", "Studio quality", "Lossless"];
+ let qualities = [tr("Low quality"), tr("Good quality"), tr("Studio quality"), tr("Lossless")];
group(ui, pos2(page.left(), top), page.width(), 4);
for (i, label) in qualities.into_iter().enumerate() {
let row = Rect::from_min_size(pos2(page.left(), top + (ROW + 1.0) * i as f32), vec2(page.width(), ROW));
@@ -502,7 +513,7 @@ impl CustomCanvas {
ui.painter(),
pos2(row.left() + 16.0, row.center().y),
Align2::LEFT_CENTER,
- "Background color",
+ tr("Background color"),
15.0,
Weight::Regular,
ink,
@@ -519,7 +530,7 @@ impl CustomCanvas {
let top = row.bottom() + 24.0;
group(ui, pos2(page.left(), top), page.width(), 1);
let row = Rect::from_min_size(pos2(page.left(), top), vec2(page.width(), ROW));
- if switch_line(ui, row, "Background hidden", self.hidden, "hidden") {
+ if switch_line(ui, row, tr("Background hidden"), self.hidden, "hidden") {
self.hidden = !self.hidden;
}
}
@@ -551,7 +562,7 @@ impl CustomCanvas {
let rect = Rect::from_min_size(pos2(left, top + (h + down) * i as f32), vec2(w, h));
let chosen = i == self.unit;
let (fill, colour) = if chosen { (UNIT_CHOSEN, argb(UNIT_CHOSEN_INK)) } else { (KEY, ink) };
- if key(label, rect, fill, colour, 15.0, ("unit", i)) && !chosen {
+ if key(tr(label), rect, fill, colour, 15.0, ("unit", i)) && !chosen {
self.commit();
self.convert(i);
}
@@ -614,7 +625,7 @@ pub(crate) fn capsule_words<'a>(
) -> Option<&'a str> {
let galleys: Vec<_> = words
.iter()
- .map(|w| ui.painter().layout_no_wrap((*w).to_owned(), Weight::Regular.font(17.0), argb(ink)))
+ .map(|w| crate::look::layout_no_wrap(ui.painter(), tr(w).to_owned(), Weight::Regular.font(17.0), argb(ink)))
.collect();
let width: f32 = galleys.iter().map(|g| g.size().x + 26.0).sum();
let capsule = Rect::from_min_size(pos2(right - width, top), vec2(width, 43.0));
@@ -625,7 +636,7 @@ pub(crate) fn capsule_words<'a>(
for (word, galley) in words.iter().zip(galleys) {
let button = Rect::from_min_size(pos2(x, top), vec2(galley.size().x + 26.0, 43.0));
let at = button.center() - galley.size() / 2.0;
- ui.painter().galley(at, galley.clone(), argb(ink));
+ crate::look::draw_layout(ui.painter(), at, galley.clone(), argb(ink));
if ui.interact(button, ui.scope_id().with(("capsule", *word)), Sense::click()).clicked() {
tapped = Some(*word);
}
diff --git a/desktop/src/edit_layout.rs b/desktop/src/edit_layout.rs
index 7269fdd95..14b0d4885 100644
--- a/desktop/src/edit_layout.rs
+++ b/desktop/src/edit_layout.rs
@@ -4,6 +4,8 @@
//! it. Where each goes is the core's to work out ([`procraft_core::BarLayout`]); here the app tells
//! it where each bar always is, and draws the handles.
+use procraft_core::tr;
+
use std::sync::Arc;
use egui::{Align2, Pos2, Rect, Sense, pos2, vec2};
@@ -123,8 +125,8 @@ fn layouts_list(ctx: &egui::Context, named: &procraft_core::NamedLayouts, row: R
);
let delete = Rect::from_min_size(pos2(r.right() - 76.0, r.top()), vec2(70.0, 44.0));
let rename = delete.translate(vec2(-76.0, 0.0));
- text(ui.painter(), rename.center(), Align2::CENTER_CENTER, "Rename", 15.0, Weight::Regular, accent);
- text(ui.painter(), delete.center(), Align2::CENTER_CENTER, "Delete", 15.0, Weight::Regular, accent);
+ text(ui.painter(), rename.center(), Align2::CENTER_CENTER, tr("Rename"), 15.0, Weight::Regular, accent);
+ text(ui.painter(), delete.center(), Align2::CENTER_CENTER, tr("Delete"), 15.0, Weight::Regular, accent);
if ui.interact(delete, id.with(("delete", i)), Sense::click()).clicked() {
done = Some(Done::Delete(name.clone()));
} else if ui.interact(rename, id.with(("rename", i)), Sense::click()).clicked() {
@@ -149,7 +151,7 @@ fn layouts_list(ctx: &egui::Context, named: &procraft_core::NamedLayouts, row: R
);
ui.put(field, egui::TextEdit::singleline(&mut entry));
let save = Rect::from_min_max(pos2(field.right() + 8.0, last.top()), last.max);
- let word = if renaming.is_some() { "Rename" } else { "Save" };
+ let word = if renaming.is_some() { tr("Rename") } else { tr("Save") };
text_at(ui, save, word, accent);
if ui.interact(save, id.with("save"), Sense::click()).clicked() {
done = Some(match renaming.take() {
@@ -230,10 +232,12 @@ pub fn handles(
ctx,
|ui| {
// (and Collapse All, or Open All while any is collapsed, with Collapse to edge on)
- let mut labels = vec!["Layouts"];
- labels.extend(hidden.then_some("Show Hidden"));
- labels.extend(collapse.map(|any| if any { "Open All" } else { "Collapse All" }));
- labels.extend(["Reset", "Done"]);
+ use procraft_core::message;
+
+ let mut labels = vec![message!("Layouts")];
+ labels.extend(hidden.then_some(message!("Show Hidden")));
+ labels.extend(collapse.map(|any| if any { message!("Open All") } else { message!("Collapse All") }));
+ labels.extend([message!("Reset"), message!("Done")]);
let wide = |l: &str| matches!(l, "Show Hidden" | "Collapse All" | "Open All");
let widths: Vec = labels.iter().map(|l| if wide(l) { 130.0 } else { 90.0 }).collect();
let whole: f32 = widths.iter().sum();
@@ -245,7 +249,7 @@ pub fn handles(
for (label, width) in labels.into_iter().zip(widths) {
let cell = Rect::from_min_size(pos2(left, row.top()), vec2(width, 44.0));
left += width;
- text(ui.painter(), cell.center(), Align2::CENTER_CENTER, label, 17.0, Weight::Regular, ink);
+ text(ui.painter(), cell.center(), Align2::CENTER_CENTER, tr(label), 17.0, Weight::Regular, ink);
if ui.interact(cell, ui.scope_id().with(("edit layout", label)), Sense::click()).clicked() {
let list = egui::Id::unique("named layouts open");
if label == "Layouts" {
diff --git a/desktop/src/export_card.rs b/desktop/src/export_card.rs
index 7f9aa8ad7..6c61d8aa2 100644
--- a/desktop/src/export_card.rs
+++ b/desktop/src/export_card.rs
@@ -3,6 +3,8 @@
//! how far it has come, and Cancel; once made the pie is full and a check is drawn in it, then the
//! card goes. It comes and goes as an alert does, the window dimmed, nothing under it touched.
+use procraft_core::tr;
+
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
use std::time::{Duration, Instant};
@@ -190,7 +192,7 @@ impl ExportCard {
// the title after the share glyph (22 tall: 18.6 of its 50 frame), 13 between
let title_y = card.top() + 21.0 + 31.0 / 2.0;
let ink = argb(INK);
- let words = painter.layout_no_wrap(title.into(), Weight::Bold.font(26.0), ink).size().x;
+ let words = crate::look::layout_no_wrap(painter, title.into(), Weight::Bold.font(26.0), ink).size().x;
let left = card.center().x - (22.0 + 13.0 + words) / 2.0;
look.icon(ui, run.glyph, pos2(left + 11.0, title_y), 59.0, argb(pc::ACCENT));
text(ui.painter(), pos2(left + 35.0, title_y), Align2::LEFT_CENTER, title, 26.0, Weight::Bold, ink);
@@ -223,7 +225,7 @@ impl ExportCard {
ui.painter(),
button.center(),
Align2::CENTER_CENTER,
- "Cancel",
+ tr("Cancel"),
17.0,
Weight::Medium,
argb(CANCEL_INK),
@@ -248,7 +250,9 @@ impl ExportCard {
/// `line` as it fits in `width` at the card's line's size: whole, or with its middle left out.
fn fitted(painter: &egui::Painter, line: &str, width: f32) -> String {
- let wide = |s: &str| painter.layout_no_wrap(s.to_owned(), Weight::Regular.font(15.0), Color32::WHITE).size().x;
+ let wide = |s: &str| {
+ crate::look::layout_no_wrap(painter, s.to_owned(), Weight::Regular.font(15.0), Color32::WHITE).size().x
+ };
if wide(line) <= width {
return line.to_owned();
}
diff --git a/desktop/src/files.rs b/desktop/src/files.rs
index 5003bbdf4..5b95047f6 100644
--- a/desktop/src/files.rs
+++ b/desktop/src/files.rs
@@ -1,6 +1,8 @@
//! Artworks on disk: new, open (ProCraft packages, PSDs and PNGs), save as .procraft, export,
//! and asking before unsaved changes are lost.
+use procraft_core::tr;
+
use std::path::{Path, PathBuf};
use std::sync::Arc;
@@ -100,7 +102,7 @@ pub fn app_dir() -> PathBuf {
/// Shows a passing message with an OK button.
pub fn say(text: &str) {
- message().set_level(MessageLevel::Info).set_title("ProCraft").set_description(text).show();
+ message().set_level(MessageLevel::Info).set_title(tr("ProCraft")).set_description(text).show();
}
/// Whether the file at `path` holds brushes, by its name (a zip by what it holds): ours (a brush,
@@ -134,7 +136,7 @@ pub fn keep_pending_brushes(paths: &[PathBuf]) -> bool {
kept |= std::fs::copy(path, to).is_ok();
}
if kept {
- say("Brushes will be added to the library when a canvas opens.");
+ say(tr("Brushes will be added to the library when a canvas opens."));
}
kept
}
@@ -263,9 +265,9 @@ pub fn keep_brushes(session: &procraft_core::CanvasSession) {
FAILING.store(false, std::sync::atomic::Ordering::Relaxed);
} else if !FAILING.swap(true, std::sync::atomic::Ordering::Relaxed) {
tell_later(
- "Can't keep the brushes",
- "The brush library couldn't be kept. The disk may be full: brushes brought in or changed \
- since are lost when ProCraft closes, unless some room is made.",
+ tr("Can't keep the brushes"),
+ tr("The brush library couldn't be kept. The disk may be full: brushes brought in or changed \
+ since are lost when ProCraft closes, unless some room is made."),
);
}
}
@@ -284,7 +286,7 @@ pub fn save_file(bytes: &[u8], name: &str, extension: &str, kind: &str) {
let safe: String = name.chars().map(|c| if c.is_alphanumeric() || " _-".contains(c) { c } else { '_' }).collect();
let safe = if safe.trim().is_empty() { "Brush".to_owned() } else { safe };
let Some(path) = dialog()
- .set_title(format!("Share {kind}"))
+ .set_title(procraft_core::trf("Share {0}", &[("0", &kind)]))
.add_filter(kind, &[extension])
.set_file_name(format!("{safe}.{extension}"))
.save_file()
@@ -293,18 +295,18 @@ pub fn save_file(bytes: &[u8], name: &str, extension: &str, kind: &str) {
};
// a file there already is replaced only once this one is written whole
if let Err(e) = write_whole(&path, bytes) {
- tell("Can't share", &e.to_string());
+ tell(tr("Can't share"), &e.to_string());
}
}
/// A sound the user picks (titled `title`): a WAV file, read whole, with its name.
pub fn pick_sound(title: &str) -> Option<(Vec, String)> {
- let path = dialog().set_title(title).add_filter("Sounds", &["wav", "wave"]).pick_file()?;
+ let path = dialog().set_title(title).add_filter(tr("Sounds"), &["wav", "wave"]).pick_file()?;
let name = path.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
match std::fs::read(&path) {
Ok(bytes) => Some((bytes, name)),
Err(_) => {
- say("This file could not be read.");
+ say(tr("This file could not be read."));
None
}
}
@@ -321,12 +323,12 @@ pub fn pick_plugin_folder(title: &str) -> Option<(String, String)> {
/// A picture the user picks (titled `title`), a PNG or a JPEG, read whole, with its name.
pub fn pick_control_picture(title: &str) -> Option<(Vec, String)> {
- let path = dialog().set_title(title).add_filter("Pictures", &["png", "jpg", "jpeg"]).pick_file()?;
+ let path = dialog().set_title(title).add_filter(tr("Pictures"), &["png", "jpg", "jpeg"]).pick_file()?;
let name = path.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
match std::fs::read(&path) {
Ok(bytes) => Some((bytes, name)),
Err(_) => {
- say("This file could not be read.");
+ say(tr("This file could not be read."));
None
}
}
@@ -346,7 +348,7 @@ pub fn pick_file(title: &str) -> Option<(Vec, String)> {
match std::fs::read(&path) {
Ok(bytes) => Some((bytes, name)),
Err(_) => {
- say("This file could not be read.");
+ say(tr("This file could not be read."));
None
}
}
@@ -355,7 +357,7 @@ pub fn pick_file(title: &str) -> Option<(Vec, String)> {
/// Says the canvas holds no more layers, and how many it holds.
pub fn no_room(session: &CanvasSession) {
let most = session.layer_stats().maximum;
- tell("No room", &format!("This canvas holds at most {most} layers."));
+ tell(tr("No room"), &procraft_core::trf("This canvas holds at most {0} layers.", &[("0", &most)]));
}
/// Where the brush library, the brushes' choices and their sliders are kept.
@@ -472,10 +474,10 @@ pub fn keep_new_artwork(session: &Arc, dir: &str) -> Option Option {
- let path = dialog().set_title("Import").add_filter("Color profiles", &["icc", "icm"]).pick_file()?;
+ let path = dialog().set_title(tr("Import")).add_filter(tr("Color profiles"), &["icc", "icm"]).pick_file()?;
let name = std::fs::read(path).ok().and_then(procraft_core::import_profile);
if name.is_none() {
- tell("Can't import", "This file isn't a color profile.");
+ tell(tr("Can't import"), tr("This file isn't a color profile."));
}
name
}
@@ -489,15 +491,18 @@ pub fn is_plugin_file(path: &Path) -> bool {
/// A plugin file the user picks.
pub fn pick_plugin() -> Option {
- dialog().set_title("Import").add_filter("ProCraft plugins", &["procraft-plugin", "procraftplugin"]).pick_file()
+ dialog()
+ .set_title(tr("Import"))
+ .add_filter(tr("ProCraft plugins"), &["procraft-plugin", "procraftplugin"])
+ .pick_file()
}
/// A picture the user picks (PNG, JPEG, WebP, GIF, BMP or TIFF), to make a new artwork of
/// ([`picture_artwork`]).
pub fn pick_picture() -> Option {
dialog()
- .set_title("Photo")
- .add_filter("Pictures", &["png", "jpg", "jpeg", "webp", "gif", "bmp", "tif", "tiff"])
+ .set_title(tr("Photo"))
+ .add_filter(tr("Pictures"), &["png", "jpg", "jpeg", "webp", "gif", "bmp", "tif", "tiff"])
.pick_file()
}
@@ -566,7 +571,7 @@ pub fn pick_artwork_files(more: &[&str]) -> Option> {
"tiff",
];
let all: Vec<&str> = artworks.iter().chain(more).copied().collect();
- dialog().set_title("Import").add_filter("Artworks and models", &all).pick_files()
+ dialog().set_title(tr("Import")).add_filter(tr("Artworks and models"), &all).pick_files()
}
/// The artwork in the files `paths` (picked, or dropped on the gallery): a layered package, a
@@ -575,7 +580,10 @@ pub fn pick_artwork_files(more: &[&str]) -> Option> {
pub fn open_artwork_files(paths: Vec) -> Option<(Arc, Option)> {
// a model among them takes the rest as the files picked with it
if let Some(model) = paths.iter().find(|p| is_model_file(p)) {
- return open_model(model, &paths).map(|s| (s, None)).map_err(|e| tell_later("Can't open the model", &e)).ok();
+ return open_model(model, &paths)
+ .map(|s| (s, None))
+ .map_err(|e| tell_later(tr("Can't open the model"), &e))
+ .ok();
}
let path = paths.into_iter().next()?;
let name = path.file_stem().map(|s| s.to_string_lossy().into_owned()).unwrap_or_default();
@@ -583,7 +591,7 @@ pub fn open_artwork_files(paths: Vec) -> Option<(Arc, Op
// a model's artwork opens from where it is unpacked, and is kept as any new artwork is
if procraft_core::zip_file_kind(path.to_string_lossy().into_owned()) == procraft_core::ZipKind::ModelArtwork {
let opened = open_model_artwork(&path).map(|s| (s, None));
- return opened.map_err(|e| tell_later("Can't open the model", &e)).ok();
+ return opened.map_err(|e| tell_later(tr("Can't open the model"), &e)).ok();
}
let opened = match extension.as_str() {
"psd" | "psb" => open_psd(&path, &name),
@@ -600,7 +608,7 @@ pub fn open_artwork_files(paths: Vec) -> Option<(Arc, Op
};
// a package brings its time-lapse too
let package = matches!(extension.as_str(), "procraft" | "procreate").then_some(path);
- opened.map(|s| (s, package)).map_err(|e| tell_later("Can't open the file", &e)).ok()
+ opened.map(|s| (s, package)).map_err(|e| tell_later(tr("Can't open the file"), &e)).ok()
}
/// The model's artwork in file `path`, unpacked beside the other things opened from files.
@@ -609,7 +617,7 @@ fn open_model_artwork(path: &Path) -> Result, String> {
let _ = std::fs::remove_dir_all(&work);
let dir = work.to_string_lossy().into_owned();
if !procraft_core::unpack_model_artwork(path.to_string_lossy().into_owned(), dir.clone()) {
- return Err("This file can't be opened.".to_owned());
+ return Err(tr("This file can't be opened.").to_owned());
}
let opened = CanvasSession::open(dir).map_err(|e| e.to_string());
// its layers' files read before their folder goes (they are read as the canvas is made)
@@ -627,11 +635,11 @@ fn open_pdf(path: &Path, name: &str) -> Result, String> {
let (pages, artwork) = (work.join("pages"), work.join("artwork"));
let _ = std::fs::remove_dir_all(&work);
std::fs::create_dir_all(&pages).map_err(|e| e.to_string())?;
- let unreadable = || "This PDF can't be opened.".to_owned();
+ let unreadable = || tr("This PDF can't be opened.").to_owned();
let opened = crate::pdf::draw_pages(path, &pages)
.map_err(|e| {
log::error!("drawing a PDF's pages: {e}");
- if e.to_string() == crate::pdf::NO_POPPLER { crate::pdf::NO_POPPLER.to_owned() } else { unreadable() }
+ if e.to_string() == crate::pdf::NO_POPPLER { tr(crate::pdf::NO_POPPLER).to_owned() } else { unreadable() }
})
.and_then(|(count, w, h)| {
let dir = artwork.to_string_lossy().into_owned();
@@ -648,9 +656,10 @@ fn open_pdf(path: &Path, name: &str) -> Result, String> {
// its layers' files read before their folder goes
s.hold_opened_files();
}),
- PagesOutcome::TooManyPages { most } => {
- Err(format!("This PDF has more pages than a canvas its size can hold as layers ({most})."))
- }
+ PagesOutcome::TooManyPages { most } => Err(procraft_core::trf(
+ "This PDF has more pages than a canvas its size can hold as layers ({0}).",
+ &[("0", &most)],
+ )),
PagesOutcome::Unreadable => Err(unreadable()),
}
});
@@ -670,7 +679,7 @@ fn open_model(path: &Path, picked: &[PathBuf]) -> Result, Str
.filter_map(|p| std::fs::read(p).ok().map(|bytes| ModelFile { name: file_name(p), bytes }))
.collect();
let name = path.file_stem().map(|s| s.to_string_lossy().into_owned()).filter(|n| !n.trim().is_empty());
- let name = name.unwrap_or_else(|| "Untitled Artwork".to_owned());
+ let name = name.unwrap_or_else(|| tr("Untitled Artwork").to_owned());
let session = CanvasSession::open_model(bytes, file_name(path), files, name, 0).map_err(|e| e.to_string())?;
session.load_model_textures();
Ok(session)
@@ -688,12 +697,14 @@ fn open_psd(path: &Path, name: &str) -> Result, String> {
s.hold_opened_files();
})
}
- PsdOutcome::TooManyLayers { most } => Err(format!("It has more layers than a canvas its size holds ({most}).")),
- PsdOutcome::TooLarge => Err("Its canvas is larger than this computer can hold.".into()),
+ PsdOutcome::TooManyLayers { most } => {
+ Err(procraft_core::trf("It has more layers than a canvas its size holds ({0}).", &[("0", &most)]))
+ }
+ PsdOutcome::TooLarge => Err(tr("Its canvas is larger than this computer can hold.").into()),
PsdOutcome::Unsupported => {
- Err("This kind of PSD isn't read (bitmap, indexed, Lab or 32 bits a channel).".into())
+ Err(tr("This kind of PSD isn't read (bitmap, indexed, Lab or 32 bits a channel).").into())
}
- PsdOutcome::Unreadable => Err("It isn't a PSD, or it's damaged.".into()),
+ PsdOutcome::Unreadable => Err(tr("It isn't a PSD, or it's damaged.").into()),
};
// the opened artwork holds its layers' files by now
let _ = std::fs::remove_dir_all(&dir);
@@ -745,7 +756,7 @@ pub fn read_png(path: &Path) -> Result {
pub fn about() {
message()
.set_level(MessageLevel::Info)
- .set_title("ProCraft")
+ .set_title(tr("ProCraft"))
.set_description(format!("Version {}", env!("PROCRAFT_VERSION")))
.show();
}
@@ -758,8 +769,8 @@ pub fn save(session: &Arc, ui: &mut Interface, ask: bool) {
Some(p) => p,
None => {
let Some(p) = dialog()
- .set_title("Save")
- .add_filter("ProCraft artwork", &["procraft"])
+ .set_title(tr("Save"))
+ .add_filter(tr("ProCraft artwork"), &["procraft"])
.set_file_name(format!("{}.procraft", session.name()))
.save_file()
else {
@@ -846,8 +857,11 @@ pub fn export(
}
// each layer (or a model's texture set) a PNG file, in a folder the user picks
if matches!(format, Format::LayerPngs | Format::ChosenLayerPngs | Format::ModelTextures) {
- let title =
- if format == Format::ModelTextures { "Share textures as PNG files" } else { "Share layers as PNG files" };
+ let title = if format == Format::ModelTextures {
+ tr("Share textures as PNG files")
+ } else {
+ tr("Share layers as PNG files")
+ };
let Some(dir) = dialog().set_title(title).pick_folder() else { return };
let dir = dir.to_string_lossy().into_owned();
writing(session, card, "Can't share", move |session| {
@@ -861,7 +875,7 @@ pub fn export(
return;
}
let Some(path) = dialog()
- .set_title(format!("Export {}", format.name()))
+ .set_title(procraft_core::trf("Export {0}", &[("0", &format.name())]))
.add_filter(format.name(), &[format.extension()])
.set_file_name(format!("{}.{}", export_file_name(session.name(), format.package()), format.extension()))
.save_file()
@@ -907,7 +921,7 @@ pub fn export_plugin(session: &Arc, key: &str, card: &mut crate::
let Some(export) = session.plugin_exports().into_iter().find(|e| e.key == key) else { return };
let extension = export.extension.clone();
let Some(path) = dialog()
- .set_title(format!("Export {}", export.label))
+ .set_title(procraft_core::trf("Export {0}", &[("0", &export.label)]))
.add_filter(export.label.as_str(), &[extension.as_str()])
.set_file_name(format!("{}.{extension}", export_file_name(session.name(), false)))
.save_file()
@@ -996,7 +1010,7 @@ pub fn share_artworks(
let file_name = |name: &str| export_file_name(name.to_owned(), false);
let targets: Vec<(procraft_core::GalleryArtwork, PathBuf)> = if let [one] = list {
let Some(path) = dialog()
- .set_title(format!("Share {}", format.name()))
+ .set_title(procraft_core::trf("Share {0}", &[("0", &format.name())]))
.add_filter(format.name(), &[extension])
.set_file_name(format!("{}.{extension}", file_name(&one.name)))
.save_file()
@@ -1005,7 +1019,8 @@ pub fn share_artworks(
};
vec![(one.clone(), with_extension(path, extension))]
} else {
- let Some(dir) = dialog().set_title(format!("Share as {}", format.name())).pick_folder() else {
+ let Some(dir) = dialog().set_title(procraft_core::trf("Share as {0}", &[("0", &format.name())])).pick_folder()
+ else {
return;
};
let mut used = std::collections::HashSet::new();
@@ -1050,7 +1065,7 @@ pub fn share_artworks(
}
exporting.ended(false);
if !cancelled {
- tell_later("Can't share", &format!("{}: {e}", a.name));
+ tell_later(tr("Can't share"), &format!("{}: {e}", a.name));
}
return;
}
@@ -1062,7 +1077,7 @@ pub fn share_artworks(
Ok(made) => exporting.ended(made),
Err(e) => {
exporting.ended(false);
- tell_later("Can't share", &e);
+ tell_later(tr("Can't share"), &e);
}
}
});
@@ -1086,7 +1101,7 @@ pub fn share_pdf(
return;
}
let Some(path) = dialog()
- .set_title(format!("Share {}", Format::Pdf.name()))
+ .set_title(procraft_core::trf("Share {0}", &[("0", &Format::Pdf.name())]))
.add_filter(Format::Pdf.name(), &["pdf"])
.set_file_name(format!("{}.pdf", export_file_name(group.to_owned(), false)))
.save_file()
@@ -1119,7 +1134,7 @@ pub fn share_pdf(
let added = if s.prepare_offscreen() {
book.add(Arc::clone(&s)).map_err(|e| format!("{}: {e}", a.name))
} else {
- Err(format!("{}: There's no GPU device to draw it with.", a.name))
+ Err(procraft_core::trf("{0}: There's no GPU device to draw it with.", &[("0", &a.name)]))
};
open.opened(None);
added?;
@@ -1134,7 +1149,7 @@ pub fn share_pdf(
Err(e) => {
exporting.ended(false);
if !exporting.cancelled() {
- tell_later("Can't share", &e);
+ tell_later(tr("Can't share"), &e);
}
}
}
@@ -1193,7 +1208,7 @@ fn write_artwork_open(
open.opened(Some(&s));
let written = (|| {
if !s.prepare_offscreen() {
- return Err("There's no GPU device to draw it with.".to_owned());
+ return Err(tr("There's no GPU device to draw it with.").to_owned());
}
match format {
Format::Procraft | Format::Package => {
diff --git a/desktop/src/filter_list.rs b/desktop/src/filter_list.rs
index cae609bdd..12388473e 100644
--- a/desktop/src/filter_list.rs
+++ b/desktop/src/filter_list.rs
@@ -2,6 +2,8 @@
//! as the Textures sheet is, with the filters the plugins on offer under their headings, in the
//! order they list them. A click picks one; Cancel, or a click off the sheet, closes it.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use egui::{Align2, Rect, Sense, Ui, UiBuilder, pos2, vec2};
use procraft_core::PluginLayerFilter;
@@ -75,9 +77,10 @@ impl FilterList {
}
let head = Rect::from_min_size(pos2(sheet.left() + 19.0, sheet.top() + 30.0), vec2(sheet.width() - 38.0, 39.0));
let title_at = pos2(head.left(), head.center().y);
- text(ui.painter(), title_at, Align2::LEFT_CENTER, "Filter Layer", 28.0, Weight::Bold, argb(TITLE));
+ text(ui.painter(), title_at, Align2::LEFT_CENTER, tr("Filter Layer"), 28.0, Weight::Bold, argb(TITLE));
let cancel_at = pos2(head.right(), head.center().y);
- let cancel = text(ui.painter(), cancel_at, Align2::RIGHT_CENTER, "Cancel", 17.0, Weight::Regular, argb(DIM));
+ let cancel =
+ text(ui.painter(), cancel_at, Align2::RIGHT_CENTER, tr("Cancel"), 17.0, Weight::Regular, argb(DIM));
if ui.interact(cancel.expand(8.0), ui.scope_id().with("filter layers cancel"), Sense::click()).clicked() {
return Picked::Cancelled;
}
diff --git a/desktop/src/gallery.rs b/desktop/src/gallery.rs
index 197bdfc35..b914e43ca 100644
--- a/desktop/src/gallery.rs
+++ b/desktop/src/gallery.rs
@@ -5,6 +5,8 @@
//! share, duplicate or delete. The artworks are the core's store (gallery.rs), kept in the app's folder; the presets
//! are the core's too, kept as the Android app keeps them.
+use procraft_core::{message, tr, trf};
+
use crate::scroll::ScrollArea;
use std::collections::HashMap;
use std::sync::Arc;
@@ -573,7 +575,7 @@ impl Gallery {
ui.painter(),
at,
Align2::CENTER_CENTER,
- "Tap + to start a new canvas",
+ tr("Tap + to start a new canvas"),
17.0,
Weight::Regular,
argb(TEXT),
@@ -738,7 +740,7 @@ impl Gallery {
self.end_selecting();
}
SelectAction::Delete => {
- self.alert.open(&pick.delete_title, &pick.delete_message, "Delete", Some(&icons::TRASH));
+ self.alert.open(&pick.delete_title, &pick.delete_message, tr("Delete"), Some(&icons::TRASH));
}
SelectAction::More => self.more_open = !self.more_open,
// several go into one PDF, named after the stack they are in (or the one picked alone)
@@ -760,7 +762,7 @@ impl Gallery {
/// under More, the title on one line shrunk to fit beside them.
fn header_fit(&mut self, ui: &Ui, screen: Rect) -> GalleryHeaderFit {
let title = self.stack.as_ref().map_or("ProCraft", |s| s.1.as_str()).to_owned();
- let own = ui.painter().layout_no_wrap(title, Weight::Bold.font(36.0), Color32::WHITE).size();
+ let own = crate::look::layout_no_wrap(ui.painter(), title, Weight::Bold.font(36.0), Color32::WHITE).size();
// in a stack the name follows the way back; selecting, it stands alone
let title_x = if self.stack.is_some() && !self.selecting { 60.0 } else { 32.0 };
let fit = gallery_header_fit(
@@ -872,7 +874,7 @@ impl Gallery {
ui.painter(),
pos2(body.left() + 24.0, body.top() + 14.0),
Align2::LEFT_TOP,
- "More Options",
+ tr("More Options"),
24.0,
Weight::Bold,
ink,
@@ -1051,7 +1053,7 @@ impl Gallery {
ui.painter(),
pos2(field.center().x, field.bottom() + 12.0),
Align2::CENTER_TOP,
- "ProCraft",
+ tr("ProCraft"),
64.0,
Weight::Bold,
Color32::WHITE,
@@ -1074,7 +1076,7 @@ impl Gallery {
ui.painter(),
recovery.center(),
Align2::CENTER_CENTER,
- "Start Gallery Recovery",
+ tr("Start Gallery Recovery"),
15.0,
Weight::Regular,
ink,
@@ -1307,7 +1309,7 @@ impl Gallery {
ui,
pos2(screen.left() + 32.0, top + 11.0),
Align2::LEFT_TOP,
- "ProCraft",
+ tr("ProCraft"),
argb(TITLE).gamma_multiply(title_in),
&fit,
);
@@ -1756,7 +1758,8 @@ impl Gallery {
let (k, origin) = (0.2 + 0.8 * open, pos2(cell.center().x + width / 2.0, frame.center().y));
let grown = |r: Rect| Rect::from_min_max(origin + (r.min - origin) * k, origin + (r.max - origin) * k);
let mut x = cell.center().x - width / 2.0;
- for (label, delete) in [("Share", false), ("Duplicate", false), ("Delete", true)] {
+ for (label, delete) in [(message!("Share"), false), (message!("Duplicate"), false), (message!("Delete"), true)]
+ {
let pill =
Rect::from_min_size(pos2(x, frame.center().y - SWIPE_PILL.1 / 2.0), vec2(SWIPE_PILL.0, SWIPE_PILL.1));
x += SWIPE_PILL.0 + 3.0;
@@ -1769,7 +1772,7 @@ impl Gallery {
ui.painter(),
drawn.center(),
Align2::CENTER_CENTER,
- label,
+ tr(label),
words,
Weight::SemiBold,
ink.gamma_multiply(alpha),
@@ -1786,13 +1789,13 @@ impl Gallery {
"Delete" => {
self.swiped = None;
self.deleting = Some(on.dir.clone());
- let title = format!("Delete \u{201c}{}\u{201d}?", on.name);
+ let title = trf("Delete \u{201c}{0}\u{201d}?", &[("0", &on.name)]);
let message = if on.stack {
- format!("Its {} artworks go with it. This can't be undone.", on.artworks.len())
+ trf("Its {0} artworks go with it. This can't be undone.", &[("0", &on.artworks.len())])
} else {
- "This can't be undone.".to_owned()
+ tr("This can't be undone.").to_owned()
};
- self.alert.open(&title, &message, "Delete", Some(&icons::TRASH));
+ self.alert.open(&title, &message, tr("Delete"), Some(&icons::TRASH));
}
_ => {
self.swiped = None;
@@ -1854,7 +1857,7 @@ impl Gallery {
ui.painter(),
pos2(rect.left() + 22.0, rect.top() + 27.5),
Align2::LEFT_CENTER,
- "Image Format",
+ tr("Image Format"),
24.0,
Weight::Bold,
ink,
@@ -2056,7 +2059,7 @@ impl Gallery {
let ink = if self.selecting && chosen { Color32::WHITE } else { argb(TEXT) };
let name = one_line(ui, &a.name, 13.0, Weight::SemiBold, ink, frame.width());
let at = pos2(cell.center().x - name.size().x / 2.0, frame.bottom() + 12.0);
- ui.painter().galley(at, name.clone(), Color32::WHITE);
+ crate::look::draw_layout(ui.painter(), at, name.clone(), Color32::WHITE);
let size = format!("{} \u{d7} {}px", a.width, a.height);
text(
ui.painter(),
@@ -2111,8 +2114,8 @@ impl Gallery {
let ink = if self.selecting && chosen { Color32::WHITE } else { argb(TEXT) };
let label = one_line(ui, name, 13.0, Weight::SemiBold, ink, frame.width());
let at = pos2(cell.center().x - label.size().x / 2.0, frame.bottom() + 12.0);
- ui.painter().galley(at, label.clone(), Color32::WHITE);
- let count = format!("{} artworks", artworks.len());
+ crate::look::draw_layout(ui.painter(), at, label.clone(), Color32::WHITE);
+ let count = trf("{0} artworks", &[("0", &artworks.len())]);
text(
ui.painter(),
pos2(cell.center().x, at.y + label.size().y),
@@ -2145,7 +2148,7 @@ impl Gallery {
ui.painter(),
pos2(body.left() + 23.0, body.top() + 21.0),
Align2::LEFT_TOP,
- "New canvas",
+ tr("New canvas"),
26.0,
Weight::Bold,
ink,
@@ -2166,7 +2169,7 @@ impl Gallery {
let row =
Rect::from_min_size(pos2(body.left() + 9.0, body.top() + NEW_HEADER), vec2(NEW_WIDTH - 18.0, 38.0));
ui.painter().rect_filled(row, 19.0, argb(LIGHT_ROW_STRONG));
- preset_row(ui, row, "Screen Size", &format!("{sw} \u{d7} {sh}px"), P3);
+ preset_row(ui, row, tr("Screen Size"), &format!("{sw} \u{d7} {sh}px"), P3);
if ui.interact(row, ui.scope_id().with("screen size"), Sense::click()).clicked() {
asked = Some(Asked::ScreenSize(self.folder()));
}
@@ -2299,20 +2302,37 @@ fn preset_row(ui: &Ui, row: Rect, name: &str, size: &str, profile: &str) {
let chip =
Rect::from_min_max(pos2(x - galley.size().x - 16.0, row.center().y - 9.0), pos2(x, row.center().y + 9.0));
ui.painter().rect_filled(chip, 9.0, argb(LIGHT_CHIP));
- ui.painter().galley(pos2(chip.left() + 8.0, chip.center().y - galley.size().y / 2.0), galley, ink);
+ crate::look::draw_layout(
+ ui.painter(),
+ pos2(chip.left() + 8.0, chip.center().y - galley.size().y / 2.0),
+ galley,
+ ink,
+ );
x = chip.left() - 4.0;
}
let galley = one_line(ui, name, 17.0, Weight::Regular, ink, x - 8.0 - (row.left() + 17.0));
- ui.painter().galley(pos2(row.left() + 17.0, row.center().y - galley.size().y / 2.0), galley, ink);
+ crate::look::draw_layout(
+ ui.painter(),
+ pos2(row.left() + 17.0, row.center().y - galley.size().y / 2.0),
+ galley,
+ ink,
+ );
}
/// `text` on one line at most `max_width` wide, ending in "…" when cut.
-fn one_line(ui: &Ui, text: &str, size: f32, weight: Weight, colour: Color32, max_width: f32) -> Arc {
+fn one_line(
+ ui: &Ui,
+ text: &str,
+ size: f32,
+ weight: Weight,
+ colour: Color32,
+ max_width: f32,
+) -> crate::look::TextLayout {
let mut job = LayoutJob::default();
let format = TextFormat { font_id: weight.font(size), color: colour, ..Default::default() };
job.append(text, 0.0, format);
job.wrap = TextWrapping { max_width, max_rows: 1, break_anywhere: true, overflow_character: Some('\u{2026}') };
- ui.painter().layout_job(job)
+ crate::look::layout_job(ui.painter(), job)
}
fn presets_path() -> std::path::PathBuf {
@@ -2540,15 +2560,15 @@ fn select_action(action: GalleryAction) -> SelectAction {
/// A title-row button's name, as More's list shows it.
fn action_label(action: GalleryAction) -> &'static str {
match action {
- GalleryAction::Select => "Select",
- GalleryAction::Import => "Import",
- GalleryAction::Photo => "Photo",
- GalleryAction::Stack => "Stack",
- GalleryAction::Preview => "Preview",
- GalleryAction::Share => "Share",
- GalleryAction::Duplicate => "Duplicate",
- GalleryAction::Delete => "Delete",
- GalleryAction::More => "More",
+ GalleryAction::Select => tr("Select"),
+ GalleryAction::Import => tr("Import"),
+ GalleryAction::Photo => tr("Photo"),
+ GalleryAction::Stack => tr("Stack"),
+ GalleryAction::Preview => tr("Preview"),
+ GalleryAction::Share => tr("Share"),
+ GalleryAction::Duplicate => tr("Duplicate"),
+ GalleryAction::Delete => tr("Delete"),
+ GalleryAction::More => tr("More"),
}
}
@@ -2556,7 +2576,7 @@ fn action_label(action: GalleryAction) -> &'static str {
/// as it always was where it fits; else shrunk as `fit` says, about the same middle, on one line
/// cut short past the room it gets. Where it is.
fn title_text(ui: &Ui, at: Pos2, align: Align2, name: &str, ink: Color32, fit: &GalleryHeaderFit) -> Rect {
- let own = ui.painter().layout_no_wrap(name.to_owned(), Weight::Bold.font(36.0), ink).size();
+ let own = crate::look::layout_no_wrap(ui.painter(), name.to_owned(), Weight::Bold.font(36.0), ink).size();
if fit.title_scale >= 1.0 && own.x <= fit.title_room + 0.5 {
return text(ui.painter(), at, align, name, 36.0, Weight::Bold, ink);
}
@@ -2567,7 +2587,7 @@ fn title_text(ui: &Ui, at: Pos2, align: Align2, name: &str, ink: Color32, fit: &
};
let galley = one_line(ui, name, 36.0 * fit.title_scale, Weight::Bold, ink, fit.title_room.max(1.0));
let rect = Align2::LEFT_CENTER.anchor_size(pos2(at.x, middle), galley.size());
- ui.painter().galley(rect.min, galley, ink);
+ crate::look::draw_layout(ui.painter(), rect.min, galley, ink);
rect
}
diff --git a/desktop/src/gesture_controls.rs b/desktop/src/gesture_controls.rs
index 8b169c078..b627903de 100644
--- a/desktop/src/gesture_controls.rs
+++ b/desktop/src/gesture_controls.rs
@@ -3,6 +3,8 @@
//! it is narrow) and, for the one chosen, a card of switches for the ways of touching that do it,
//! a delay under the held ones; Reset to defaults under General; Done.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use egui::{Align2, Color32, Id, Order, Rect, Sense, Stroke, Ui, UiBuilder, pos2, vec2};
use procraft_core::{GestureOption, GesturePurpose, GestureSettings, gesture_options, gesture_purposes};
@@ -137,7 +139,7 @@ impl GestureControls {
ui.painter().rect_filled(card, 20, argb(RAIL_FILL));
ui.painter().rect_stroke(card, 20, Stroke::new(1.0, argb(CARD_EDGE)), egui::StrokeKind::Inside);
let title = pos2(card.left() + 24.0, card.top() + 19.0);
- text(ui.painter(), title, Align2::LEFT_TOP, "Gesture controls", 24.0, Weight::Bold, argb(INK));
+ text(ui.painter(), title, Align2::LEFT_TOP, tr("Gesture controls"), 24.0, Weight::Bold, argb(INK));
let mut y = card.top() + 65.0;
for p in gesture_purposes() {
let row = Rect::from_min_size(pos2(card.left() + 8.0, y), vec2(card.width() - 16.0, 53.0));
@@ -235,16 +237,16 @@ impl GestureControls {
ui.painter(),
reset.center(),
Align2::CENTER_CENTER,
- "Reset to defaults",
+ tr("Reset to defaults"),
15.0,
Weight::Regular,
ink,
);
if response.clicked() {
self.reset.open(
- "Reset gesture controls?",
- "Every gesture goes back to how the app starts out.",
- "Reset",
+ tr("Reset gesture controls?"),
+ tr("Every gesture goes back to how the app starts out."),
+ tr("Reset"),
None,
);
}
@@ -271,7 +273,7 @@ fn option_row(ui: &Ui, o: &GestureOption, on: bool, row: Rect) -> bool {
fn delay_row(ui: &Ui, seconds: f32, enabled: bool, row: Rect, key: &str) -> Option {
let ink = argb(INK);
let left = row.left() + 28.0;
- text(ui.painter(), pos2(left, row.center().y), Align2::LEFT_CENTER, "Delay", 15.0, Weight::Regular, ink);
+ text(ui.painter(), pos2(left, row.center().y), Align2::LEFT_CENTER, tr("Delay"), 15.0, Weight::Regular, ink);
let shown = format!("{seconds:.2}s");
let value = text(
ui.painter(),
diff --git a/desktop/src/gradient_map.rs b/desktop/src/gradient_map.rs
index 2f262527a..cd34ecb89 100644
--- a/desktop/src/gradient_map.rs
+++ b/desktop/src/gradient_map.rs
@@ -4,6 +4,8 @@
//! on the bar adds a stop, a stop drags along it, a tap on one opens the compact colour picker
//! over it, a hold offers Delete). The library is the core's (gradients.rs), kept between runs.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use std::time::{Duration, Instant};
@@ -121,7 +123,7 @@ impl GradientMap {
ui.painter().rect_filled(rect, 33, argb(PANEL_FILL));
let inner = Rect::from_min_max(rect.min + vec2(14.0, 12.0), rect.max - vec2(14.0, 12.0));
let header = Rect::from_min_size(inner.min, vec2(inner.width(), 40.0));
- let title = if self.editing.is_some() { "Gradient Map" } else { "Gradient Library" };
+ let title = if self.editing.is_some() { tr("Gradient Map") } else { tr("Gradient Library") };
let at = pos2(header.left() + 14.0, header.center().y);
text(ui.painter(), at, Align2::LEFT_CENTER, title, 20.0, Weight::Bold, argb(MENU_TEXT));
let button = Rect::from_min_size(pos2(header.right() - 40.0, header.top()), vec2(40.0, 40.0));
@@ -359,10 +361,10 @@ impl GradientMap {
let Some((what, over)) = self.menu_for else { return };
let entries: Vec = match what {
Pressed::Card(_) => vec![
- Entry::Item(&icons::MENU_TRASH, "Delete", menu::DANGER),
- Entry::Item(&icons::MENU_DUPLICATE, "Duplicate", menu::INK),
+ Entry::Item(&icons::MENU_TRASH, procraft_core::message!("Delete"), menu::DANGER),
+ Entry::Item(&icons::MENU_DUPLICATE, procraft_core::message!("Duplicate"), menu::INK),
],
- Pressed::Stop(_) => vec![Entry::Item(&icons::MENU_TRASH, "Delete", menu::DANGER)],
+ Pressed::Stop(_) => vec![Entry::Item(&icons::MENU_TRASH, procraft_core::message!("Delete"), menu::DANGER)],
};
let size = vec2(menu::LIBRARY_WIDTH, menu::entries_height(&entries));
let rect = Rect::from_min_size(pos2(over.center().x - size.x / 2.0, over.top() - size.y), size);
diff --git a/desktop/src/guide_editor.rs b/desktop/src/guide_editor.rs
index 0611000b5..c3c8a234b 100644
--- a/desktop/src/guide_editor.rs
+++ b/desktop/src/guide_editor.rs
@@ -6,6 +6,8 @@
//! view, as the wheel and a trackpad's pinch do; a handle tapped shows its menu (a point's Delete,
//! a centre's Reset). The guide itself is the core's (guide.rs).
+use procraft_core::tr;
+
use egui::{Align2, Color32, Id, Order, Pos2, Rect, Sense, Stroke, pos2, vec2};
use procraft_core::{CanvasSession, GuideInfo, GuideType, GuideUnit, SymmetryType};
@@ -152,7 +154,7 @@ impl SizeKeypad {
let ink = argb(SHEET_INK);
// "Length" 16 into a 250 wide title centred over the sheet, the size from 144 on
let title = pos2(sheet.center().x - 125.0 + 16.0, sheet.top() + 24.0);
- text(ui.painter(), title, Align2::LEFT_CENTER, "Length", 12.0, Weight::Regular, ink);
+ text(ui.painter(), title, Align2::LEFT_CENTER, tr("Length"), 12.0, Weight::Regular, ink);
let typed = title + vec2(144.0, 0.0);
text(ui.painter(), typed, Align2::LEFT_CENTER, &self.typed, 12.0, Weight::Regular, ink);
// narrower keys where the window is too narrow for them
@@ -311,7 +313,7 @@ impl GuideEditor {
ui.painter(),
band.min + vec2(32.0, 27.0),
Align2::LEFT_TOP,
- "Drawing Guides",
+ tr("Drawing Guides"),
20.0,
Weight::Bold,
argb(TITLE),
@@ -320,7 +322,15 @@ impl GuideEditor {
let cancel = Rect::from_min_size(pos2(done.left() - 13.0 - 73.0, band.top() + 20.0), vec2(73.0, 43.0));
ui.painter().rect_filled(cancel, 21.5, argb(BUTTON));
ui.painter().rect_stroke(cancel, 21.5, Stroke::new(1.0, argb(BUTTON_EDGE)), egui::StrokeKind::Inside);
- text(ui.painter(), cancel.center(), Align2::CENTER_CENTER, "Cancel", 17.0, Weight::Regular, argb(TITLE));
+ text(
+ ui.painter(),
+ cancel.center(),
+ Align2::CENTER_CENTER,
+ tr("Cancel"),
+ 17.0,
+ Weight::Regular,
+ argb(TITLE),
+ );
if ui.interact(cancel, ui.scope_id().with("cancel"), Sense::click()).clicked() {
ended = Some(false);
}
@@ -346,7 +356,7 @@ impl GuideEditor {
ui.painter(),
note.center(),
Align2::CENTER_CENTER,
- "Tap to create vanishing points",
+ tr("Tap to create vanishing points"),
12.0,
Weight::Regular,
argb(TITLE),
@@ -427,7 +437,7 @@ impl GuideEditor {
ui,
pos2(third, third_top),
slider_w,
- "Grid size",
+ tr("Grid size"),
size_to_slider(g.size),
"",
false,
@@ -446,7 +456,7 @@ impl GuideEditor {
ui.painter(),
options_button.center(),
Align2::CENTER_CENTER,
- "Options",
+ tr("Options"),
15.0,
Weight::Regular,
argb(LABEL),
@@ -464,7 +474,7 @@ impl GuideEditor {
crate::transform::switch(ui, switch_at, g.assisted, "assisted");
let label_at = pos2(if wide { switch_at.x - 12.0 } else { third + slider_w + gap + 8.0 }, switch_y);
let align = if wide { Align2::RIGHT_CENTER } else { Align2::LEFT_CENTER };
- text(ui.painter(), label_at, align, "Assisted Drawing", 15.0, Weight::Regular, argb(LABEL));
+ text(ui.painter(), label_at, align, tr("Assisted Drawing"), 15.0, Weight::Regular, argb(LABEL));
let tap = Rect::from_min_size(switch_at, vec2(63.0, 28.0));
if ui.interact(tap, ui.scope_id().with("assisted"), Sense::click()).clicked() {
session.set_guide_assisted(!g.assisted);
@@ -489,16 +499,17 @@ impl GuideEditor {
let chosen = kinds.iter().position(|k| *k == g.symmetry).unwrap_or(0);
let height = 44.0 * 4.0 + 3.0 + 14.0 + 40.0 * 2.0;
let mut open = true;
- options_menu(ctx, &mut open, button, "Guide Options", height, |ui, inner| {
+ options_menu(ctx, &mut open, button, tr("Guide Options"), height, |ui, inner| {
let group = Rect::from_min_size(inner.min, vec2(inner.width(), 44.0 * 4.0 + 3.0));
- let labels = ["Vertical", "Horizontal", "Quadrant", "Radial"];
+ let labels = [tr("Vertical"), tr("Horizontal"), tr("Quadrant"), tr("Radial")];
if let Some(k) = options_choices(ui, look, group, 44.0, &labels, chosen)
&& let Some(kind) = kinds.get(k)
{
session.set_guide_symmetry(*kind, g.rotational);
}
- for (i, (label, on)) in
- [("Rotational Symmetry", g.rotational), ("Assisted Drawing", g.assisted)].into_iter().enumerate()
+ for (i, (label, on)) in [(tr("Rotational Symmetry"), g.rotational), (tr("Assisted Drawing"), g.assisted)]
+ .into_iter()
+ .enumerate()
{
let row = Rect::from_min_size(
pos2(inner.left(), group.bottom() + 14.0 + 40.0 * i as f32),
@@ -533,12 +544,13 @@ impl GuideEditor {
/// slider chip: 12 either side of the words and 3 above and below, 8 right of and 4 above where a
/// plain value sits. Returns whether it was tapped.
fn size_chip(ui: &egui::Ui, at: Pos2, width: f32, label: &str) -> bool {
- let galley = ui.painter().layout_no_wrap(label.to_owned(), Weight::Regular.font(16.0), argb(CHIP_INK));
+ let galley =
+ crate::look::layout_no_wrap(ui.painter(), label.to_owned(), Weight::Regular.font(16.0), argb(CHIP_INK));
let right = at.x + width - 15.0 + 8.0;
let top = at.y + 6.0 - 4.0;
let chip = Rect::from_min_max(pos2(right - galley.size().x - 24.0, top), pos2(right, top + galley.size().y + 6.0));
ui.painter().rect_filled(chip, 14.0, argb(CHIP));
- ui.painter().galley(pos2(chip.left() + 12.0, chip.top() + 3.0), galley, argb(CHIP_INK));
+ crate::look::draw_layout(ui.painter(), pos2(chip.left() + 12.0, chip.top() + 3.0), galley, argb(CHIP_INK));
ui.interact(chip, ui.scope_id().with("grid size chip"), Sense::click()).clicked()
}
diff --git a/desktop/src/layers.rs b/desktop/src/layers.rs
index 63b09c1b6..adc6aac03 100644
--- a/desktop/src/layers.rs
+++ b/desktop/src/layers.rs
@@ -9,6 +9,8 @@
//! texture set's name over its meshes (each its picture and box), the open mesh's layers under it,
//! and under a layer its channels (colour, roughness, metalness), one of which a click paints on.
+use procraft_core::tr;
+
use crate::scroll::{RowDrag, ScrollArea};
use std::collections::HashMap;
use std::time::Instant;
@@ -80,7 +82,7 @@ const THUMBS_A_FRAME: usize = 4;
const OPTIONS_LEFT: f32 = -183.0;
const OPTIONS_WIDTH: f32 = 194.0;
/// Delete on a locked layer's row says this.
-const LOCKED_DELETE: &str = "A locked layer can’t be deleted. Unlock it first.";
+const LOCKED_DELETE: &str = procraft_core::message!("A locked layer can\u{2019}t be deleted. Unlock it first.");
const OPTIONS_TOP: f32 = 57.0;
const OPTIONS_CORNER: f32 = 24.0;
/// The blend editor under a row: the opacity and its slider, then the list of modes (nine rows
@@ -537,7 +539,7 @@ impl Layers {
}
let body = panel::body_in(ui.ctx(), rect);
// the chevron turns blue while layers are picked
- let (title_tapped, row) = panel::header_title(ui, look, body, "Layers", 24.0, true, any_picked);
+ let (title_tapped, row) = panel::header_title(ui, look, body, tr("Layers"), 24.0, true, any_picked);
title = row;
if title_tapped {
self.title_menu.open();
@@ -759,7 +761,7 @@ impl Layers {
// asked first; then, as measured, a locked one among them stops it, said why
if self.deleting.show(ctx, look) == Some(Answer::Action) {
if session.chosen_locked() {
- self.locked.tell("Locked layer selection", LOCKED_DELETE, Some(&icons::PAGE_LOCKED));
+ self.locked.tell(tr("Locked layer selection"), tr(LOCKED_DELETE), Some(&icons::PAGE_LOCKED));
} else {
session.delete_picked();
}
@@ -788,16 +790,17 @@ impl Layers {
backdrops: &mut Vec,
) {
let ink = menu::INK;
- let mut entries = vec![Entry::Item(&icons::MENU_SELECT_ALL, "Select All", ink), menu::DIVIDER];
+ let mut entries =
+ vec![Entry::Item(&icons::MENU_SELECT_ALL, procraft_core::message!("Select All"), ink), menu::DIVIDER];
if picked {
- entries.push(Entry::Item(&icons::MENU_GROUP, "Group", ink));
- entries.push(Entry::Item(&icons::MENU_MERGE, "Merge", ink));
+ entries.push(Entry::Item(&icons::MENU_GROUP, procraft_core::message!("Group"), ink));
+ entries.push(Entry::Item(&icons::MENU_MERGE, procraft_core::message!("Merge"), ink));
entries.push(menu::DIVIDER);
}
- entries.push(Entry::Item(&icons::MENU_SHARE, "Share", ink));
- entries.push(Entry::Item(&icons::MENU_DUPLICATE, "Duplicate", ink));
+ entries.push(Entry::Item(&icons::MENU_SHARE, procraft_core::message!("Share"), ink));
+ entries.push(Entry::Item(&icons::MENU_DUPLICATE, procraft_core::message!("Duplicate"), ink));
entries.push(menu::DIVIDER);
- entries.push(Entry::Item(&icons::MENU_TRASH, "Delete", menu::DANGER));
+ entries.push(Entry::Item(&icons::MENU_TRASH, procraft_core::message!("Delete"), menu::DANGER));
let size = vec2(menu::LIBRARY_WIDTH, menu::entries_height(&entries));
let screen = panel::screen(ctx);
let left = (title.center().x - size.x / 2.0).clamp(screen.left(), (screen.right() - size.x).max(screen.left()));
@@ -826,7 +829,12 @@ impl Layers {
crate::files::no_room(session);
}
}
- _ => self.deleting.open("Delete these layers?", "Undo brings them back.", "Delete", Some(&icons::TRASH)),
+ _ => self.deleting.open(
+ tr("Delete these layers?"),
+ tr("Undo brings them back."),
+ tr("Delete"),
+ Some(&icons::TRASH),
+ ),
}
}
@@ -951,7 +959,7 @@ impl Layers {
if slide > PICK_REACH / 2.0 {
if !session.pick_more_submeshes(index as u32) {
self.notice =
- Some(("Those meshes aren't in the same texture set".to_owned(), true, NoticeKind::Problem));
+ Some((tr("Those meshes aren't in the same texture set").to_owned(), true, NoticeKind::Problem));
}
self.mesh_swiped = None;
} else {
@@ -962,13 +970,16 @@ impl Layers {
self.mesh_slid.insert(index, slide);
if slide < 0.0 {
let rect = Rect::from_min_max(pos2(place.right() - SWIPE_BUTTON, place.top()), place.max);
- let label = if locked { "Unlock" } else { "Lock" };
+ let label = if locked { "Unlock" } else { tr("Lock") };
ui.painter().rect_filled(rect, 8, argb(SWIPE_FILL));
text(ui.painter(), rect.center(), Align2::CENTER_CENTER, label, 15.0, Weight::Medium, argb(SWIPE_INK));
if ui.interact(rect, ui.scope_id().with(("mesh lock", index)), Sense::click()).clicked() {
session.set_submesh_locked(index as u32, !locked);
- self.notice =
- Some((if locked { "Unlock mesh" } else { "Lock mesh" }.to_owned(), false, NoticeKind::Done));
+ self.notice = Some((
+ if locked { tr("Unlock mesh") } else { tr("Lock mesh") }.to_owned(),
+ false,
+ NoticeKind::Done,
+ ));
self.mesh_swiped = None;
self.mesh_slid.remove(&index);
}
@@ -999,7 +1010,7 @@ impl Layers {
let arrow = Rect::from_min_size(pos2(visibility.left() - 44.0 + 8.0, row.center().y - 25.5), vec2(44.0, 51.0));
let left = tile.right() + 29.0;
let g = galley(ui, name, 17.0, Weight::Regular, ink, arrow.left() - 6.0 - left);
- ui.painter().galley(pos2(left, row.center().y - g.size().y / 2.0), g, ink);
+ crate::look::draw_layout(ui.painter(), pos2(left, row.center().y - g.size().y / 2.0), g, ink);
look.icon(ui, if open { &icons::CHEVRON_DOWN } else { &icons::CHEVRON_RIGHT }, arrow.center(), 16.0, ink);
if locked {
look.icon(ui, &icons::PAGE_LOCKED, pos2(arrow.left() - 4.0, row.center().y), 16.0, ink);
@@ -1008,8 +1019,11 @@ impl Layers {
check_box(ui, look, visibility.center(), !hidden, argb(CHECK_FILL));
if ui.interact(visibility, ui.scope_id().with(("mesh box", index)), Sense::click()).clicked() {
session.set_submesh_hidden(index as u32, !hidden);
- self.notice =
- Some((if hidden { "Show Submesh" } else { "Hide Submesh" }.to_owned(), false, NoticeKind::Done));
+ self.notice = Some((
+ if hidden { tr("Show Submesh") } else { tr("Hide Submesh") }.to_owned(),
+ false,
+ NoticeKind::Done,
+ ));
} else if response.clicked() {
self.open_mesh(session, colours, index);
}
@@ -1018,15 +1032,17 @@ impl Layers {
/// Layer `id`'s content in `channel` replaced by a picture chosen now.
fn replace_map(&mut self, session: &CanvasSession, colours: &mut Colours, id: u64, channel: u32) {
- let Some(path) = crate::files::dialog().set_title("Replace Material Map Content").pick_file() else { return };
+ let Some(path) = crate::files::dialog().set_title(tr("Replace Material Map Content")).pick_file() else {
+ return;
+ };
let Ok(picture) = image::open(&path) else {
- self.notice = Some(("This picture can't be opened.".to_owned(), true, NoticeKind::Problem));
+ self.notice = Some((tr("This picture can't be opened.").to_owned(), true, NoticeKind::Problem));
return;
};
let rgba = picture.to_rgba8();
let image = ThumbnailImage { width: rgba.width(), height: rgba.height(), rgba: rgba.into_raw() };
if session.replace_material_map(id, channel, image) {
- self.notice = Some(("Replace Material Map Content".to_owned(), false, NoticeKind::Done));
+ self.notice = Some((tr("Replace Material Map Content").to_owned(), false, NoticeKind::Done));
self.channel_pictures.retain(|(_, l), _| *l != id);
self.follow_channel(session, colours);
}
@@ -1148,17 +1164,19 @@ impl Layers {
/// The buttons a row slid left shows behind it: Lock (or Unlock), Duplicate (not for a mask)
/// and Delete (Clear for the only layer).
fn swipe_buttons(&mut self, ui: &Ui, session: &CanvasSession, l: &LayerInfo, row: Rect, alone: bool) {
- let mut buttons = vec![(if l.locked { "Unlock" } else { "Lock" }, SWIPE_FILL, SWIPE_INK)];
+ use procraft_core::message;
+
+ let mut buttons = vec![(if l.locked { message!("Unlock") } else { message!("Lock") }, SWIPE_FILL, SWIPE_INK)];
if l.kind != LayerType::Mask {
- buttons.push(("Duplicate", SWIPE_FILL, SWIPE_INK));
+ buttons.push((message!("Duplicate"), SWIPE_FILL, SWIPE_INK));
}
- buttons.push((if alone { "Clear" } else { "Delete" }, SWIPE_DELETE, 0xFFFFFFFF));
+ buttons.push((if alone { message!("Clear") } else { message!("Delete") }, SWIPE_DELETE, 0xFFFFFFFF));
let mut right = row.right();
for (label, fill, ink) in buttons.into_iter().rev() {
let rect = Rect::from_min_max(pos2(right - SWIPE_BUTTON, row.top()), pos2(right, row.bottom()));
right -= SWIPE_BUTTON + SWIPE_GAP;
ui.painter().rect_filled(rect, 8, argb(fill));
- text(ui.painter(), rect.center(), Align2::CENTER_CENTER, label, 15.0, Weight::Medium, argb(ink));
+ text(ui.painter(), rect.center(), Align2::CENTER_CENTER, tr(label), 15.0, Weight::Medium, argb(ink));
if ui.interact(rect, ui.scope_id().with(("swipe", l.id, label)), Sense::click()).clicked() {
match label {
"Lock" | "Unlock" => {
@@ -1174,12 +1192,20 @@ impl Layers {
}
// as measured, a locked one is told about, not deleted
_ if l.locked => {
- self.locked.tell("Locked layer selection", LOCKED_DELETE, Some(&icons::PAGE_LOCKED))
+ self.locked.tell(tr("Locked layer selection"), tr(LOCKED_DELETE), Some(&icons::PAGE_LOCKED))
}
_ if shared_by_meshes(session) => {
self.shared_going = Some(l.id);
- let on_all = format!("\u{201c}{}\u{201d} is on every mesh of this texture set.", l.name);
- self.deleting_shared.open("Delete shared layer?", &on_all, "Delete", Some(&icons::TRASH));
+ let on_all = procraft_core::trf(
+ "\u{201c}{0}\u{201d} is on every mesh of this texture set.",
+ &[("0", &l.name)],
+ );
+ self.deleting_shared.open(
+ tr("Delete shared layer?"),
+ &on_all,
+ tr("Delete"),
+ Some(&icons::TRASH),
+ );
}
_ => _ = session.delete_layer(l.id),
}
@@ -1603,8 +1629,11 @@ impl Layers {
}
LayerOption::Rasterize => {
session.rasterize_layer(l.id);
- self.notice =
- Some((if l.text { "Text rasterized" } else { "Layer rasterized" }.into(), true, NoticeKind::Done));
+ self.notice = Some((
+ if l.text { tr("Text rasterized") } else { tr("Layer rasterized") }.into(),
+ true,
+ NoticeKind::Done,
+ ));
}
// a plugin's layer: its strokes recoloured, or given the paint brush, as strokes
LayerOption::Recolour | LayerOption::ApplyBrush => {
@@ -1634,7 +1663,7 @@ impl Layers {
let left = rect.left() + 13.0;
let right = rect.right() - 13.0;
let y = rect.top() + 22.0 + 23.0 / 2.0;
- text(ui.painter(), pos2(left, y), Align2::LEFT_CENTER, "Opacity", 17.0, Weight::Regular, ink);
+ text(ui.painter(), pos2(left, y), Align2::LEFT_CENTER, tr("Opacity"), 17.0, Weight::Regular, ink);
let reading =
if l.opacity >= 0.995 { "Max".to_owned() } else { format!("{}%", (l.opacity * 100.0).round() as i32) };
text(ui.painter(), pos2(right, y), Align2::RIGHT_CENTER, &reading, 17.0, Weight::Regular, ink);
@@ -1803,24 +1832,29 @@ impl Layers {
// what the layer is, under its name (which stays in the middle): a reference layer, one
// drawing assist is on for, a private one, a model's layer its texture set's meshes share
let tag = if l.reference && l.assisted {
- Some("Assisted Reference")
+ Some(tr("Assisted Reference"))
} else if l.reference && looks.shared {
- Some("Shared Reference")
+ Some(tr("Shared Reference"))
} else if l.reference {
- Some("Reference")
+ Some(tr("Reference layer"))
} else if looks.shared {
- Some("Shared")
+ Some(tr("Shared"))
} else if l.assisted {
- Some("Assisted")
+ Some(tr("Assisted"))
} else if l.private {
- Some("Private")
+ Some(tr("Private"))
} else {
None
};
self.name(ui, look, session, l, pos2(name_left, row.center().y), name_right, ink);
if let Some(tag) = tag {
let g = galley(ui, tag, 13.0, Weight::Regular, ink, name_right - name_left - 29.0);
- ui.painter().galley(pos2(name_left + 29.0, row.center().y + 17.5 - g.size().y / 2.0), g, ink);
+ crate::look::draw_layout(
+ ui.painter(),
+ pos2(name_left + 29.0, row.center().y + 17.5 - g.size().y / 2.0),
+ g,
+ ink,
+ );
}
if let Some((c, lit)) = cube {
look.icon(ui, &icons::TAB3_D, c.center(), 48.0, if lit { argb(pc::ACCENT) } else { ink });
@@ -2007,7 +2041,12 @@ impl Layers {
ink,
(row.right() - 96.0 * scale - name_left).max(1.0),
);
- mini.painter().galley(pos2(name_left + 29.0 * scale, row.center().y - name.size().y / 2.0), name, ink);
+ crate::look::draw_layout(
+ mini.painter(),
+ pos2(name_left + 29.0 * scale, row.center().y - name.size().y / 2.0),
+ name,
+ ink,
+ );
let right = row.right() - 8.0 * scale;
if !group && !mask {
let code = blend_code(&modes, l.blend);
@@ -2100,12 +2139,16 @@ impl Layers {
/// The +'s menu's rows: a plain layer, then each kind of layer, named as its plugin names it, beside
/// its badge (or a plug, when it draws none).
fn add_entries(kinds: &[procraft_core::PluginKind], filters: bool) -> Vec> {
- let mut entries = vec![Entry::Item(&icons::MENU_NEW_LAYER, "Layer", menu::INK)];
+ let mut entries = vec![Entry::Item(&icons::MENU_NEW_LAYER, procraft_core::message!("Layer"), menu::INK)];
let badged = |k: &procraft_core::PluginKind| procraft_core::plugin_kind_badge(k.clone());
entries.extend(kinds.iter().map(|k| Entry::Badge(badged(k), k.label.as_str(), menu::INK)));
// the filter layers the plugins offer, in a list of their own
if filters {
- entries.push(Entry::Badge(procraft_core::PluginBadge::filter(), "Filter Layer", menu::INK));
+ entries.push(Entry::Badge(
+ procraft_core::PluginBadge::filter(),
+ procraft_core::message!("Filter Layer"),
+ menu::INK,
+ ));
}
entries
}
@@ -2171,7 +2214,7 @@ fn set_header(ui: &mut Ui, name: &str, first: bool) {
let (row, _) = ui.allocate_exact_size(vec2(ui.available_width(), SET_HEADER), Sense::hover());
let ink = argb(PANEL_TITLE);
let g = galley(ui, name, 14.0, Weight::SemiBold, ink, row.width() - 32.0);
- ui.painter().galley(row.min + vec2(16.0, 12.0), g, ink);
+ crate::look::draw_layout(ui.painter(), row.min + vec2(16.0, 12.0), g, ink);
}
/// `texture` fitted in `rect`, centred.
@@ -2189,7 +2232,7 @@ fn locked_name(ui: &Ui, look: &mut Look, l: &LayerInfo, at: Pos2, right: f32, in
look.icon(ui, &icons::LOCK_ROW, pos2(at.x + 3.0 + 8.5, at.y), 17.0, ink);
}
let g = galley(ui, &l.name, 17.0, Weight::Regular, ink, (right - at.x - 29.0 - 6.0).max(10.0));
- ui.painter().galley(pos2(at.x + 29.0, at.y - g.size().y / 2.0), g, ink);
+ crate::look::draw_layout(ui.painter(), pos2(at.x + 29.0, at.y - g.size().y / 2.0), g, ink);
}
/// How a row looks: its corners (top, bottom), its fill, its thumbnail's version and whether its
@@ -2281,7 +2324,7 @@ fn blend_rows(ui: &Ui, look: &mut Look, list: Rect, modes: &[BlendModeInfo], scr
&painter,
pos2(row.left() + 12.0, row.center().y),
Align2::LEFT_CENTER,
- &m.name,
+ &m.label,
17.0,
Weight::Regular,
ink,
@@ -2310,8 +2353,8 @@ fn background_row(ui: &mut Ui, look: &mut Look, session: &CanvasSession) -> bool
ui.painter().rect_filled(swatch, 14, fill);
let ink = argb(PANEL_TITLE);
let visibility = Rect::from_min_size(pos2(row.right() - 8.0 - 44.0, row.center().y - 20.5), vec2(44.0, 41.0));
- let g = galley(ui, "Background color", 17.0, Weight::Regular, ink, visibility.left() - swatch.right() - 14.0);
- ui.painter().galley(pos2(swatch.right() + 14.0, row.center().y - g.size().y / 2.0), g, ink);
+ let g = galley(ui, tr("Background color"), 17.0, Weight::Regular, ink, visibility.left() - swatch.right() - 14.0);
+ crate::look::draw_layout(ui.painter(), pos2(swatch.right() + 14.0, row.center().y - g.size().y / 2.0), g, ink);
check_box(ui, look, visibility.center(), background.visible, argb(CHECK_FILL));
if ui.interact(visibility, ui.scope_id().with("background visible"), Sense::click()).clicked() {
session.set_background_visible(!background.visible);
@@ -2328,7 +2371,7 @@ fn action_row(ui: &mut Ui, label: &str) -> bool {
ui.painter().rect_filled(row, 17, argb(BACKGROUND_ROW));
let ink = argb(PANEL_TITLE);
let g = galley(ui, label, 17.0, Weight::Regular, ink, row.width() - 36.0);
- ui.painter().galley(pos2(row.left() + 18.0, row.center().y - g.size().y / 2.0), g, ink);
+ crate::look::draw_layout(ui.painter(), pos2(row.left() + 18.0, row.center().y - g.size().y / 2.0), g, ink);
response.clicked()
}
@@ -2400,14 +2443,7 @@ fn blend_code(modes: &[BlendModeInfo], blend: u32) -> String {
}
/// Text on one line, cut short with an ellipsis past `max_width`.
-fn galley(
- ui: &Ui,
- text: &str,
- size: f32,
- weight: Weight,
- colour: Color32,
- max_width: f32,
-) -> std::sync::Arc {
+fn galley(ui: &Ui, text: &str, size: f32, weight: Weight, colour: Color32, max_width: f32) -> crate::look::TextLayout {
let mut job = LayoutJob::default();
let format = TextFormat {
font_id: weight.font(size),
@@ -2417,7 +2453,7 @@ fn galley(
};
job.append(text, 0.0, format);
job.wrap = TextWrapping { max_width, max_rows: 1, break_anywhere: true, overflow_character: Some('…') };
- ui.painter().layout_job(job)
+ crate::look::layout_job(ui.painter(), job)
}
/// Two rows pinched to this share of how far apart they were merge (a pinch a third closed merges,
@@ -2921,14 +2957,22 @@ mod tests {
// with filter layers offered, Filter Layer last, beside the filter badge
let with_filters = add_entries(&kinds, true);
let filter = procraft_core::PluginBadge::filter();
- assert!(matches!(with_filters.last(), Some(Entry::Badge(b, "Filter Layer", _)) if *b == filter));
+ assert!(
+ matches!(with_filters.last(), Some(Entry::Badge(b, procraft_core::message!("Filter Layer"), _)) if *b == filter)
+ );
let entries = add_entries(&kinds, false);
assert_eq!(entries.len(), 3);
- let first = matches!(&entries[0], Entry::Item(icon, "Layer", _) if icon.name == "menunewlayer");
+ let first = matches!(&entries[0], Entry::Item(icon, procraft_core::message!("Layer"), _) if icon.name == "menunewlayer");
assert!(first, "a plain layer first, beside the new layer glyph");
- assert!(matches!(&entries[1], Entry::Badge(b, "Curves", _) if *b == badge), "a kind beside its badge");
+ assert!(
+ matches!(&entries[1], Entry::Badge(b, procraft_core::message!("Curves"), _) if *b == badge),
+ "a kind beside its badge"
+ );
let plug = procraft_core::PluginBadge::plug();
- assert!(matches!(&entries[2], Entry::Badge(b, "Plain", _) if *b == plug), "a plug when a kind draws none");
+ assert!(
+ matches!(&entries[2], Entry::Badge(b, procraft_core::message!("Plain"), _) if *b == plug),
+ "a plug when a kind draws none"
+ );
// drawn, a click on the last row picks it
let (ctx, mut look) = (egui::Context::default(), Look::default());
crate::look::install_fonts(&ctx);
diff --git a/desktop/src/library.rs b/desktop/src/library.rs
index 7fa46ae87..8892d2004 100644
--- a/desktop/src/library.rs
+++ b/desktop/src/library.rs
@@ -7,6 +7,8 @@
//! makes a brush or a set, or brings brushes in from a file. Two fingers pinched in on a library go
//! to every library's card, and pinched out on a card open it.
+use procraft_core::tr;
+
use std::collections::HashMap;
use std::sync::Arc;
use std::time::{Duration, Instant};
@@ -813,7 +815,7 @@ impl Library {
let name = libraries.get(place).map_or("Brush library", |l| l.name.as_str());
let renaming = !self.showing_libraries && self.renaming_library.as_ref().is_some_and(|r| r.0 == place);
let heading = match (self.showing_libraries, renaming) {
- (true, _) => "Brush libraries",
+ (true, _) => tr("Brush libraries"),
(false, true) => "",
(false, false) => name,
};
@@ -1050,7 +1052,7 @@ impl Library {
painter.rect_filled(at, 12, argb(pc::ACCENT).gamma_multiply(0.9));
self.preview_in(&painter, (b.set, b.index), at, true);
let name = one_line(ui, &b.name, 14.0, Weight::SemiBold, Color32::WHITE, at.width() - 28.0);
- painter.galley(at.min + vec2(18.0, 11.0), name, Color32::WHITE);
+ crate::look::draw_layout(&painter, at.min + vec2(18.0, 11.0), name, Color32::WHITE);
// several going together: how many
if self.dragged_with.len() > 1 {
let badge = pos2(at.right() - 20.0, at.top() + 20.0);
@@ -1082,7 +1084,12 @@ impl Library {
look.icon(ui, icon, pos2(at.left() + 24.0, at.center().y), 40.0, Color32::WHITE);
let left = at.left() + 4.0 + 40.0 + 1.0;
let name = one_line(ui, &set.name, 14.0, Weight::SemiBold, Color32::WHITE, at.right() - 8.0 - left);
- painter.galley(pos2(left, at.center().y - name.size().y / 2.0), name, Color32::WHITE);
+ crate::look::draw_layout(
+ &painter,
+ pos2(left, at.center().y - name.size().y / 2.0),
+ name,
+ Color32::WHITE,
+ );
ctx.request_repaint();
}
});
@@ -1152,7 +1159,7 @@ impl Library {
match chose {
Swiped::Share => {
if let Some(bytes) = session.brush_as_file(key.0, key.1) {
- crate::files::save_file(&bytes, &name, "brush", "Brush");
+ crate::files::save_file(&bytes, &name, "brush", tr("Brush"));
}
}
Swiped::Duplicate => {
@@ -1224,7 +1231,7 @@ impl Library {
let word = |ui: &Ui, text: &str, at: Rect, salt: &str| {
let galley = one_line(ui, text, 15.0, Weight::Regular, argb(SWIPE_INK), at.width());
let middle = at.center() - galley.size() / 2.0;
- ui.painter().galley(middle, galley, argb(SWIPE_INK));
+ crate::look::draw_layout(ui.painter(), middle, galley, argb(SWIPE_INK));
ui.interact(at, ui.scope_id().with(salt), Sense::click()).clicked()
};
let delete = Rect::from_min_size(pos2(right - 63.0, top), vec2(63.0, 32.0));
@@ -1251,13 +1258,13 @@ impl Library {
fn ask_delete(&mut self, what: Deleting) {
let title = match what {
- Deleting::Set(_) => "Delete this set and its brushes?",
- Deleting::Brush(..) => "Delete this brush?",
- Deleting::Picked => "Delete these brushes?",
- Deleting::Library(_) => "Delete this library?",
+ Deleting::Set(_) => tr("Delete this set and its brushes?"),
+ Deleting::Brush(..) => tr("Delete this brush?"),
+ Deleting::Picked => tr("Delete these brushes?"),
+ Deleting::Library(_) => tr("Delete this library?"),
};
self.delete_what = Some(what);
- self.deleting.open(title, "It can't be brought back.", "Delete", Some(&icons::TRASH));
+ self.deleting.open(title, tr("It can't be brought back."), tr("Delete"), Some(&icons::TRASH));
}
/// The plus's menu, hanging below it, their right edges in line: a new brush, a new set, or
@@ -1275,10 +1282,10 @@ impl Library {
let ink = menu::INK;
// the Recent set holds no brushes of its own to add one to
let mut entries = vec![
- Entry::Item(&icons::MENU_NEW_BRUSH, "Create new brush", ink),
- Entry::Item(&icons::MENU_NEW_SET, "Create new set", ink),
+ Entry::Item(&icons::MENU_NEW_BRUSH, procraft_core::message!("Create new brush"), ink),
+ Entry::Item(&icons::MENU_NEW_SET, procraft_core::message!("Create new set"), ink),
Entry::Rule(11.0),
- Entry::Item(&icons::MENU_FOLDER, "Import from Files", ink),
+ Entry::Item(&icons::MENU_FOLDER, procraft_core::message!("Import from Files"), ink),
];
if self.recent {
entries.remove(0);
@@ -1309,7 +1316,7 @@ impl Library {
self.library_changed();
}
_ => {
- let Some((path, name)) = crate::files::pick_path("Import brushes") else { return };
+ let Some((path, name)) = crate::files::pick_path(tr("Import brushes")) else { return };
self.shown_set = Some(shown);
self.picked_file = Some((path, name, false));
}
@@ -1332,14 +1339,14 @@ impl Library {
let own = library.get(i).map_or(0, |s| s.icon as usize);
let set_icon = icons::SET_ICONS.get(own).unwrap_or(&icons::BRUSH_SET);
let entries = [
- Entry::Item(&icons::MENU_RENAME, "Rename", ink),
- Entry::Item(&icons::MENU_DUPLICATE, "Duplicate", ink),
- Entry::More(set_icon, "Customize icon", ink),
+ Entry::Item(&icons::MENU_RENAME, procraft_core::message!("Rename"), ink),
+ Entry::Item(&icons::MENU_DUPLICATE, procraft_core::message!("Duplicate"), ink),
+ Entry::More(set_icon, procraft_core::message!("Customize icon"), ink),
menu::DIVIDER,
- Entry::Item(&icons::MENU_SHARE, "Share", ink),
+ Entry::Item(&icons::MENU_SHARE, procraft_core::message!("Share"), ink),
// the only set too: the library is then left with none
menu::DIVIDER,
- Entry::Item(&icons::MENU_TRASH, "Delete", menu::DANGER),
+ Entry::Item(&icons::MENU_TRASH, procraft_core::message!("Delete"), menu::DANGER),
];
let size = vec2(menu::LIBRARY_WIDTH, menu::entries_height(&entries));
let screen = panel::screen(ctx);
@@ -1401,7 +1408,7 @@ impl Library {
"Share" => {
let name = library.get(i).map_or("Brushes", |s| s.name.as_str());
if let Some(bytes) = session.brush_set_as_file(i as u32) {
- crate::files::save_file(&bytes, name, "brushset", "Brush set");
+ crate::files::save_file(&bytes, name, "brushset", tr("Brush set"));
}
}
_ => self.ask_delete(Deleting::Set(i as u32)),
@@ -1419,24 +1426,28 @@ impl Library {
let ink = menu::INK;
let mut entries = match pinned {
Some(pinned) => vec![
- Entry::Item(&icons::SWIPE_FIND, "Find", ink),
+ Entry::Item(&icons::SWIPE_FIND, procraft_core::message!("Find"), ink),
if pinned {
- Entry::Item(&icons::SWIPE_UNPIN, "Unpin", ink)
+ Entry::Item(&icons::SWIPE_UNPIN, procraft_core::message!("Unpin"), ink)
} else {
- Entry::Item(&icons::SWIPE_PIN, "Pin", ink)
+ Entry::Item(&icons::SWIPE_PIN, procraft_core::message!("Pin"), ink)
},
],
None => {
vec![
- Entry::Item(&icons::MENU_RENAME, "Rename", ink),
- Entry::Item(&icons::MENU_DUPLICATE, "Duplicate", ink),
+ Entry::Item(&icons::MENU_RENAME, procraft_core::message!("Rename"), ink),
+ Entry::Item(&icons::MENU_DUPLICATE, procraft_core::message!("Duplicate"), ink),
]
}
};
- entries.extend([menu::DIVIDER, Entry::Item(&icons::MENU_SHARE, "Share", ink), menu::DIVIDER]);
+ entries.extend([
+ menu::DIVIDER,
+ Entry::Item(&icons::MENU_SHARE, procraft_core::message!("Share"), ink),
+ menu::DIVIDER,
+ ]);
entries.push(match pinned {
- Some(_) => Entry::Item(&icons::MENU_CLEAR, "Clear", ink),
- None => Entry::Item(&icons::MENU_TRASH, "Delete", menu::DANGER),
+ Some(_) => Entry::Item(&icons::MENU_CLEAR, procraft_core::message!("Clear"), ink),
+ None => Entry::Item(&icons::MENU_TRASH, procraft_core::message!("Delete"), menu::DANGER),
});
let size = vec2(menu::LIBRARY_WIDTH, menu::entries_height(&entries));
let screen = panel::screen(ctx);
@@ -1463,7 +1474,7 @@ impl Library {
}
"Share" => {
if let Some(bytes) = session.brush_as_file(key.0, key.1) {
- crate::files::save_file(&bytes, &name, "brush", "Brush");
+ crate::files::save_file(&bytes, &name, "brush", tr("Brush"));
}
}
"Delete" => self.ask_delete(Deleting::Brush(key.0, key.1)),
@@ -1489,7 +1500,7 @@ impl Library {
row: Rect,
backdrops: &mut Vec,
) {
- let entries = [Entry::Item(&icons::MENU_CLEAR, "Clear", menu::INK)];
+ let entries = [Entry::Item(&icons::MENU_CLEAR, procraft_core::message!("Clear"), menu::INK)];
let size = vec2(menu::LIBRARY_WIDTH, menu::entries_height(&entries) + RECENT_MENU_EXTRA);
let screen = panel::screen(ctx);
let top = (row.center().y - size.y / 2.0)
@@ -1775,7 +1786,7 @@ impl Library {
look.icon(ui, &icons::RECENT_SET, pos2(rect.left() + 24.0, rect.center().y), 40.0, ink);
let name = one_line(ui, "Recent", 14.0, Weight::SemiBold, ink, rect.width() - 53.0);
let left = rect.left() + 4.0 + 40.0 + 1.0;
- ui.painter().galley(pos2(left, rect.center().y - name.size().y / 2.0), name, ink);
+ crate::look::draw_layout(ui.painter(), pos2(left, rect.center().y - name.size().y / 2.0), name, ink);
(response, rect)
}
@@ -1837,9 +1848,9 @@ impl Library {
break_anywhere: false,
overflow_character: Some('…'),
};
- let galley = ui.painter().layout_job(job);
+ let galley = crate::look::layout_job(ui.painter(), job);
let at = Align2::LEFT_CENTER.anchor_size(pos2(left, rect.center().y), galley.size());
- ui.painter().galley(at.min, galley, ink);
+ crate::look::draw_layout(ui.painter(), at.min, galley, ink);
(response, rect)
}
@@ -1913,7 +1924,7 @@ impl Library {
let pill = Rect::from_min_size(name_at, galley.size()).expand2(vec2(6.0, 2.0));
painter.rect_filled(pill, pill.height() / 2.0, argb(NAME_PILL).gamma_multiply(alpha));
}
- painter.galley(name_at, galley, ink);
+ crate::look::draw_layout(&painter, name_at, galley, ink);
}
if response.secondary_clicked() {
self.swiped = None;
@@ -2094,7 +2105,7 @@ impl Library {
pos2(clear.map_or(field.right() - 8.0, |r| r.left() - 6.0), field.bottom()),
);
if self.query.is_empty() {
- text(&painter, words.left_center(), Align2::LEFT_CENTER, "Search", 17.0, Weight::Regular, hint);
+ text(&painter, words.left_center(), Align2::LEFT_CENTER, tr("Search"), 17.0, Weight::Regular, hint);
}
let edit = egui::TextEdit::singleline(&mut self.query)
.frame(egui::Frame::NONE)
@@ -2140,7 +2151,7 @@ impl Library {
};
if found.is_empty() {
let at = pos2(area.center().x, area.top() + 24.0);
- text(ui.painter(), at, Align2::CENTER_TOP, "No results", 15.0, Weight::Medium, argb(PANEL_TITLE));
+ text(ui.painter(), at, Align2::CENTER_TOP, tr("No results"), 15.0, Weight::Medium, argb(PANEL_TITLE));
return None;
}
let mut tapped = None;
@@ -2173,7 +2184,7 @@ impl Library {
let pill = Rect::from_min_size(name_at, galley.size()).expand2(vec2(6.0, 2.0));
painter.rect_filled(pill, pill.height() / 2.0, argb(NAME_PILL));
}
- painter.galley(name_at, galley, ink);
+ crate::look::draw_layout(&painter, name_at, galley, ink);
if ui.interact(tile, ui.scope_id().with(("result", key)), Sense::click()).clicked() {
tapped = Some(key);
}
@@ -2309,11 +2320,18 @@ fn format(size: f32, weight: Weight, colour: Color32) -> TextFormat {
}
/// Text on one line, cut short with an ellipsis past `max_width`.
-fn one_line(ui: &Ui, text: &str, size: f32, weight: Weight, colour: Color32, max_width: f32) -> Arc {
+fn one_line(
+ ui: &Ui,
+ text: &str,
+ size: f32,
+ weight: Weight,
+ colour: Color32,
+ max_width: f32,
+) -> crate::look::TextLayout {
let mut job = LayoutJob::default();
job.append(text, 0.0, format(size, weight, colour));
job.wrap = TextWrapping { max_width, max_rows: 1, break_anywhere: true, overflow_character: Some('…') };
- ui.painter().layout_job(job)
+ crate::look::layout_job(ui.painter(), job)
}
/// Whether a sample stroke (`PREVIEW` big, premultiplied RGBA) runs under its name: the name's box
diff --git a/desktop/src/library/libraries.rs b/desktop/src/library/libraries.rs
index ba7e1a1e7..f9222202c 100644
--- a/desktop/src/library/libraries.rs
+++ b/desktop/src/library/libraries.rs
@@ -1,6 +1,8 @@
//! The brush libraries in the library panel: the title's menu, every library's card and its
//! menu, and a library with no sets yet.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use std::sync::Arc;
@@ -104,7 +106,7 @@ impl Library {
ui.painter(),
middle,
Align2::CENTER_TOP,
- "This library has no brushes yet",
+ tr("This library has no brushes yet"),
17.0,
Weight::SemiBold,
argb(PANEL_TITLE),
@@ -113,7 +115,7 @@ impl Library {
ui.painter(),
middle + vec2(0.0, 30.0),
Align2::CENTER_TOP,
- "Make a set with +, then brushes in it.",
+ tr("Make a set with +, then brushes in it."),
14.0,
Weight::Regular,
argb(PANEL_GLYPH),
@@ -197,7 +199,7 @@ impl Library {
let name_at = Rect::from_min_size(card.min + vec2(10.0, 10.0), vec2(card.width() - 20.0, 18.0));
if !self.rename_field(ui, session, i, name_at, 14.0) {
let name = one_line(ui, &library.name, 14.0, Weight::SemiBold, argb(PANEL_TITLE), name_at.width());
- painter.galley(name_at.min, name, argb(PANEL_TITLE));
+ crate::look::draw_layout(&painter, name_at.min, name, argb(PANEL_TITLE));
}
// the one in use's shown set; another's first with a brush chosen in it
let chosen =
@@ -215,7 +217,12 @@ impl Library {
let icon = icons::SET_ICONS.get(set.icon as usize).unwrap_or(&icons::BRUSH_SET);
look.icon(ui, icon, pos2(row.left() + 10.0, row.center().y), 18.0, ink);
let name = one_line(ui, &set.name, 8.0, Weight::Regular, ink, row.width() - 22.0);
- painter.galley(pos2(row.left() + 20.0, row.center().y - name.size().y / 2.0), name, ink);
+ crate::look::draw_layout(
+ &painter,
+ pos2(row.left() + 20.0, row.center().y - name.size().y / 2.0),
+ name,
+ ink,
+ );
y += CARD_SET_ROW + CARD_SET_GAP;
}
let left = card.left() + 10.0 + sets_width + 6.0;
@@ -236,7 +243,7 @@ impl Library {
painter.image(stroke.id(), row, uv, self.tint(false));
}
let name = one_line(ui, &b.name, 8.0, Weight::Regular, argb(PANEL_TITLE), width - 4.0);
- painter.galley(row.min + vec2(3.0, 1.0), name, argb(PANEL_TITLE));
+ crate::look::draw_layout(&painter, row.min + vec2(3.0, 1.0), name, argb(PANEL_TITLE));
y += CARD_BRUSH + 2.0;
}
}
@@ -284,13 +291,13 @@ impl Library {
) {
let ink = menu::INK;
let entries: Vec = if self.showing_libraries {
- vec![Entry::Item(&icons::MENU_RESTORE, "Restore default library", ink)]
+ vec![Entry::Item(&icons::MENU_RESTORE, procraft_core::message!("Restore default library"), ink)]
} else {
vec![
- Entry::Item(&icons::MENU_RENAME, "Rename", ink),
- Entry::Item(&icons::MENU_SHARE, "Share", ink),
+ Entry::Item(&icons::MENU_RENAME, procraft_core::message!("Rename"), ink),
+ Entry::Item(&icons::MENU_SHARE, procraft_core::message!("Share"), ink),
Entry::Rule(11.0),
- Entry::Item(&icons::MENU_LIBRARIES, "Back to libraries", ink),
+ Entry::Item(&icons::MENU_LIBRARIES, procraft_core::message!("Back to libraries"), ink),
]
};
let size = vec2(menu::LIBRARY_WIDTH, menu::entries_height(&entries));
@@ -310,8 +317,8 @@ impl Library {
"Share" => {
let name = libraries.iter().find(|l| l.current).map_or("Brushes", |l| l.name.as_str());
match session.brush_library_as_file() {
- Some(bytes) => crate::files::save_file(&bytes, name, "brushlibrary", "Brush library"),
- None => crate::files::say("This library has no brushes to share."),
+ Some(bytes) => crate::files::save_file(&bytes, name, "brushlibrary", tr("Brush library")),
+ None => crate::files::say(tr("This library has no brushes to share.")),
}
}
"Back to libraries" => self.showing_libraries = true,
@@ -334,8 +341,8 @@ impl Library {
backdrops: &mut Vec,
) {
let entries = [
- Entry::Item(&icons::MENU_NEW_LIBRARY, "Create new library", menu::INK),
- Entry::Item(&icons::MENU_FOLDER, "Import from Files", menu::INK),
+ Entry::Item(&icons::MENU_NEW_LIBRARY, procraft_core::message!("Create new library"), menu::INK),
+ Entry::Item(&icons::MENU_FOLDER, procraft_core::message!("Import from Files"), menu::INK),
];
let size = vec2(menu::LIBRARY_WIDTH, menu::entries_height(&entries));
let rect = Rect::from_min_size(pos2(plus.right() - size.x, plus.bottom()), size);
@@ -358,7 +365,7 @@ impl Library {
if session.new_brush_library().is_none() {
log::error!("a new brush library couldn't be made");
}
- } else if let Some((path, name)) = crate::files::pick_path("Import a brush library") {
+ } else if let Some((path, name)) = crate::files::pick_path(tr("Import a brush library")) {
// read on a thread of its own (with the import card, which the app shows), then added
// as a library and brought into use
self.picked_file = Some((path, name, true));
@@ -378,12 +385,12 @@ impl Library {
let Some(card) = self.card_rects.iter().find(|(c, _)| *c == i).map(|(_, r)| *r) else { return };
let ink = menu::INK;
let mut entries = vec![
- Entry::Item(&icons::MENU_RENAME, "Rename", ink),
- Entry::Item(&icons::MENU_DUPLICATE, "Duplicate", ink),
+ Entry::Item(&icons::MENU_RENAME, procraft_core::message!("Rename"), ink),
+ Entry::Item(&icons::MENU_DUPLICATE, procraft_core::message!("Duplicate"), ink),
];
if libraries.len() > 1 {
entries.push(menu::DIVIDER);
- entries.push(Entry::Item(&icons::MENU_TRASH, "Delete", menu::DANGER));
+ entries.push(Entry::Item(&icons::MENU_TRASH, procraft_core::message!("Delete"), menu::DANGER));
}
let size = vec2(menu::LIBRARY_WIDTH, menu::entries_height(&entries));
let rect = Rect::from_min_size(pos2(card.center().x - size.x / 2.0, card.top() + card.height() / 4.0), size);
@@ -407,9 +414,9 @@ impl Library {
_ => {
self.delete_what = Some(Deleting::Library(i as u32));
self.deleting.open(
- "Delete this library?",
- "Its sets and brushes go with it.",
- "Delete",
+ tr("Delete this library?"),
+ tr("Its sets and brushes go with it."),
+ tr("Delete"),
Some(&icons::TRASH),
);
}
diff --git a/desktop/src/licences.rs b/desktop/src/licences.rs
index 8036fd493..95f5f1607 100644
--- a/desktop/src/licences.rs
+++ b/desktop/src/licences.rs
@@ -4,6 +4,8 @@
//! third-party crates (Android's does), so they follow here (desktop/licenses.txt, written by
//! tools/licenses.py).
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use std::sync::{Arc, OnceLock};
@@ -77,8 +79,8 @@ fn offsets(ui: &Ui, width: f32) -> Arc<(Vec, f32)> {
offsets
}
-fn galley(ui: &Ui, paragraph: &str, width: f32) -> Arc {
- ui.painter().layout(paragraph.to_owned(), Weight::Regular.font(14.0), argb(INK), width)
+fn galley(ui: &Ui, paragraph: &str, width: f32) -> crate::look::TextLayout {
+ crate::look::layout(ui.painter(), paragraph.to_owned(), Weight::Regular.font(14.0), argb(INK), width)
}
/// Shows the licences; true once closed.
@@ -97,7 +99,7 @@ pub fn show(ctx: &egui::Context) -> bool {
ui.painter().rect_filled(panel, 28, argb(FILL));
ui.painter().rect_stroke(panel, 28, Stroke::new(1.0, argb(EDGE)), StrokeKind::Inside);
let title = pos2(panel.left() + 24.0, panel.top() + 24.0);
- text(ui.painter(), title, Align2::LEFT_TOP, "Licences", 24.0, Weight::Bold, argb(TITLE));
+ text(ui.painter(), title, Align2::LEFT_TOP, tr("Licences"), 24.0, Weight::Bold, argb(TITLE));
let body = Rect::from_min_max(
pos2(panel.left() + 24.0, panel.top() + 24.0 + 32.0 + 16.0),
pos2(panel.right() - 24.0, panel.bottom() - 16.0 - 40.0 - 16.0),
@@ -111,13 +113,18 @@ pub fn show(ctx: &egui::Context) -> bool {
if *y > viewport.bottom() {
break;
}
- ui.painter().galley(rect.min + vec2(0.0, *y), galley(ui, paragraph, body.width()), argb(INK));
+ crate::look::draw_layout(
+ ui.painter(),
+ rect.min + vec2(0.0, *y),
+ galley(ui, paragraph, body.width()),
+ argb(INK),
+ );
}
});
});
let done =
Rect::from_min_size(pos2(panel.right() - 24.0 - 80.0, panel.bottom() - 16.0 - 40.0), vec2(80.0, 40.0));
- text(ui.painter(), done.center(), Align2::CENTER_CENTER, "Done", 16.0, Weight::Medium, argb(pc::ACCENT));
+ text(ui.painter(), done.center(), Align2::CENTER_CENTER, tr("Done"), 16.0, Weight::Medium, argb(pc::ACCENT));
close |= ui.interact(done, ui.scope_id().with("done"), Sense::click()).clicked();
});
close
diff --git a/desktop/src/lighting.rs b/desktop/src/lighting.rs
index e158b3d69..c3b104f8d 100644
--- a/desktop/src/lighting.rs
+++ b/desktop/src/lighting.rs
@@ -5,6 +5,8 @@
//! environment shows, the exposure, and which environment lights the model. Also the environments
//! themselves (our own panoramas, bundled with the Android app) a model is lit by.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use egui::{Align2, Color32, Id, Order, Pos2, Rect, Sense, Stroke, Ui, UiBuilder, pos2, vec2};
use procraft_core::{CanvasSession, ModelLight};
@@ -43,7 +45,7 @@ const SLOP: f32 = 8.0;
pub const DEFAULT_ENVIRONMENT: &str = "mountain";
macro_rules! environment {
- ($label:literal, $asset:literal, $icon:path) => {
+ ($label:expr, $asset:literal, $icon:path) => {
(
$label,
$asset,
@@ -55,17 +57,17 @@ macro_rules! environment {
/// The environments as the studio lists them: their names, assets, pictures and panoramas.
const ENVIRONMENTS: [(&str, &str, &Icon, &[u8]); 11] = [
- environment!("Studio", "studio", icons::ENV_STUDIO),
- environment!("Coast", "coast", icons::ENV_COAST),
- environment!("Auditorium", "auditorium", icons::ENV_AUDITORIUM),
- environment!("City", "city", icons::ENV_CITY),
- environment!("Nightlife", "nightlife", icons::ENV_NIGHTLIFE),
- environment!("Portside", "portside", icons::ENV_PORTSIDE),
- environment!("Industrial", "industrial", icons::ENV_INDUSTRIAL),
- environment!("Sunrise", "sunrise", icons::ENV_SUNRISE),
- environment!("Beach", "beach", icons::ENV_BEACH),
- environment!("Mountain", "mountain", icons::ENV_MOUNTAIN),
- environment!("Daytime", "daytime", icons::ENV_DAYTIME),
+ environment!(procraft_core::message!("Studio"), "studio", icons::ENV_STUDIO),
+ environment!(procraft_core::message!("Coast"), "coast", icons::ENV_COAST),
+ environment!(procraft_core::message!("Auditorium"), "auditorium", icons::ENV_AUDITORIUM),
+ environment!(procraft_core::message!("City"), "city", icons::ENV_CITY),
+ environment!(procraft_core::message!("Nightlife"), "nightlife", icons::ENV_NIGHTLIFE),
+ environment!(procraft_core::message!("Portside"), "portside", icons::ENV_PORTSIDE),
+ environment!(procraft_core::message!("Industrial"), "industrial", icons::ENV_INDUSTRIAL),
+ environment!(procraft_core::message!("Sunrise"), "sunrise", icons::ENV_SUNRISE),
+ environment!(procraft_core::message!("Beach"), "beach", icons::ENV_BEACH),
+ environment!(procraft_core::message!("Mountain"), "mountain", icons::ENV_MOUNTAIN),
+ environment!(procraft_core::message!("Daytime"), "daytime", icons::ENV_DAYTIME),
];
/// Lights the model by environment `name`; false if there's no such one.
@@ -119,9 +121,9 @@ fn hue_colour(t: f32) -> Color32 {
/// A share as a light's sliders show it: None, a percentage, or Max.
fn level(v: f32) -> String {
if v <= 0.0 {
- "None".into()
+ tr("None").into()
} else if v >= 1.0 {
- "Max".into()
+ tr("Max").into()
} else {
format!("{}%", (v * 100.0).round())
}
@@ -235,7 +237,7 @@ impl LightingStudio {
ui.painter(),
bar.min + vec2(32.0, 27.0),
Align2::LEFT_TOP,
- "Lighting Studio",
+ tr("Lighting Studio"),
20.0,
Weight::Bold,
argb(STUDIO_TITLE),
@@ -247,7 +249,10 @@ impl LightingStudio {
ui.painter().rect_filled(pill, 21.5, argb(PILL_FILL));
ui.painter().rect_stroke(pill, 21.5, Stroke::new(1.0, argb(PILL_EDGE)), egui::StrokeKind::Inside);
let mut x = pill.left();
- for (label, width) in [("Cancel", 73.0), ("Add Light", 92.0), ("Environment", 113.0)] {
+ use procraft_core::message;
+ for (label, width) in
+ [(message!("Cancel"), 73.0), (message!("Add Light"), 92.0), (message!("Environment"), 113.0)]
+ {
let cell = Rect::from_min_size(pos2(x, pill.top()), vec2(width, 43.0));
x += width;
if label == "Environment" && self.environment_open {
@@ -257,7 +262,7 @@ impl LightingStudio {
ui.painter(),
cell.center(),
Align2::CENTER_CENTER,
- label,
+ tr(label),
17.0,
Weight::Regular,
argb(PILL_INK),
@@ -269,7 +274,7 @@ impl LightingStudio {
self.environment_open = false;
self.light_open = None;
if !session.add_model_light() {
- said = Some("A model can have four lights at most.");
+ said = Some(tr("A model can have four lights at most."));
}
}
_ => self.environment_open = !self.environment_open,
@@ -335,7 +340,7 @@ impl LightingStudio {
ui.painter(),
rect.min + vec2(26.0, 8.0 + 20.0),
Align2::LEFT_CENTER,
- "Environment",
+ tr("Environment"),
24.0,
Weight::Bold,
argb(PANEL_TITLE),
@@ -349,7 +354,7 @@ impl LightingStudio {
ui.painter(),
pos2(row.left() + 16.0, row.center().y),
Align2::LEFT_CENTER,
- "Show Environment",
+ tr("Show Environment"),
17.0,
Weight::Regular,
argb(LABEL_INK),
@@ -404,7 +409,7 @@ impl LightingStudio {
ui.painter(),
pos2(cell.left() + 11.0, cell.center().y),
Align2::LEFT_CENTER,
- label,
+ tr(label),
16.0,
Weight::Regular,
ink,
@@ -457,7 +462,7 @@ impl LightingStudio {
ui.painter(),
body.min + vec2(16.0, 5.0 + 20.0),
Align2::LEFT_CENTER,
- "Light Settings",
+ tr("Light Settings"),
24.0,
Weight::Bold,
argb(PANEL_TITLE),
@@ -472,21 +477,21 @@ impl LightingStudio {
let degrees = if light.hue >= 1.0 { 360.0 } else { egui::ecolor::Hsva::from(hue).h * 360.0 };
let rows: [(&str, String, f32, [Color32; 2], Color32); 3] = [
(
- "Hue",
- if light.saturation <= 0.0 { "None".into() } else { format!("{}°", degrees.round()) },
+ tr("Hue"),
+ if light.saturation <= 0.0 { tr("None").into() } else { format!("{}°", degrees.round()) },
light.hue,
[Color32::TRANSPARENT; 2],
hue,
),
(
- "Saturation",
+ tr("Saturation"),
level(light.saturation),
light.saturation,
[argb(SATURATION_START), hue],
crate::look::mix(argb(SATURATION_START), hue, light.saturation),
),
(
- "Intensity",
+ tr("Intensity"),
level(light.intensity),
light.intensity,
[Color32::BLACK, Color32::WHITE],
@@ -581,7 +586,7 @@ impl LightingStudio {
if k == 0 {
session.delete_model_light(index);
} else if !session.duplicate_model_light(index) {
- said = Some("A model can have four lights at most.");
+ said = Some(tr("A model can have four lights at most."));
}
self.light_open = None;
}
@@ -610,14 +615,22 @@ fn gradient(ui: &Ui, rect: Rect, a: Color32, b: Color32) {
fn exposure_slider(ui: &Ui, session: &CanvasSession, rect: Rect, held: &mut Option<(Id, f32)>) {
let value = session.model_exposure();
let shown = if value <= 0.0 {
- "Min".to_owned()
+ tr("Min").to_owned()
} else if value >= MOST_EXPOSURE {
- "Max".to_owned()
+ tr("Max").to_owned()
} else {
format!("{}%", (value * 100.0).round())
};
ui.painter().rect_filled(rect, 14, argb(GROUP_FILL));
- text(ui.painter(), rect.min + vec2(16.0, 19.0), Align2::LEFT_TOP, "Exposure", 17.0, Weight::Regular, argb(DIM_INK));
+ text(
+ ui.painter(),
+ rect.min + vec2(16.0, 19.0),
+ Align2::LEFT_TOP,
+ tr("Exposure"),
+ 17.0,
+ Weight::Regular,
+ argb(DIM_INK),
+ );
text(
ui.painter(),
pos2(rect.right() - 16.0, rect.top() + 19.0),
diff --git a/desktop/src/liquify.rs b/desktop/src/liquify.rs
index 04b03f97b..e67bd34b5 100644
--- a/desktop/src/liquify.rs
+++ b/desktop/src/liquify.rs
@@ -4,6 +4,8 @@
//! sliders over the way (its list in a popover), Adjust and Reset. Adjust's popover takes back
//! some of what it did. The touches liquify (touch.rs); the values are the core's (adjusting.rs).
+use procraft_core::tr;
+
use egui::{Align2, Color32, Id, Order, Rect, Sense, Ui, pos2, vec2};
use procraft_core::{AdjustShown, CanvasSession, LiquifyKind};
@@ -24,22 +26,26 @@ const WIDE: (f32, f32) = (1093.0, 162.0);
const UPRIGHT: (f32, f32) = (654.0, 200.0);
const KINDS: [(LiquifyKind, &str, &Icon); 8] = [
- (LiquifyKind::Push, "Push", &icons::LIQUIFY_PUSH),
- (LiquifyKind::TwirlRight, "Twirl Right", &icons::LIQUIFY_TWIRL_RIGHT),
- (LiquifyKind::TwirlLeft, "Twirl Left", &icons::LIQUIFY_TWIRL_LEFT),
- (LiquifyKind::Pinch, "Pinch", &icons::LIQUIFY_PINCH),
- (LiquifyKind::Expand, "Expand", &icons::LIQUIFY_EXPAND),
- (LiquifyKind::Crystals, "Crystals", &icons::LIQUIFY_CRYSTALS),
- (LiquifyKind::Edge, "Edge", &icons::LIQUIFY_EDGE),
- (LiquifyKind::Reconstruct, "Reconstruct", &icons::LIQUIFY_RECONSTRUCT),
+ (LiquifyKind::Push, procraft_core::message!("Push"), &icons::LIQUIFY_PUSH),
+ (LiquifyKind::TwirlRight, procraft_core::message!("Twirl Right"), &icons::LIQUIFY_TWIRL_RIGHT),
+ (LiquifyKind::TwirlLeft, procraft_core::message!("Twirl Left"), &icons::LIQUIFY_TWIRL_LEFT),
+ (LiquifyKind::Pinch, procraft_core::message!("Pinch"), &icons::LIQUIFY_PINCH),
+ (LiquifyKind::Expand, procraft_core::message!("Expand"), &icons::LIQUIFY_EXPAND),
+ (LiquifyKind::Crystals, procraft_core::message!("Crystals"), &icons::LIQUIFY_CRYSTALS),
+ (LiquifyKind::Edge, procraft_core::message!("Edge"), &icons::LIQUIFY_EDGE),
+ (LiquifyKind::Reconstruct, procraft_core::message!("Reconstruct"), &icons::LIQUIFY_RECONSTRUCT),
+];
+const SLIDERS: [(&str, Option<&str>); 4] = [
+ (procraft_core::message!("Size"), None),
+ (procraft_core::message!("Pressure"), None),
+ (procraft_core::message!("Distortion"), Some(procraft_core::message!("None"))),
+ (procraft_core::message!("Momentum"), Some(procraft_core::message!("None"))),
];
-const SLIDERS: [(&str, Option<&str>); 4] =
- [("Size", None), ("Pressure", None), ("Distortion", Some("None")), ("Momentum", Some("None"))];
/// A slider's value as shown: Max at all, `none` (if any) at nothing, else a percentage.
fn percent(v: f32, none: Option<&str>) -> String {
if v >= 1.0 {
- "Max".into()
+ tr("Max").into()
} else if let (true, Some(none)) = (v <= 0.0, none) {
none.into()
} else {
@@ -106,16 +112,27 @@ impl Liquify {
let top = rect.top() + 28.0;
for (k, &(kind, label, glyph)) in KINDS.iter().enumerate() {
let ink = if shown.liquify_kind == kind { pc::ACCENT.into() } else { IDLE };
- if button(ui, look, pos2(left + 94.0 * k as f32, top), glyph, label, ink, LABEL, 24.0, true) {
+ if button(ui, look, pos2(left + 94.0 * k as f32, top), glyph, tr(label), ink, LABEL, 24.0, true) {
session.adjustment_liquify_kind(kind);
self.popup = Popup::None;
}
}
let (ink, words) = if can_adjust { (IDLE, LABEL) } else { (DIM, DIM) };
- if button(ui, look, pos2(left + 94.0 * 8.0, top), &icons::ADJUST_KNOB, "Adjust", ink, words, 39.5, can_adjust) {
+ if button(
+ ui,
+ look,
+ pos2(left + 94.0 * 8.0, top),
+ &icons::ADJUST_KNOB,
+ tr("Adjust"),
+ ink,
+ words,
+ 39.5,
+ can_adjust,
+ ) {
self.popup = if self.popup == Popup::Adjust { Popup::None } else { Popup::Adjust };
}
- if button(ui, look, pos2(left + 94.0 * 9.0, top), &icons::PIE_RESET, "Reset", ink, words, 23.0, can_adjust) {
+ if button(ui, look, pos2(left + 94.0 * 9.0, top), &icons::PIE_RESET, tr("Reset"), ink, words, 23.0, can_adjust)
+ {
session.adjustment_liquify_reset();
self.popup = Popup::None;
}
@@ -126,7 +143,7 @@ impl Liquify {
vec2(each, 59.0),
);
let v = shown.liquify.get(i).copied().unwrap_or(0.0);
- if let Some(v) = menu_slider(ui, row, label, v, &percent(v, *none)) {
+ if let Some(v) = menu_slider(ui, row, tr(label), v, &percent(v, none.map(tr))) {
session.adjustment_liquify_value(i as u32, v);
}
}
@@ -141,7 +158,7 @@ impl Liquify {
let top = inner.top() + row as f32 * (59.0 + 5.0);
let r = Rect::from_min_size(pos2(inner.left() + col as f32 * (each + 20.0), top), vec2(each, 59.0));
let v = shown.liquify.get(i).copied().unwrap_or(0.0);
- if let Some(v) = menu_slider(ui, r, label, v, &percent(v, *none)) {
+ if let Some(v) = menu_slider(ui, r, tr(label), v, &percent(v, none.map(tr))) {
session.adjustment_liquify_value(i as u32, v);
}
}
@@ -149,7 +166,7 @@ impl Liquify {
let cell =
|k: f32| Rect::from_min_size(pos2(inner.left() + k * (w + 8.0), inner.bottom() - 40.0), vec2(w, 40.0));
let can_adjust = shown.liquified;
- let name = KINDS.iter().find(|k| k.0 == shown.liquify_kind).map_or("", |k| k.1);
+ let name = KINDS.iter().find(|k| k.0 == shown.liquify_kind).map_or("", |k| tr(k.1));
let way = cell(0.0);
ui.painter().rect_filled(way, 20, argb(PANEL_BUTTON));
text(ui.painter(), way.center(), Align2::CENTER_CENTER, name, 15.0, Weight::Regular, argb(MENU_TEXT));
@@ -159,11 +176,12 @@ impl Liquify {
let fill = if can_adjust { argb(PANEL_BUTTON) } else { argb(PANEL_BUTTON).gamma_multiply(0.5) };
let tint = if can_adjust { argb(MENU_TEXT) } else { argb(DIM) };
for (k, glyph, size, gap, label) in
- [(1.0, &icons::ADJUST_KNOB, 39.5, 2.0, "Adjust"), (2.0, &icons::PIE_RESET, 23.0, 2.5, "Reset")]
+ [(1.0, &icons::ADJUST_KNOB, 39.5, 2.0, tr("Adjust")), (2.0, &icons::PIE_RESET, 23.0, 2.5, tr("Reset"))]
{
let b = cell(k);
ui.painter().rect_filled(b, 20, fill);
- let words = ui.painter().layout_no_wrap(label.into(), Weight::Regular.font(15.0), tint).size().x;
+ let words =
+ crate::look::layout_no_wrap(ui.painter(), label.into(), Weight::Regular.font(15.0), tint).size().x;
let left = b.center().x - (size + gap + words) / 2.0;
look.icon(ui, glyph, pos2(left + size / 2.0, b.center().y), size, tint);
text(
@@ -201,7 +219,7 @@ impl Liquify {
egui::Area::new(Id::unique("liquify kinds")).fixed_pos(rect.min).order(Order::Tooltip).show(ctx, |ui| {
popover_frame(ui, rect, tip_x, tip_y);
let inner = rect.shrink(10.0);
- menu_title(ui, inner, "Liquify Mode");
+ menu_title(ui, inner, tr("Liquify Mode"));
let group =
Rect::from_min_size(pos2(inner.left(), inner.top() + 50.0), vec2(inner.width(), 8.0 * 44.0 + 7.0));
ui.painter().rect_filled(group, 13, argb(MENU_GROUP));
@@ -226,7 +244,7 @@ impl Liquify {
ui.painter(),
pos2(row.left() + 16.0, row.center().y),
Align2::LEFT_CENTER,
- label,
+ tr(label),
17.0,
Weight::Regular,
ink,
@@ -262,13 +280,13 @@ impl Liquify {
egui::Area::new(Id::unique("liquify adjust")).fixed_pos(rect.min).order(Order::Tooltip).show(ctx, |ui| {
popover_frame(ui, rect, tip_x, tip_y);
let inner = rect.shrink(10.0);
- menu_title(ui, inner, "Strength");
+ menu_title(ui, inner, tr("Strength"));
let group = Rect::from_min_size(pos2(inner.left(), inner.top() + 44.0), vec2(inner.width(), 59.0 + 16.0));
ui.painter().rect_filled(group, 13, argb(MENU_GROUP));
let row = Rect::from_min_size(group.min + vec2(0.0, 8.0), vec2(group.width(), 59.0));
let amount = shown.liquify_amount;
let label = percent(amount, None);
- let (v, let_go) = menu_slider_let_go(ui, row, "Amount", amount, &label);
+ let (v, let_go) = menu_slider_let_go(ui, row, tr("Amount"), amount, &label);
if let Some(v) = v {
session.adjustment_liquify_amount(v);
}
diff --git a/desktop/src/locale.rs b/desktop/src/locale.rs
new file mode 100644
index 000000000..490d1ebd7
--- /dev/null
+++ b/desktop/src/locale.rs
@@ -0,0 +1,44 @@
+pub fn configure() {
+ let preferred = std::env::var("PROCRAFT_LANGUAGE")
+ .ok()
+ .filter(|tag| !tag.trim().is_empty())
+ .map_or_else(system_languages, |tag| vec![tag]);
+ procraft_core::configure_app_language(preferred);
+}
+
+#[cfg(target_os = "linux")]
+fn system_languages() -> Vec {
+ let locale = ["LC_ALL", "LC_MESSAGES", "LANG"]
+ .into_iter()
+ .find_map(|name| std::env::var(name).ok().filter(|value| !value.is_empty()));
+ if locale.as_deref().is_some_and(|name| matches!(name.split('.').next(), Some("C" | "POSIX"))) {
+ return Vec::new();
+ }
+ let preferred = std::env::var("LANGUAGE").unwrap_or_default();
+ preferred.split(':').filter(|tag| !tag.is_empty()).map(str::to_owned).chain(locale).collect()
+}
+
+#[cfg(target_os = "macos")]
+fn system_languages() -> Vec {
+ objc2_foundation::NSLocale::preferredLanguages().to_vec().iter().map(|tag| tag.to_string()).collect()
+}
+
+#[cfg(windows)]
+#[allow(unsafe_code)]
+fn system_languages() -> Vec {
+ use windows::Win32::Globalization::{GetUserPreferredUILanguages, MUI_LANGUAGE_NAME};
+ use windows::core::PWSTR;
+
+ let (mut count, mut len) = (0, 0);
+ if unsafe { GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &mut count, None, &mut len) }.is_err() {
+ return Vec::new();
+ }
+ let mut tags = vec![0_u16; len as usize];
+ // The buffer has the size requested by the first call, including the terminating nulls.
+ if unsafe { GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &mut count, Some(PWSTR(tags.as_mut_ptr())), &mut len) }
+ .is_err()
+ {
+ return Vec::new();
+ }
+ tags.split(|unit| *unit == 0).take_while(|tag| !tag.is_empty()).map(String::from_utf16_lossy).collect()
+}
diff --git a/desktop/src/look.rs b/desktop/src/look.rs
index 4c32a2895..90260f183 100644
--- a/desktop/src/look.rs
+++ b/desktop/src/look.rs
@@ -224,8 +224,9 @@ pub static INTER_FACES: [(Weight, &[u8]); 4] = [
pub fn install_fonts(ctx: &egui::Context) {
ctx.set_fonts(fonts(Vec::new()));
let ctx = ctx.clone();
+ let language = procraft_core::app_language();
std::thread::spawn(move || {
- let system = system_fonts();
+ let system = system_fonts(language);
if !system.is_empty() {
ctx.set_fonts(fonts(system));
ctx.request_repaint();
@@ -261,12 +262,29 @@ fn fonts(system: Vec<(String, egui::FontData)>) -> egui::FontDefinitions {
/// their families through Core Text (where the files are differs from one release to the next):
/// `(name, font)` each, a collection's own face of the family.
#[cfg(target_os = "macos")]
-fn system_fonts() -> Vec<(String, egui::FontData)> {
- const FAMILIES: [&str; 5] =
- ["PingFang SC", "Hiragino Sans GB", "Apple SD Gothic Neo", "Arial Unicode MS", "Apple Symbols"];
+fn system_fonts(language: &str) -> Vec<(String, egui::FontData)> {
+ const FAMILIES: &[&str] = &[
+ "PingFang SC",
+ "Hiragino Sans GB",
+ "Apple SD Gothic Neo",
+ "Kohinoor Devanagari", // i18n: literal
+ "Sama Gurmukhi", // i18n: literal
+ "Tamil Sangam MN", // i18n: literal
+ "Telugu Sangam MN", // i18n: literal
+ "Thonburi", // i18n: literal
+ "Arial Unicode MS",
+ "Apple Symbols",
+ ];
let mut read: Vec<(std::path::PathBuf, String)> = Vec::new();
- FAMILIES
- .iter()
+ let preferred = match language {
+ "ja" => Some("Hiragino Sans"), // i18n: literal
+ "ko" => Some("Apple SD Gothic Neo"), // i18n: literal
+ "zh-Hant" => Some("PingFang TC"), // i18n: literal
+ _ => None,
+ };
+ preferred
+ .into_iter()
+ .chain(FAMILIES.iter().copied())
.filter_map(|family| {
let (file, face) = core_text::font_file(family)?;
// two families in one face are read once
@@ -274,16 +292,7 @@ fn system_fonts() -> Vec<(String, egui::FontData)> {
return None;
}
let bytes = std::fs::read(&file).ok()?;
- // its face in a collection, by its PostScript name
- let index = swash::FontDataRef::new(&bytes)
- .and_then(|data| {
- data.fonts().position(|font| {
- let name = font.localized_strings().find_by_id(swash::StringId::PostScript, None);
- name.is_some_and(|name| name.to_string() == face)
- })
- })
- .and_then(|i| u32::try_from(i).ok())
- .unwrap_or(0);
+ let index = font_face_index(&bytes, &face);
read.push((file, face));
let mut font = egui::FontData::from_owned(bytes);
font.index = index;
@@ -292,6 +301,19 @@ fn system_fonts() -> Vec<(String, egui::FontData)> {
.collect()
}
+#[cfg(unix)]
+fn font_face_index(bytes: &[u8], face: &str) -> u32 {
+ swash::FontDataRef::new(bytes)
+ .and_then(|data| {
+ data.fonts().position(|font| {
+ let name = font.localized_strings().find_by_id(swash::StringId::PostScript, None);
+ name.is_some_and(|name| name.to_string() == face)
+ })
+ })
+ .and_then(|i| u32::try_from(i).ok())
+ .unwrap_or(0)
+}
+
/// Core Text's calls for the fonts' files, unsafe as the system's are.
#[cfg(target_os = "macos")]
#[allow(unsafe_code)]
@@ -320,7 +342,7 @@ mod core_text {
/// Arabic, Hebrew, Indic, Thai, ...), those of them it has: names (a brush's from another app,
/// an artwork's typed in any language) shown as written. `(name, font)` each.
#[cfg(not(target_os = "macos"))]
-fn system_fonts() -> Vec<(String, egui::FontData)> {
+fn system_fonts(language: &str) -> Vec<(String, egui::FontData)> {
#[cfg(windows)]
let (dir, files): (std::path::PathBuf, &[&str]) = (
std::path::PathBuf::from(std::env::var_os("WINDIR").unwrap_or_else(|| "C:\\Windows".into())).join("Fonts"),
@@ -346,18 +368,42 @@ fn system_fonts() -> Vec<(String, egui::FontData)> {
"truetype/noto/NotoSansArabic-Regular.ttf",
"truetype/noto/NotoSansHebrew-Regular.ttf",
"truetype/noto/NotoSansDevanagari-Regular.ttf",
+ "truetype/noto/NotoSansGurmukhi-Regular.ttf",
+ "truetype/noto/NotoSansTamil-Regular.ttf",
+ "truetype/noto/NotoSansTelugu-Regular.ttf",
"truetype/noto/NotoSansThai-Regular.ttf",
"truetype/dejavu/DejaVuSans.ttf",
],
);
#[cfg(not(any(windows, unix)))]
let (dir, files): (std::path::PathBuf, &[&str]) = (std::path::PathBuf::new(), &[]);
- files
+ let preferred: &[&str] = match (cfg!(windows), language) {
+ (true, "ja") => &["YuGothR.ttc", "msgothic.ttc"],
+ (true, "ko") => &["malgun.ttf"],
+ (true, "zh-Hant") => &["msjh.ttc"],
+ _ => &[],
+ };
+ preferred
.iter()
+ .copied()
+ .chain(files.iter().copied().filter(|file| !preferred.contains(file)))
.filter_map(|file| {
let bytes = std::fs::read(dir.join(file)).ok()?;
- // a collection's first face (each of these has its regular weight first)
- Some((format!("system {file}"), egui::FontData::from_owned(bytes)))
+ #[cfg(unix)]
+ let face = match language {
+ "ja" if file.ends_with("NotoSansCJK-Regular.ttc") => Some("NotoSansCJKjp-Regular"),
+ "ko" if file.ends_with("NotoSansCJK-Regular.ttc") => Some("NotoSansCJKkr-Regular"),
+ "zh-Hans" if file.ends_with("NotoSansCJK-Regular.ttc") => Some("NotoSansCJKsc-Regular"),
+ "zh-Hant" if file.ends_with("NotoSansCJK-Regular.ttc") => Some("NotoSansCJKtc-Regular"),
+ _ => None,
+ };
+ #[cfg(unix)]
+ let index = face.map_or(0, |face| font_face_index(&bytes, face));
+ #[cfg(not(unix))]
+ let index = 0;
+ let mut font = egui::FontData::from_owned(bytes);
+ font.index = index;
+ Some((format!("system {file}"), font))
})
.collect()
}
@@ -412,21 +458,14 @@ fn tracked_runs(
};
job.append(text, 0.0, format);
}
- let galley = painter.layout_job(job);
+ let galley = layout_job(painter, job);
let rect = align.anchor_size(at, galley.size());
- painter.galley(rect.min, galley, colour);
+ draw_layout(painter, rect.min, galley, colour);
rect
}
/// Text of one weight, `size` points, wrapped `width` wide, laid out to be drawn.
-pub fn wrapped(
- painter: &Painter,
- text: &str,
- size: f32,
- weight: Weight,
- colour: Color32,
- width: f32,
-) -> Arc {
+pub fn wrapped(painter: &Painter, text: &str, size: f32, weight: Weight, colour: Color32, width: f32) -> TextLayout {
let mut job = LayoutJob::default();
let format = TextFormat {
font_id: weight.font(size),
@@ -436,7 +475,7 @@ pub fn wrapped(
};
job.append(text, 0.0, format);
job.wrap.max_width = width;
- painter.layout_job(job)
+ layout_job(painter, job)
}
/// Text wrapped `width` wide with its lines centred (about x = 0 where it is drawn) and
@@ -449,7 +488,7 @@ pub fn wrapped_centred(
colour: Color32,
width: f32,
line_height: f32,
-) -> Arc {
+) -> TextLayout {
let mut job = LayoutJob::default();
let format = TextFormat {
font_id: weight.font(size),
@@ -461,7 +500,7 @@ pub fn wrapped_centred(
job.append(text, 0.0, format);
job.wrap.max_width = width;
job.halign = egui::Align::Center;
- painter.layout_job(job)
+ layout_job(painter, job)
}
/// How far across (points) the pointer has gone since the last frame while held on `response`, a
@@ -490,7 +529,7 @@ pub fn text_width(painter: &Painter, text: &str, size: f32, weight: Weight) -> f
let mut job = LayoutJob::default();
let format = TextFormat { font_id: weight.font(size), extra_letter_spacing: TRACKING * size, ..Default::default() };
job.append(text, 0.0, format);
- painter.layout_job(job).size().x
+ layout_job(painter, job).size().x
}
/// Text of one weight; see [`text_runs`].
@@ -506,6 +545,116 @@ pub fn text(
text_runs(painter, at, align, &[(text, weight)], size, colour)
}
+#[derive(Clone)]
+pub enum TextLayout {
+ Galley(Arc),
+ Shaped { texture: TextureHandle, size: egui::Vec2, scale: f32, centered: bool },
+}
+
+impl TextLayout {
+ pub fn size(&self) -> egui::Vec2 {
+ match self {
+ Self::Galley(galley) => galley.size(),
+ Self::Shaped { size, .. } => *size,
+ }
+ }
+}
+
+pub fn layout(painter: &Painter, text: String, font: FontId, ink: Color32, width: f32) -> TextLayout {
+ layout_job(painter, LayoutJob::simple(text, font, ink, width))
+}
+
+pub fn layout_no_wrap(painter: &Painter, text: String, font: FontId, ink: Color32) -> TextLayout {
+ layout(painter, text, font, ink, f32::INFINITY)
+}
+
+pub fn layout_job(painter: &Painter, job: LayoutJob) -> TextLayout {
+ // Keep Arabic runs, Indic conjuncts and Thai marks together through font fallback.
+ if !job
+ .text
+ .chars()
+ .any(|ch| matches!(ch, '\u{0600}'..='\u{0a7f}' | '\u{0b80}'..='\u{0c7f}' | '\u{0e00}'..='\u{0e7f}' | '\u{fb50}'..='\u{feff}'))
+ {
+ return TextLayout::Galley(painter.layout_job(job));
+ }
+ let scale = painter.ctx().pixels_per_point();
+ let mut hasher = std::collections::hash_map::DefaultHasher::new();
+ job.hash(&mut hasher);
+ scale.to_bits().hash(&mut hasher);
+ let id = egui::Id::unique("shaped_interface_text");
+ let key = hasher.finish();
+ type Cache = HashMap;
+ if let Some(shaped) = painter.ctx().data_mut(|data| data.get_temp_mut_or_default::(id).get(&key).cloned()) {
+ return shaped;
+ }
+ crate::text::fonts_ready();
+ let runs = job
+ .sections
+ .iter()
+ .map(|section| {
+ let format = §ion.format;
+ let size = format.font_id.size;
+ let weight = match &format.font_id.family {
+ FontFamily::Name(name) if name.as_ref() == Weight::Medium.name() => 500,
+ FontFamily::Name(name) if name.as_ref() == Weight::SemiBold.name() => 600,
+ FontFamily::Name(name) if name.as_ref() == Weight::Bold.name() => 700,
+ _ => 400,
+ };
+ procraft_core::InterfaceRun {
+ text: &job.text[section.byte_range.start.0..section.byte_range.end.0],
+ size,
+ line_height: format.line_height.unwrap_or(size * 1.2),
+ weight,
+ colour: format.color.to_srgba_unmultiplied(),
+ }
+ })
+ .collect::>();
+ let centered = job.halign == egui::Align::Center;
+ let width = job.wrap.max_width.is_finite().then_some(job.wrap.max_width);
+ let Some(drawn) = procraft_core::draw_interface_text(&runs, scale, width, centered, job.wrap.max_rows) else {
+ return TextLayout::Galley(painter.layout_job(job));
+ };
+ let image = egui::ColorImage::from_rgba_premultiplied(drawn.pixels, &drawn.rgba);
+ let texture = painter.ctx().load_texture("shaped_interface_text", image, TextureOptions::LINEAR);
+ let shaped = TextLayout::Shaped { texture, size: drawn.size.into(), scale, centered };
+ painter.ctx().data_mut(|data| {
+ let cache = data.get_temp_mut_or_default::(id);
+ if cache.len() >= 256 {
+ cache.clear();
+ }
+ cache.insert(key, shaped.clone());
+ });
+ shaped
+}
+
+pub fn draw_layout(painter: &Painter, at: Pos2, words: TextLayout, ink: Color32) {
+ draw_layout_rotated(painter, at, words, ink, 0.0);
+}
+
+pub fn draw_layout_rotated(painter: &Painter, at: Pos2, words: TextLayout, ink: Color32, angle: f32) {
+ match words {
+ TextLayout::Galley(galley) => {
+ if angle == 0.0 {
+ painter.galley(at, galley, ink);
+ } else {
+ painter.add(egui::epaint::TextShape::new(at, galley, ink).with_angle(angle));
+ }
+ }
+ TextLayout::Shaped { texture, size, scale, centered } => {
+ let x = if centered { -size.x / 2.0 } else { 0.0 };
+ let pad = 2.0 / scale;
+ let min = vec2(x - pad, -pad);
+ let rect = Rect::from_min_size(at + min, texture.size_vec2() / scale);
+ let mut mesh = egui::Mesh::with_texture(texture.id());
+ mesh.add_rect_with_uv(rect, ALL, Color32::WHITE);
+ if angle != 0.0 {
+ mesh.rotate(egui::emath::Rot2::from_angle(angle), at);
+ }
+ painter.add(mesh);
+ }
+ }
+}
+
/// The whole of a texture.
const ALL: Rect = Rect { min: pos2(0.0, 0.0), max: pos2(1.0, 1.0) };
diff --git a/desktop/src/main.rs b/desktop/src/main.rs
index df8d4cfef..d98e6b16d 100644
--- a/desktop/src/main.rs
+++ b/desktop/src/main.rs
@@ -4,6 +4,8 @@
// no console window behind the app on Windows (a debug build keeps it, for the log)
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
+use procraft_core::tr;
+
mod actions;
mod adjust_panels;
mod adjustments;
@@ -44,6 +46,7 @@ mod library;
mod licences;
mod lighting;
mod liquify;
+mod locale;
mod look;
mod menu;
mod model_picture;
@@ -267,12 +270,12 @@ fn veil(ctx: &egui::Context, what: &str) {
/// compiler they take a minute or more, and a canvas opened meanwhile waits for them).
const CANVASES_SLOW: Duration = Duration::from_secs(2);
/// What the window says meanwhile.
-const GETTING_READY: &str = "Getting the canvas ready…";
+const GETTING_READY: &str = procraft_core::message!("Getting the canvas ready…");
/// What a canvas's veil says while it opens: while the pipelines it waits for are still being
/// made (`waiting`), that.
fn opening_words(waiting: bool) -> &'static str {
- if waiting { GETTING_READY } else { "Opening…" }
+ if waiting { tr(GETTING_READY) } else { tr("Opening…") }
}
/// At the gallery's foot while the canvases' pipelines are still being made: a note saying so,
@@ -281,16 +284,18 @@ fn getting_ready_note(ctx: &egui::Context) {
let screen = ctx.content_rect();
let painter = ctx.layer_painter(egui::LayerId::new(egui::Order::Foreground, egui::Id::unique("getting ready")));
let ink = look::argb(look::pc::TEXT);
- let wide = painter.layout_no_wrap(GETTING_READY.to_owned(), look::Weight::Regular.font(15.0), ink).size().x;
+ let words = tr(GETTING_READY);
+ let wide = crate::look::layout_no_wrap(&painter, words.to_owned(), look::Weight::Regular.font(15.0), ink).size().x;
let note = egui::Rect::from_center_size(
egui::pos2(screen.center().x, screen.bottom() - 24.0 - 18.0),
egui::vec2(wide + 36.0, 36.0),
);
painter.rect_filled(note, 18.0, look::argb(look::pc::BAR));
- look::text(&painter, note.center(), egui::Align2::CENTER_CENTER, GETTING_READY, 15.0, look::Weight::Regular, ink);
+ look::text(&painter, note.center(), egui::Align2::CENTER_CENTER, words, 15.0, look::Weight::Regular, ink);
}
fn main() {
+ locale::configure();
// the log, to the app folder's file too, and a crash's message into it
startup::init();
// artworks being opened, noted until they show: one the app ended while opening is asked about
@@ -308,7 +313,7 @@ fn main() {
let event_loop = match EventLoop::new() {
Ok(l) => l,
Err(e) => {
- startup::stopped(&format!("it couldn't make its window's event loop: {e}"));
+ startup::stopped(&procraft_core::trf("it couldn't make its window's event loop: {0}", &[("0", &e)]));
return;
}
};
@@ -366,7 +371,7 @@ fn main() {
// (its message and place are in the log already)
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| event_loop.run_app(&mut app))) {
Ok(Ok(())) => {}
- Ok(Err(e)) => startup::stopped(&format!("its window's event loop stopped: {e}")),
+ Ok(Err(e)) => startup::stopped(&procraft_core::trf("its window's event loop stopped: {0}", &[("0", &e)])),
Err(panic) => {
if let Some(screen) = &app.screen {
screen.window.set_visible(false);
@@ -470,7 +475,7 @@ impl TitleWatch {
/// at again [`TITLE_CHECK`] later while it isn't saved.
fn follow(&mut self, name: &str, saved: bool, now: Instant) -> Option {
let unsaved = if saved { "" } else { " •" };
- let title = format!("{name}{unsaved} — ProCraft");
+ let title = procraft_core::trf("{0}{1} \u{2014} ProCraft", &[("0", &name), ("1", &unsaved)]);
self.check_at = (!saved).then(|| now + TITLE_CHECK);
(title != self.shown).then(|| {
self.shown.clone_from(&title);
@@ -550,7 +555,7 @@ impl ApplicationHandler for App {
return;
}
let attributes = Window::default_attributes()
- .with_title("ProCraft")
+ .with_title(tr("ProCraft"))
.with_window_icon(window_icon())
.with_inner_size(LogicalSize::new(1440.0, 900.0))
.with_min_inner_size(LogicalSize::new(640.0, 480.0))
@@ -567,7 +572,7 @@ impl ApplicationHandler for App {
let window = match event_loop.create_window(attributes) {
Ok(w) => Arc::new(w),
Err(e) => {
- startup::stopped(&format!("it couldn't open its window: {e}"));
+ startup::stopped(&procraft_core::trf("it couldn't open its window: {0}", &[("0", &e)]));
event_loop.exit();
return;
}
@@ -611,7 +616,7 @@ impl ApplicationHandler for App {
}
Err(e) => {
log::error!("no GPU for the window:\n{e}");
- files::tell("ProCraft can't draw", &startup::no_gpu_text(&e));
+ files::tell(tr("ProCraft can't draw"), &startup::no_gpu_text(&e));
event_loop.exit();
return;
}
@@ -1027,7 +1032,7 @@ impl App {
} else if exporting {
veil(ui.ctx(), "Exporting…");
} else if finishing_slowly {
- veil(ui.ctx(), "Finishing the fill…");
+ veil(ui.ctx(), tr("Finishing the fill…"));
}
// whether to leave the artwork without saving it, over everything
leave_answer = leave_answer.or(self.leave_question.show(ui.ctx(), &mut self.ui.look));
@@ -1252,7 +1257,7 @@ impl App {
}
}
Some(_) => {}
- None => files::say("The plugin couldn't make this artwork."),
+ None => files::say(tr("The plugin couldn't make this artwork.")),
}
}
Some(gallery::Asked::Share(list, format)) => {
@@ -1444,7 +1449,7 @@ impl App {
let name = p.file_name().map(|n| n.to_string_lossy().into_owned());
std::fs::read(p).is_ok_and(|bytes| store.import_file(bytes, name))
});
- files::say(if added.count() > 0 { "Palette added." } else { "This palette can't be read." });
+ files::say(if added.count() > 0 { tr("Palette added.") } else { tr("This palette can't be read.") });
}
let (brushes, paths): (Vec<_>, Vec<_>) = paths.into_iter().partition(|p| files::is_brush_file(p));
if !brushes.is_empty() {
@@ -1517,7 +1522,7 @@ impl App {
self.zoom = Some(zoom::Zoom::opening(&session, cell, turns, (size.width, size.height), scale));
}
}
- Err(e) => files::tell("Can't open the artwork", &e),
+ Err(e) => files::tell(tr("Can't open the artwork"), &e),
}
}
@@ -1535,7 +1540,7 @@ impl App {
self.open_artwork(session, dir);
self.ui.started_new();
}
- Err(e) => files::tell("Can't open the picture", &e),
+ Err(e) => files::tell(tr("Can't open the picture"), &e),
}
}
@@ -1602,7 +1607,7 @@ impl App {
let path = match files::drag_file(artwork, format) {
Ok(path) => path,
Err(e) => {
- files::tell("Can't drag it out", &e);
+ files::tell(tr("Can't drag it out"), &e);
return;
}
};
@@ -1657,10 +1662,13 @@ impl App {
if let Some(tried) = startup::device_lost() {
log::warn!("the graphics device stopped as this backend started: starting again on the next");
if !startup::start_on_next(tried) {
- startup::stopped("the graphics device stopped, and it couldn't start itself again");
+ startup::stopped(tr("the graphics device stopped, and it couldn't start itself again"));
}
} else {
- files::tell("The graphics device stopped", "ProCraft starts again, with the artwork as it was last saved.");
+ files::tell(
+ tr("The graphics device stopped"),
+ tr("ProCraft starts again, with the artwork as it was last saved."),
+ );
startup::start_again(None);
}
event_loop.exit();
@@ -1688,7 +1696,7 @@ impl App {
self.screen = None;
self.closed = true;
if !startup::start_again(Some(tried)) {
- startup::stopped("its pipelines failed on this graphics backend, and it couldn't start itself again");
+ startup::stopped(tr("its pipelines failed on this graphics backend, and it couldn't start itself again"));
}
event_loop.exit();
}
@@ -1767,7 +1775,7 @@ impl App {
procraft_core::Leaving::Lost { message } => {
log::warn!("left with the GPU device lost: {message}");
if then.is_some() {
- files::tell("The graphics stopped working", &message);
+ files::tell(tr("The graphics stopped working"), &message);
}
true
}
@@ -1794,7 +1802,7 @@ impl App {
let why = e.to_string();
let said =
if procraft_core::storage_was_full(why.clone()) { procraft_core::NO_ROOM.to_owned() } else { why };
- files::tell("Can't keep the artwork", &said);
+ files::tell(tr("Can't keep the artwork"), &said);
false
}
}
diff --git a/desktop/src/menu.rs b/desktop/src/menu.rs
index 9a7ac682b..9f0ff5c32 100644
--- a/desktop/src/menu.rs
+++ b/desktop/src/menu.rs
@@ -8,7 +8,7 @@ use egui::emath::TSTransform;
use egui::{Align2, Id, LayerId, Order, Pos2, Rect, Sense, Ui, Vec2, pos2, vec2};
use crate::icons;
-use crate::look::{Look, Themed, Weight, argb, cubic_bezier, text};
+use crate::look::{Look, Themed, Weight, argb, cubic_bezier, text, text_width};
/// How long a menu takes to open or close, seconds.
const MENU_TIME: f32 = 0.3;
@@ -233,7 +233,12 @@ pub fn option(
} else {
argb(INK)
};
- text(ui.painter(), pos2(row.left() + 19.0, row.center().y), Align2::LEFT_CENTER, label, 17.0, Weight::Regular, ink);
+ let tail = if checked { 38.0 } else { 16.0 };
+ let room = row.width() - 19.0 - tail;
+ let width = text_width(ui.painter(), label, 17.0, Weight::Regular);
+ let size = (17.0 * room / width.max(room)).max(12.0);
+ let painter = ui.painter().with_clip_rect(row.with_max_x(row.right() - tail));
+ text(&painter, pos2(row.left() + 19.0, row.center().y), Align2::LEFT_CENTER, label, size, Weight::Regular, ink);
if checked {
look.icon(ui, &icons::TICK, pos2(row.right() - 16.0 - 9.0, row.center().y), 18.0, ink);
}
@@ -295,7 +300,7 @@ pub fn entries(ui: &Ui, look: &mut Look, rect: Rect, entries: &[Entry]) -> Optio
ui.painter(),
pos2(row.left() + 52.0, row.center().y),
Align2::LEFT_CENTER,
- label,
+ procraft_core::tr(label),
18.0,
Weight::Regular,
ink,
diff --git a/desktop/src/model_picture.rs b/desktop/src/model_picture.rs
index 19e6e810e..320054b7e 100644
--- a/desktop/src/model_picture.rs
+++ b/desktop/src/model_picture.rs
@@ -3,6 +3,8 @@
//! wheel over it scale and turn it; off it, the model turns as ever. The core carries it onto the
//! surface as it goes.
+use procraft_core::tr;
+
use egui::{Color32, Id, LayerId, Order, Stroke, pos2};
use procraft_core::CanvasSession;
@@ -27,12 +29,12 @@ pub fn show(ctx: &egui::Context, look: &mut Look, session: &CanvasSession) {
painter.circle_filled(p, 6.0, Color32::WHITE);
}
let buttons = [
- Button::new(&icons::FLIP_HORIZONTAL, "Flip Horizontal", 50.0),
- Button::new(&icons::FLIP_VERTICAL, "Flip Vertical", 50.0),
- Button::new(&icons::ROTATE45, "Rotate 45\u{b0}", 44.0),
- Button::new(&icons::TRANSFORM_RESET, "Reset", 44.0),
- Button::new(&icons::CROSS, "Cancel", 28.0),
- Button::new(&icons::TICK, "Done", 28.0),
+ Button::new(&icons::FLIP_HORIZONTAL, tr("Flip Horizontal"), 50.0),
+ Button::new(&icons::FLIP_VERTICAL, tr("Flip Vertical"), 50.0),
+ Button::new(&icons::ROTATE45, tr("Rotate 45\u{b0}"), 44.0),
+ Button::new(&icons::TRANSFORM_RESET, tr("Reset"), 44.0),
+ Button::new(&icons::CROSS, tr("Cancel"), 28.0),
+ Button::new(&icons::TICK, tr("Done"), 28.0),
];
match floating_toolbar(ctx, look, "model picture bar", BUTTON_ROOMY, &[], &buttons, 43.0) {
Some(Tapped::Button(0)) => session.model_picture_flip(true),
diff --git a/desktop/src/overlays.rs b/desktop/src/overlays.rs
index fa2e218c7..072959073 100644
--- a/desktop/src/overlays.rs
+++ b/desktop/src/overlays.rs
@@ -2,6 +2,8 @@
//! (ui/AppRoot.kt, ui/Eyedropper.kt, ui/AdjustmentsUi.kt): the notice band under the top bar
//! ("Undo Brush stroke"), the eyedropper's band and loupe, and the bar of a snapped shape.
+use procraft_core::tr;
+
use std::time::{Duration, Instant};
use egui::{Align2, Color32, Pos2, Rect, Sense, TextureHandle, TextureOptions, Ui, pos2, vec2};
@@ -285,7 +287,11 @@ impl Overlays {
ui.painter(),
band.center(),
Align2::CENTER_CENTER,
- if p.from_reference { "Picking color from reference" } else { "Picking color from canvas" },
+ if p.from_reference {
+ tr("Picking color from reference")
+ } else {
+ tr("Picking color from canvas")
+ },
14.0,
Weight::Regular,
ink,
@@ -419,7 +425,9 @@ impl Overlays {
let name = if self.shape_editing { "Editing" } else { label(info.kind) };
// laid out from the middle: the icon, the name, the kind in grey and the disclosure
let painter = ui.painter();
- let measure = |s: &str, size: f32, w: Weight| painter.layout_no_wrap(s.into(), w.font(size), ink).size().x;
+ let measure = |s: &str, size: f32, w: Weight| {
+ crate::look::layout_no_wrap(painter, s.into(), w.font(size), ink).size().x
+ };
let mut width = 29.0 + measure(name, 17.0, Weight::Bold);
if self.shape_editing && several {
width += 3.0 + measure(label(info.kind), 15.0, Weight::Regular);
@@ -466,11 +474,14 @@ impl Overlays {
if *kind == info.kind {
ui.painter().rect_filled(cell, 14, argb(pc::ACCENT));
}
- let words = ui
- .painter()
- .layout_no_wrap(label(*kind).into(), Weight::Regular.font(14.0), Color32::WHITE)
- .size()
- .x;
+ let words = crate::look::layout_no_wrap(
+ ui.painter(),
+ label(*kind).into(),
+ Weight::Regular.font(14.0),
+ Color32::WHITE,
+ )
+ .size()
+ .x;
let start = cell.center().x - (28.0 + 6.0 + words) / 2.0;
look.icon(ui, icon(*kind), pos2(start + 14.0, cell.center().y), 28.0, Color32::WHITE);
text(
@@ -635,38 +646,20 @@ fn shape_handles(ui: &Ui, points: &[Pos2], info: &QuickShapeInfo) {
pub fn label(kind: QuickShapeKind) -> &'static str {
match kind {
- QuickShapeKind::Line => "Line",
- QuickShapeKind::Polyline => "Polyline",
- QuickShapeKind::Arc => "Arc",
- QuickShapeKind::Curve => "Curve",
- QuickShapeKind::Ellipse => "Ellipse",
- QuickShapeKind::Circle => "Circle",
- QuickShapeKind::Triangle => "Triangle",
- QuickShapeKind::EquilateralTriangle => "Equilateral",
- QuickShapeKind::Quadrilateral => "Quadrilateral",
- QuickShapeKind::Rectangle => "Rectangle",
- QuickShapeKind::Square => "Square",
+ QuickShapeKind::Line => tr("Line"),
+ QuickShapeKind::Polyline => tr("Polyline"),
+ QuickShapeKind::Arc => tr("Arc"),
+ QuickShapeKind::Curve => tr("Curve"),
+ QuickShapeKind::Ellipse => tr("Ellipse"),
+ QuickShapeKind::Circle => tr("Circle"),
+ QuickShapeKind::Triangle => tr("Triangle"),
+ QuickShapeKind::EquilateralTriangle => tr("Equilateral"),
+ QuickShapeKind::Quadrilateral => tr("Quadrilateral"),
+ QuickShapeKind::Rectangle => tr("Rectangle"),
+ QuickShapeKind::Square => tr("Square"),
}
}
-/// What a stroke snapped to, for the notice band.
-pub fn snapped_to(kind: QuickShapeKind) -> String {
- let what = match kind {
- QuickShapeKind::Line => "a line",
- QuickShapeKind::Polyline => "a polyline",
- QuickShapeKind::Arc => "an arc",
- QuickShapeKind::Curve => "a curve",
- QuickShapeKind::Ellipse => "an ellipse",
- QuickShapeKind::Circle => "a circle",
- QuickShapeKind::Triangle => "a triangle",
- QuickShapeKind::EquilateralTriangle => "an equilateral triangle",
- QuickShapeKind::Quadrilateral => "a quadrilateral",
- QuickShapeKind::Rectangle => "a rectangle",
- QuickShapeKind::Square => "a square",
- };
- format!("Snapped to {what}")
-}
-
fn icon(kind: QuickShapeKind) -> &'static icons::Icon {
match kind {
QuickShapeKind::Line => &icons::SHAPE_LINE,
diff --git a/desktop/src/panel.rs b/desktop/src/panel.rs
index fa441e3d8..b248ee7ef 100644
--- a/desktop/src/panel.rs
+++ b/desktop/src/panel.rs
@@ -1,6 +1,8 @@
//! The panels hanging from the top bar, as the Android app's (ui/Popover.kt, ui/AppRoot.kt): a
//! frosted body with an arrow pointing up at its button, a soft shadow around it, and a header.
+use procraft_core::tr;
+
use egui::emath::TSTransform;
use egui::{Align2, Color32, Pos2, Rect, Sense, Ui, Vec2, pos2};
use procraft_core::{HangSide, InterfacePart};
@@ -180,13 +182,13 @@ pub fn window_menu(ui: &Ui, at: Rect) -> Option {
let pinned = ctx.data(|d| d.get_temp::(egui::Id::unique("window pinned"))).unwrap_or(false);
let mut rows = Vec::new();
if panels_fold(&ctx) {
- rows.push((WindowAct::Fold, "Fold"));
+ rows.push((WindowAct::Fold, tr("Fold")));
}
- rows.push((WindowAct::Hide, "Hide"));
- rows.push((WindowAct::Pin, if pinned { "Unpin" } else { "Pin to Top" }));
- rows.push((WindowAct::Reset, "Reset Position"));
+ rows.push((WindowAct::Hide, tr("Hide")));
+ rows.push((WindowAct::Pin, if pinned { tr("Unpin") } else { tr("Pin to Top") }));
+ rows.push((WindowAct::Reset, tr("Reset Position")));
if let Some(any) = collapse_all(&ctx) {
- rows.push((WindowAct::CollapseAll, if any { "Open All" } else { "Collapse All" }));
+ rows.push((WindowAct::CollapseAll, if any { tr("Open All") } else { tr("Collapse All") }));
}
// in the window's points, over everything
let origin = to_window(&ctx) * at.left_bottom();
diff --git a/desktop/src/pdf.rs b/desktop/src/pdf.rs
index 895a98425..92457414b 100644
--- a/desktop/src/pdf.rs
+++ b/desktop/src/pdf.rs
@@ -10,7 +10,8 @@ pub const DPI: f32 = 300.0;
const MOST_SIDE: f32 = 4096.0;
/// What is said where PDFs are drawn by poppler's tools and they aren't installed.
-pub const NO_POPPLER: &str = "Opening a PDF needs pdftoppm: install poppler-utils from your system's packages.";
+pub const NO_POPPLER: &str =
+ procraft_core::message!("Opening a PDF needs pdftoppm: install poppler-utils from your system's packages.");
/// The canvas a PDF whose first page is `first` points (wide, tall) comes in at: [`DPI`], its
/// longer side within [`MOST_SIDE`].
diff --git a/desktop/src/projection.rs b/desktop/src/projection.rs
index c7f1d0aa4..902812653 100644
--- a/desktop/src/projection.rs
+++ b/desktop/src/projection.rs
@@ -2,6 +2,8 @@
//! attached, that display shows the whole canvas fitted and centred on black, drawn again after
//! each frame of the main window, and black while the gallery shows.
+use procraft_core::tr;
+
use std::sync::Arc;
use procraft_core::{CanvasSession, configure, screen_profile};
@@ -24,7 +26,7 @@ impl Projection {
/// A borderless window filling `monitor`, its surface on `gpu`'s device.
pub fn open(event_loop: &ActiveEventLoop, monitor: MonitorHandle, gpu: &Gpu) -> Option {
let attributes = Window::default_attributes()
- .with_title("ProCraft")
+ .with_title(tr("ProCraft"))
.with_decorations(false)
// the keyboard stays with the main window
.with_active(false);
diff --git a/desktop/src/questions.rs b/desktop/src/questions.rs
index 31e441eb6..2cae0d975 100644
--- a/desktop/src/questions.rs
+++ b/desktop/src/questions.rs
@@ -6,6 +6,8 @@
//! - Opening an artwork whose opening ended the app last time: Open Anyway, or Share Log, which
//! shows the log to send on and asks again, or Cancel.
+use procraft_core::tr;
+
use crate::alert::{Alert, Answer, Asking};
use crate::look::Look;
@@ -57,11 +59,11 @@ fn leave_asking(title: &str, said: &str) -> Asking {
Asking {
title: title.into(),
message: said.into(),
- action: "Leave Without Saving".into(),
+ action: tr("Leave Without Saving").into(),
icon: None,
destructive: true,
extra: None,
- first: Some("Stay".into()),
+ first: Some(tr("Stay").into()),
alone: false,
}
}
@@ -120,10 +122,10 @@ fn open_anyway_asking(said: String) -> Asking {
Asking {
title: procraft_core::opening_ended_app_title(),
message: said,
- action: "Open Anyway".into(),
+ action: tr("Open Anyway").into(),
icon: None,
destructive: false,
- extra: Some("Share Log".into()),
+ extra: Some(tr("Share Log").into()),
first: None,
alone: false,
}
diff --git a/desktop/src/quick_menu.rs b/desktop/src/quick_menu.rs
index 03522014f..4968541b8 100644
--- a/desktop/src/quick_menu.rs
+++ b/desktop/src/quick_menu.rs
@@ -4,6 +4,8 @@
//! (the middle held, the menus), while still held. The touch that opened it, still down, aims at
//! the buttons (the one it aims at shows pressed) and lifted taps that one.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use std::time::{Duration, Instant};
@@ -446,16 +448,16 @@ impl QuickMenu {
let sets =
if matches!(self.page, Page::BrushSets | Page::Brushes(_)) { session.brush_library() } else { Vec::new() };
let (title, back) = match self.page {
- Page::Actions => ("Set Action", None),
- Page::Adjustments => ("Adjustments", Some(Page::Actions)),
- Page::BrushSets => ("Brush Set", Some(Page::Actions)),
- Page::Brushes(_) => ("Brushes", Some(Page::BrushSets)),
+ Page::Actions => (tr("Set Action"), None),
+ Page::Adjustments => (tr("Adjustments"), Some(Page::Actions)),
+ Page::BrushSets => (tr("Brush Set"), Some(Page::Actions)),
+ Page::Brushes(_) => (tr("Brushes"), Some(Page::BrushSets)),
};
let rows: Vec<(String, bool, Tap)> = match self.page {
Page::Actions => quick_actions_listed()
.into_iter()
.map(|row| match row {
- None => ("Adjustments".to_owned(), true, Tap::Go(Page::Adjustments)),
+ None => (tr("Adjustments").to_owned(), true, Tap::Go(Page::Adjustments)),
Some(QuickAction::Brushes) => {
(quick_action_label(QuickAction::Brushes), true, Tap::Go(Page::BrushSets))
}
@@ -629,7 +631,7 @@ impl QuickMenu {
ui.painter().rect_filled(panel, PICKER_CORNER, argb(PICKER_FILL));
ui.allocate_rect(panel, Sense::click());
let at = pos2(panel.left() + 21.0, panel.top() + 16.0);
- text(ui.painter(), at, Align2::LEFT_TOP, "QuickMenu", 19.3, Weight::Bold, argb(PICKER_TITLE_INK));
+ text(ui.painter(), at, Align2::LEFT_TOP, tr("QuickMenu"), 19.3, Weight::Bold, argb(PICKER_TITLE_INK));
let plus = pos2(panel.right() - 30.0, panel.top() + 28.0);
for bar in [vec2(PLUS, PLUS_WEIGHT), vec2(PLUS_WEIGHT, PLUS)] {
ui.painter().rect_filled(Rect::from_center_size(plus, bar), PLUS_WEIGHT / 2.0, argb(PLUS_INK));
@@ -737,7 +739,7 @@ impl QuickMenu {
&painter,
button.center(),
Align2::CENTER_CENTER,
- "Delete",
+ tr("Delete"),
13.0,
Weight::SemiBold,
white,
diff --git a/desktop/src/reference.rs b/desktop/src/reference.rs
index e1d337522..631820bbf 100644
--- a/desktop/src/reference.rs
+++ b/desktop/src/reference.rs
@@ -4,6 +4,8 @@
//! picture, and a click on it slides them away and back. Each artwork keeps its own window (the
//! core saves it with the artwork): shown, what it shows, its size and place, and its picture.
+use procraft_core::tr;
+
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
@@ -466,8 +468,8 @@ impl Reference {
fn import(&mut self, ctx: &egui::Context, session: &CanvasSession) {
let Some(path) = crate::files::dialog()
- .set_title("Import Image")
- .add_filter("Pictures", &["png", "jpg", "jpeg", "webp", "gif", "bmp", "tif", "tiff"])
+ .set_title(tr("Import Image"))
+ .add_filter(tr("Pictures"), &["png", "jpg", "jpeg", "webp", "gif", "bmp", "tif", "tiff"])
.pick_file()
else {
return;
@@ -483,7 +485,7 @@ impl Reference {
session.set_reference_picture_at(self.index, png.into_inner());
}
}
- Err(_) => crate::files::tell("Can't import it", "This picture can't be opened."),
+ Err(_) => crate::files::tell(tr("Can't import it"), tr("This picture can't be opened.")),
}
}
@@ -584,7 +586,7 @@ impl Reference {
ui.painter(),
button.center(),
Align2::CENTER_CENTER,
- "Import Image",
+ tr("Import Image"),
16.0,
Weight::Regular,
argb(MUTED),
@@ -626,7 +628,7 @@ impl Reference {
painter,
pos2(bar.left() + 20.0, bar.top() + 24.0),
Align2::LEFT_CENTER,
- "Reference",
+ tr("Reference"),
22.0,
Weight::Bold,
argb(TITLE),
@@ -656,7 +658,7 @@ impl Reference {
}
if self.mode == Mode::Image && self.image.is_some() {
let mut right = left_of - 6.0;
- for (label, id) in [("Import", "import"), ("Clear", "clear")] {
+ for (label, id) in [(tr("Import"), "import"), (tr("Clear"), "clear")] {
let shown = text(
ui.painter(),
pos2(right, bar.center().y),
@@ -687,7 +689,7 @@ impl Reference {
ui.interact(bottom.intersect(window), ui.scope_id().with("bottom bar"), Sense::click_and_drag());
let track = Rect::from_center_size(bottom.center(), vec2(270.0, 35.0));
ui.painter().rect_filled(track, 17.5, argb(SEGMENT_TRACK));
- let mut kinds = vec![(Mode::Canvas, "Canvas"), (Mode::Image, "Image")];
+ let mut kinds = vec![(Mode::Canvas, tr("Canvas")), (Mode::Image, tr("Image"))];
if session.model_info().is_some() && self.index == 0 {
kinds.push((Mode::Model, "3D"));
}
diff --git a/desktop/src/screen.rs b/desktop/src/screen.rs
index f1c3ae61a..c53afaaed 100644
--- a/desktop/src/screen.rs
+++ b/desktop/src/screen.rs
@@ -174,13 +174,16 @@ impl Screen {
/// [`Screen::new`] on backend `backend`; one that isn't the `last` to try fails on any GPU
/// error, a lost device or a surface it can't show.
fn on(window: &Arc, display: &OwnedDisplayHandle, backend: usize, last: bool) -> Result {
+ use procraft_core::{tr, trf};
+
// each stage timed in the log: on a slow driver, where a start stopped shows
let ms = |since: Instant| since.elapsed().as_millis();
let window = Arc::clone(window);
let started = Instant::now();
- let instance =
- Gpu::instance_for_display(backend, Box::new(display.clone())).ok_or("no such graphics backend")?;
- let surface = instance.create_surface(Arc::clone(&window)).map_err(|e| format!("the window's surface: {e}"))?;
+ let instance = Gpu::instance_for_display(backend, Box::new(display.clone()))
+ .ok_or_else(|| tr("no such graphics backend"))?;
+ let surface =
+ instance.create_surface(Arc::clone(&window)).map_err(|e| trf("the window's surface: {0}", &[("0", &e)]))?;
log::info!("the backend's instance and the window's surface made in {} ms", ms(started));
let gpu = Gpu::for_surface(instance, &surface).map_err(|e| e.to_string())?;
procraft_core::keep_device(&gpu);
@@ -189,14 +192,17 @@ impl Screen {
let config = configure(&gpu, &surface, (size.width, size.height), INTERFACE_WIDE);
log::info!("the window's surface set up in {} ms", ms(configured));
if !last && config.is_none() {
- return Err("the window's surface couldn't be set up".to_owned());
+ return Err(tr("the window's surface couldn't be set up").to_owned());
}
let format = config.as_ref().map_or(wgpu::TextureFormat::Bgra8Unorm, |c| c.format);
let interface = Instant::now();
let renderer = egui_wgpu::Renderer::new(&gpu.device, format, egui_wgpu::RendererOptions::default());
log::info!("the interface's pipelines made in {} ms", ms(interface));
if !last && (gpu.errors() > 0 || gpu.is_lost()) {
- return Err(format!("the interface's pipelines: {} GPU errors, lost {}", gpu.errors(), gpu.is_lost()));
+ return Err(trf(
+ "the interface's pipelines: {0} GPU errors, lost {1}",
+ &[("0", &gpu.errors()), ("1", &gpu.is_lost())],
+ ));
}
let ctx = egui::Context::default();
// Ctrl (⌘) with + - 0 zoom the canvas (the interface's shortcuts), not the whole interface
diff --git a/desktop/src/selection.rs b/desktop/src/selection.rs
index 017def354..d15bc8299 100644
--- a/desktop/src/selection.rs
+++ b/desktop/src/selection.rs
@@ -4,6 +4,8 @@
//! dragged out and the freehand path, dashed; the crosshair and the bar while a colour
//! selection's threshold is slid). The shared touches make the selections.
+use procraft_core::tr;
+
use std::collections::HashMap;
use egui::{
@@ -241,21 +243,23 @@ impl Selection {
})
.collect();
let mut buttons = vec![
- Button::new(&icons::SELECT_ADD, "Add", 44.0).active(!removable || !self.removes),
- Button::new(&icons::SELECT_REMOVE, "Remove", 44.0).active(removable && self.removes).enabled(removable),
- Button::new(&icons::INVERT, "Invert", 44.0).enabled(has),
- Button::new(&icons::SELECT_COPY_PASTE, "Copy & Paste", 44.0).enabled(has || drawing),
- Button::new(&icons::FEATHER, "Feather", 44.0).active(self.popup == Popup::Feather).enabled(has || drawing),
- Button::new(&icons::SAVE_LOAD, "Save & Load", 44.0)
+ Button::new(&icons::SELECT_ADD, tr("Add"), 44.0).active(!removable || !self.removes),
+ Button::new(&icons::SELECT_REMOVE, tr("Remove"), 44.0).active(removable && self.removes).enabled(removable),
+ Button::new(&icons::INVERT, tr("Invert"), 44.0).enabled(has),
+ Button::new(&icons::SELECT_COPY_PASTE, tr("Copy & Paste"), 44.0).enabled(has || drawing),
+ Button::new(&icons::FEATHER, tr("Feather"), 44.0)
+ .active(self.popup == Popup::Feather)
+ .enabled(has || drawing),
+ Button::new(&icons::SAVE_LOAD, tr("Save & Load"), 44.0)
.active(self.popup == Popup::Saved)
.enabled(has || drawing),
- Button::new(&icons::COLOR_FILL, "Color Fill", 37.0).active(self.color_fill),
+ Button::new(&icons::COLOR_FILL, tr("Color Fill"), 37.0).active(self.color_fill),
];
// on a model: a selection reaches every surface under it
if model {
- buttons.push(Button::new(&icons::X_RAY, "X-Ray", 44.0).active(session.selection_x_ray()));
+ buttons.push(Button::new(&icons::X_RAY, tr("X-Ray"), 44.0).active(session.selection_x_ray()));
}
- buttons.push(Button::new(&icons::CLEAR_SELECTION, "Clear", 44.0).enabled(has || drawing));
+ buttons.push(Button::new(&icons::CLEAR_SELECTION, tr("Clear"), 44.0).enabled(has || drawing));
let tapped = floating_toolbar(ctx, look, "selection toolbar", BUTTON_ROOMY, &segments, &buttons, 41.0);
match tapped {
Some(Tapped::Background) => self.set_popup(session, Popup::None),
@@ -355,7 +359,7 @@ impl Selection {
ui.painter().rect_filled(group, 13, argb(MENU_GROUP));
let amount = self.feather;
let shown =
- if amount <= 0.0 { "None".to_owned() } else { format!("{}%", (amount * 100.0).round() as i32) };
+ if amount <= 0.0 { tr("None").to_owned() } else { format!("{}%", (amount * 100.0).round() as i32) };
let row = Rect::from_min_size(group.min + vec2(0.0, 8.0), vec2(group.width(), 59.0));
let (value, let_go) = menu_slider_let_go(ui, row, "Amount", amount, &shown);
if let Some(v) = value {
@@ -374,7 +378,7 @@ impl Selection {
ui.painter(),
pos2(inner.left() + 14.0, inner.top() + 20.0),
Align2::LEFT_CENTER,
- "Selections",
+ tr("Selections"),
24.0,
Weight::Bold,
ink,
@@ -426,7 +430,7 @@ impl Selection {
&painter,
delete.center(),
Align2::CENTER_CENTER,
- "Delete",
+ tr("Delete"),
15.0,
Weight::Regular,
Color32::WHITE,
@@ -452,7 +456,7 @@ impl Selection {
egui::epaint::RectShape::filled(shown, corners, Color32::WHITE).with_texture(t.id(), uv);
painter.add(picture);
}
- let label = format!("Selection {}", i + 1);
+ let label = procraft_core::trf("Selection {0}", &[("0", &(i + 1))]);
text(
&painter,
pos2(thumb.right() + 14.0, row.center().y),
@@ -557,7 +561,10 @@ impl Selection {
let screen = ctx.content_rect();
let band = Rect::from_min_size(pos2(screen.left(), bar_top), vec2(screen.width(), 24.0));
painter.rect_filled(band, 0, argb(MESSAGE_BAR));
- let reading = format!("Selection Threshold {:.1}%", (threshold * 1000.0).round() / 10.0);
+ let reading = procraft_core::trf(
+ "Selection Threshold {0}%",
+ &[("0", &format_args!("{:.1}", (threshold * 1000.0).round() / 10.0))],
+ );
text(&painter, band.center(), Align2::CENTER_CENTER, &reading, 14.0, Weight::Regular, argb(MESSAGE_TEXT));
}
}
diff --git a/desktop/src/settings.rs b/desktop/src/settings.rs
index f8af9d610..21ca0a590 100644
--- a/desktop/src/settings.rs
+++ b/desktop/src/settings.rs
@@ -5,6 +5,8 @@
//! feedback sounds and tap assistance; and, on a computer of several GPUs, which to draw with.
//! Kept with the Prefs tab's.
+use procraft_core::tr;
+
use crate::scroll::ScrollArea;
use egui::{Align2, Color32, Id, Order, Rect, Sense, Stroke, UiBuilder, Vec2, pos2, vec2};
@@ -87,60 +89,68 @@ const GROUPS: [(&str, &[Row]); 5] = [
&[
Row::Toggle(
Setting::OrientationMemory,
- "Canvas Orientation Memory",
- "An artwork opens zoomed and turned as it was left.",
+ procraft_core::message!("Canvas Orientation Memory"),
+ procraft_core::message!("An artwork opens zoomed and turned as it was left."),
),
Row::Toggle(
Setting::FitInside,
- "Fit Canvas Inside Interface",
- "A fitted canvas keeps clear of the top bar and the sidebar.",
+ procraft_core::message!("Fit Canvas Inside Interface"),
+ procraft_core::message!("A fitted canvas keeps clear of the top bar and the sidebar."),
),
],
),
(
"",
&[
- Row::Toggle(Setting::NoTimeLapse, "Disable Time-lapse", "New artworks don't record their time-lapse."),
+ Row::Toggle(
+ Setting::NoTimeLapse,
+ procraft_core::message!("Disable Time-lapse"),
+ procraft_core::message!("New artworks don't record their time-lapse."),
+ ),
Row::Toggle(
Setting::SimplifiedUndos,
- "Simplified Undos",
- "Strokes made in an adjustment undo together once it is left.",
+ procraft_core::message!("Simplified Undos"),
+ procraft_core::message!("Strokes made in an adjustment undo together once it is left."),
),
],
),
(
- "Maximum Speed Distance",
- &[Row::SpeedDistance("How far the pen moves before a brush's speed dynamics count it as fast.")],
+ procraft_core::message!("Maximum Speed Distance"),
+ &[Row::SpeedDistance(procraft_core::message!(
+ "How far the pen moves before a brush's speed dynamics count it as fast."
+ ))],
),
(
- "Drag and Drop export",
+ procraft_core::message!("Drag and Drop export"),
&[
- Row::Choice(Pick::DragFormat, "Preferred file format"),
- Row::Choice(Pick::DragImageFormat, "Preferred image format"),
+ Row::Choice(Pick::DragFormat, procraft_core::message!("Preferred file format")),
+ Row::Choice(Pick::DragImageFormat, procraft_core::message!("Preferred image format")),
],
),
(
- "Accessibility",
+ procraft_core::message!("Accessibility"),
&[
Row::Toggle(
Setting::TouchCompanion,
- "Single Touch Gestures Companion",
- "A floating bar of undo, redo, zoom, move and fit for one finger.",
+ procraft_core::message!("Single Touch Gestures Companion"),
+ procraft_core::message!("A floating bar of undo, redo, zoom, move and fit for one finger."),
),
Row::Toggle(
Setting::ColourNames,
- "Color Description Notifications",
- "A message names the colour once it stops changing.",
+ procraft_core::message!("Color Description Notifications"),
+ procraft_core::message!("A message names the colour once it stops changing."),
),
Row::Toggle(
Setting::FeedbackSounds,
- "Feedback Sounds",
- "Undo, redo, tools and panels click as they are used.",
+ procraft_core::message!("Feedback Sounds"),
+ procraft_core::message!("Undo, redo, tools and panels click as they are used."),
),
Row::Toggle(
Setting::TapAssistance,
- "Tap Assistance - Initial Touch Location Support",
- "A tap lands where the finger first touched, even if it drifts before lifting.",
+ procraft_core::message!("Tap Assistance - Initial Touch Location Support"),
+ procraft_core::message!(
+ "A tap lands where the finger first touched, even if it drifts before lifting."
+ ),
),
],
),
@@ -178,12 +188,20 @@ pub fn show(ctx: &egui::Context, prefs: &mut Prefs) -> Option {
ui.add_space(MARGIN);
let (title, _) = ui.allocate_exact_size(vec2(width, 36.0), Sense::hover());
let inner = title.shrink2(vec2(MARGIN, 0.0));
- text(ui.painter(), inner.left_center(), Align2::LEFT_CENTER, "ProCraft", 30.0, Weight::Bold, argb(INK));
+ text(
+ ui.painter(),
+ inner.left_center(),
+ Align2::LEFT_CENTER,
+ tr("ProCraft"),
+ 30.0,
+ Weight::Bold,
+ argb(INK),
+ );
let done = text(
ui.painter(),
inner.right_center() - vec2(8.0, 0.0),
Align2::RIGHT_CENTER,
- "Done",
+ tr("Done"),
17.0,
Weight::Regular,
argb(BLUE),
@@ -194,7 +212,7 @@ pub fn show(ctx: &egui::Context, prefs: &mut Prefs) -> Option {
for (k, (heading, rows)) in GROUPS.iter().enumerate() {
ui.add_space(24.0);
let (h, _) = ui.allocate_exact_size(vec2(width, 16.0), Sense::hover());
- let words = heading.to_uppercase();
+ let words = tr(heading).to_uppercase();
text(
ui.painter(),
h.left_center() + vec2(MARGIN + 16.0, 0.0),
@@ -240,7 +258,7 @@ pub fn show(ctx: &egui::Context, prefs: &mut Prefs) -> Option {
ui.painter(),
pos2(row.left() + 16.0, cy),
Align2::LEFT_CENTER,
- "Licenses",
+ tr("Licenses"),
17.0,
Weight::Regular,
argb(INK),
@@ -267,8 +285,8 @@ pub fn show(ctx: &egui::Context, prefs: &mut Prefs) -> Option