Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Preview, Get System and the Scheduler's "when done" drop-down fit their translated text (#247)

Ahmed Nefzaouif536573332c8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1e1642af..5524c28c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -529,6 +529,13 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- **Three more controls fit their translated text**
+ ([#192](https://github.com/anefzaoui/misterdownloadmanager/issues/192), after #212): in Russian
+ and a few other languages, Download File Info's **Preview**, Options → Proxy's **Get System**
+ and the Scheduler's drop-down after **Turn off computer when done** still ended in "...".
+ Download File Info grows by what Preview's label needs (Russian, Ukrainian, Telugu, Belarusian
+ and a few more), the Proxy page's title moves left to give Get System its room, and the
+ Scheduler's drop-down widens towards its caption. English is unchanged.
- **A menu shut with Escape opens again at the first click on its title**: a menu opened from
the menu bar and shut with Escape, the pointer still on its title, was left marked open. On
Linux the next click on that title only "shut" it, and a second click was needed; on Windows
diff --git a/ROADMAP.md b/ROADMAP.md
index 14660a62..5b82455b 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -13,6 +13,9 @@ Everything below ships together, in one release, as version 0.3.0.
### Done
+- ✅ Download File Info's Preview, Options → Proxy's Get System and the Scheduler's "when done"
+ drop-down fit their translated text (Russian and others), after #212
+ ([#192](https://github.com/anefzaoui/misterdownloadmanager/issues/192))
- ✅ A menu of the menu bar shut with Escape opens again at the first click on its title (on
Linux it took two; on Windows, Escape with the pointer on the title left the menu open)
- ✅ Cookies for video sites: yt-dlp can read a browser's cookies on this computer (Firefox,
diff --git a/crates/app/src/dialogs.rs b/crates/app/src/dialogs.rs
index 51f1ac66..a30ef6b7 100644
--- a/crates/app/src/dialogs.rs
+++ b/crates/app/src/dialogs.rs
@@ -937,11 +937,22 @@ impl FileInfo {
// The "Download through" line (#44) takes a row of its own while an account takes the
// address: the window grows by it.
let dy = if self.through.is_some() { 26.0 } else { 0.0 };
+ // Preview has 92 px for its label in this language (#192), from 8 px after the group box
+ // (it ends at 462) to the window's edge (562): where it needs more, the window grows by it
+ // and the right column (icon, size, Preview) widens, its centre moving by half of it.
+ let preview_w = winui::button_fit_width(
+ &ctx.layer_painter(egui::LayerId::background()),
+ "Preview",
+ 73.0,
+ f32::INFINITY,
+ );
+ let wide = (preview_w - 92.0).max(0.0);
+ let cx = (wide / 2.0).floor();
window(
ctx,
"file-info",
"Download File Info",
- [570.0, 234.0 + dy],
+ [570.0 + wide, 234.0 + dy],
true,
winui::BG(),
|ui, o| {
@@ -1243,7 +1254,7 @@ impl FileInfo {
Some(0),
);
- // Right column, centred on x ≈ 516: file icon, size, Preview.
+ // Right column, centred on x ≈ 516 (+ cx): file icon, size, Preview.
// The shell's own 32 px icon for this file type, as IDM shows.
let ext = Path::new(&self.save_as)
.extension()
@@ -1252,7 +1263,7 @@ impl FileInfo {
icons.paint(
ui,
crate::chrome::IconKey::ExtLarge(ext),
- o + vec2(500.0, 45.0),
+ o + vec2(500.0 + cx, 45.0),
);
let (size, reason) = match &self.info {
None => ("...".to_owned(), None),
@@ -1266,14 +1277,21 @@ impl FileInfo {
Some(Err(e)) => (crate::i18n::t("Error").to_owned(), Some(e.clone())),
};
let w = winui::text_width(&p, &size);
- let at = winui::text(&p, o.x + 515.0 - w / 2.0, o.y + 103.0, &size, winui::TEXT());
+ let at = winui::text(
+ &p,
+ o.x + 515.0 + cx - w / 2.0,
+ o.y + 103.0,
+ &size,
+ winui::TEXT(),
+ );
// Why the address didn't answer (not found, sign-in needed…): on hover, copyable.
if let Some(reason) = reason {
winui::copyable(ui, at, "file-info-error", &reason, true);
}
// As wide as its label in this language (#192), around the column's centre, from
- // the folder box (it ends at 452) to the window's edge.
- let (px, pw) = winui::button_around(&p, "Preview", 480.0, 73.0, 460.0, 562.0);
+ // 8 px after the group box (it ends at 462) to the window's edge.
+ let (px, pw) =
+ winui::button_around(&p, "Preview", 480.0 + cx, 73.0, 470.0, 562.0 + wide);
winui::button(
ui,
r(o, px, 128.0, pw, 21.0),
diff --git a/crates/app/src/options.rs b/crates/app/src/options.rs
index 97c5fb38..ac1e5439 100644
--- a/crates/app/src/options.rs
+++ b/crates/app/src/options.rs
@@ -1331,24 +1331,33 @@ impl OptionsDialog {
Icon::PageProxy
.image(true)
.paint_at(ui, r(o, 21.0, 50.0, 32.0, 32.0));
- page_title(
- &p,
- winui::tahoma_bold(),
- o.x + 112.0,
- o.y + 69.0,
- "Proxy / socks configuration",
- );
- // As wide as its label in this language (#192), short of the title (a translated title
- // ends where the English one does).
- let title_end =
+ // Get System as wide as its label in this language (#192), its right end kept. A
+ // translated title ends where the English one does, unless the button needs that room:
+ // then the title moves left (no further than 8 px after the icon) and ends 8 px before it.
+ let english_end =
112.0 + winui::text_width_font(&p, winui::tahoma_bold(), "Proxy / socks configuration");
- let (get_x, get_w) = winui::button_row(
- &p,
- &[("Get System", 307.0, 93.0)],
- 0.0,
- title_end + 8.0,
- 160.0,
- )[0];
+ let title_w = page_title_width(&p, winui::tahoma_bold(), "Proxy / socks configuration");
+ // The icon ends at 53; the button never moves right of its English place.
+ let from = (53.0 + 8.0 + title_w + 8.0).min(307.0);
+ let (get_x, get_w) =
+ winui::button_row(&p, &[("Get System", 307.0, 93.0)], 0.0, from, 160.0)[0];
+ if get_x - 8.0 < english_end {
+ page_title_ending(
+ &p,
+ winui::tahoma_bold(),
+ o.x + get_x - 8.0,
+ o.y + 69.0,
+ "Proxy / socks configuration",
+ );
+ } else {
+ page_title(
+ &p,
+ winui::tahoma_bold(),
+ o.x + 112.0,
+ o.y + 69.0,
+ "Proxy / socks configuration",
+ );
+ }
let s = &mut self.s;
if winui::button_light(
ui,
@@ -3661,6 +3670,24 @@ fn page_title(p: &egui::Painter, font: egui::FontId, x: f32, baseline: f32, engl
winui::text_font(p, font, x, baseline, shown, LIGHT_TEXT());
}
+/// How wide [`page_title`] draws `english` translated.
+fn page_title_width(p: &egui::Painter, font: egui::FontId, english: &str) -> f32 {
+ winui::text_width_font(p, font, crate::i18n::t(english))
+}
+
+/// [`page_title`] ending at English x `end` (a control after it needs the room up to there).
+fn page_title_ending(
+ p: &egui::Painter,
+ font: egui::FontId,
+ end: f32,
+ baseline: f32,
+ english: &str,
+) {
+ let shown = crate::i18n::t(english);
+ let x = end - winui::text_width_font(p, font.clone(), shown);
+ winui::text_font(p, font, x, baseline, shown, LIGHT_TEXT());
+}
+
/// Group box (`#dcdcdc` frame) with its caption (translated here) at x + 9.
fn group(ui: &Ui, o: Pos2, x: f32, y: f32, w: f32, h: f32, caption: &str) {
let p = ui.painter();
diff --git a/crates/app/src/scheduler.rs b/crates/app/src/scheduler.rs
index c4d8e6cd..7cdf77c4 100644
--- a/crates/app/src/scheduler.rs
+++ b/crates/app/src/scheduler.rs
@@ -824,17 +824,23 @@ impl Scheduler {
"Exit Mister Download Manager when done",
true,
);
+ // The drop-down as wide as its choices in this language need (#192), widening to the
+ // left (its right end kept), up to 8 px after the caption, which stays whole.
+ let caption_end = winui::checkbox_caption_end(&p, 228.0, "Turn off computer when done");
+ let turn_off_w =
+ winui::combo_fit_width(&p, &TurnOff::LABELS, 119.0, 627.0 - (caption_end + 8.0));
+ let turn_off_x = 627.0 - turn_off_w;
winui::checkbox_light_until(
ui,
at(228.0, 384.0 + DY),
&mut f.turn_off_on,
"Turn off computer when done",
true,
- Some(o.x + 508.0),
+ Some(o.x + turn_off_x),
);
if let Some(i) = winui::combo_light(
ui,
- r(o, 508.0, 383.0 + DY, 119.0, 21.0),
+ r(o, turn_off_x, 383.0 + DY, turn_off_w, 21.0),
&TurnOff::LABELS,
f.turn_off,
f.turn_off_on,
diff --git a/crates/app/src/winui.rs b/crates/app/src/winui.rs
index d794aa03..a09ad9c3 100644
--- a/crates/app/src/winui.rs
+++ b/crates/app/src/winui.rs
@@ -2596,6 +2596,26 @@ pub fn button_fit_width(p: &Painter, label: &str, min: f32, max: f32) -> f32 {
label_width(p, label, min).clamp(min, max.max(min))
}
+/// The English x where the translated `caption` of a checkbox whose glyph is at English x `x`
+/// ends ([`checkbox_light_until`]'s caption starts 16 px after its glyph): what a control after
+/// it may come up to.
+pub fn checkbox_caption_end(p: &Painter, x: f32, caption: &str) -> f32 {
+ x + 16.0 + text_width(p, crate::i18n::t(caption))
+}
+
+/// How wide a [`combo_light`] must be for each of its translated `items` to show whole before
+/// its chevron (the widest decides, so the box keeps its size as the choice changes): at least
+/// `min` (its English width: English items fit it, so English never changes), at most `max`
+/// (past it the choice ends in "..." and shows whole on hover, as before).
+pub fn combo_fit_width(p: &Painter, items: &[&str], min: f32, max: f32) -> f32 {
+ let widest = items
+ .iter()
+ .map(|item| text_width_font(p, tahoma(), crate::i18n::t(item)))
+ .fold(0.0, f32::max);
+ // combo_light's room for its label: 5 px before it, 19 px for the chevron after it.
+ (widest + 5.0 + 19.0).ceil().clamp(min, max.max(min))
+}
+
/// The width a [`button`] `english` px wide wants for its translated `label`: the label and the
/// room inside the border; no wider than `english` where the label shows whole in it (a label
/// that fits as tightly as some English ones do keeps the button as it is), and narrower where the
@@ -5610,6 +5630,24 @@ mod tests {
});
}
+ #[test]
+ fn a_drop_down_is_as_wide_as_its_widest_choice() {
+ with_painter(|p| {
+ // Short choices: its English width.
+ assert_eq!(
+ combo_fit_width(p, &["Sleep", "Hibernate"], 119.0, 300.0),
+ 119.0
+ );
+ // A long one: it and the chevron's room, whichever is chosen.
+ let long = "A choice much longer than its English box";
+ let want = (text_width(p, long) + 24.0).ceil();
+ assert_eq!(combo_fit_width(p, &["Sleep", long], 119.0, 300.0), want);
+ // No room for it: as wide as there is (it ends in "..."), never below English.
+ assert_eq!(combo_fit_width(p, &[long], 119.0, 150.0), 150.0);
+ assert_eq!(combo_fit_width(p, &[long], 119.0, 80.0), 119.0);
+ });
+ }
+
#[test]
fn a_row_from_the_left_widens_to_the_right() {
with_painter(|p| {
diff --git a/tools/i18n/extract.py b/tools/i18n/extract.py
index 7ee97762..c0862325 100644
--- a/tools/i18n/extract.py
+++ b/tools/i18n/extract.py
@@ -59,6 +59,9 @@ SINKS = {
"why_disabled": (2, ""),
# A button's width measured for its label (winui::button_fit_width): the label of a button.
"button_fit_width": (1, ""),
+ # Where a checkbox's caption ends (winui::checkbox_caption_end); a page title's width and the
+ # title ending before a control (options.rs).
+ "checkbox_caption_end": (2, ""), "page_title_width": (2, ""), "page_title_ending": (4, ""),
}
SINK_CALL = re.compile(
r"\b(?:winui::|MenuEntry::|crate::i18n::|i18n::)?(" + "|".join(SINKS) + r")\s*\(")
@@ -93,6 +96,8 @@ ROLES = {
"tn": "count", "link": "link (opens a web page)", "header": "page title",
"group": "group box title", "disabled_label": "label", "page_title": "page title",
"why_disabled": "tooltip (why a control is greyed)", "button_fit_width": "button",
+ "checkbox_caption_end": "checkbox", "page_title_width": "page title",
+ "page_title_ending": "page title",
}
CONTEXT_ROLES = {
"menu": "menu command", "toolbar": "toolbar button", "column": "column title",