Skip to content

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

Buttons fit their translated text in every window (#192) (#212)

Ahmed Nefzaouib563166081d3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cba0f92a..e9a13704 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -504,6 +504,16 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- **Buttons fit their text in every language, in every window**
+ ([#192](https://github.com/anefzaoui/misterdownloadmanager/issues/192)): many windows gave
+ their buttons a width made for English, so a longer translation was cut with "..." (German
+ **Später herunterla...** in Download File Info, **Hilfsprogramme...** in Download a gallery,
+ Russian **Открыть с помощью...** in Download complete, French **Nouvelle file d’attente** in the
+ Scheduler). Each button is now as wide as its translated text, and the buttons beside it move
+ along with the same gaps, the row keeping its end; a box or caption beside a widened button
+ ends before it. Where a window has no room left, the buttons wider than their text give some
+ back first. English is unchanged, and in Arabic and the other right-to-left languages the
+ buttons widen the mirrored way.
- **Help opens the website's help pages, in your language**
([#227](https://github.com/anefzaoui/misterdownloadmanager/issues/227)): **Help contents**,
**Tutorials**, **Scheduler and queues**, **Video downloads**, the **Help** buttons of Options and
diff --git a/ROADMAP.md b/ROADMAP.md
index 06baa5cf..dd5fc970 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -13,6 +13,11 @@ Everything below ships together, in one release, as version 0.3.0.
### Done
+- ✅ Every window's buttons fit their text in every language: Download File Info (German
+ **Später herunterladen** was cut), Download complete, Add torrent, Download a gallery, the
+ progress window, the Scheduler, Options, the Help menu's windows, RSS feeds, the video helpers
+ and the browser window; English is unchanged, right to left too
+ ([#192](https://github.com/anefzaoui/misterdownloadmanager/issues/192))
- ✅ Linux builds and window shots in minutes: a WSL2 machine builds any branch in about 5
minutes (under one after a change) and shoots every window in any language in about a second
each, never showing on the screen; the Linux desktops still check what needs them (part of
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index eb2d5eb4..0d7c1eda 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -1775,6 +1775,20 @@ impl App {
"extension" => self.extension = Some(crate::extension::Extension::new()),
"language" => self.run(Cmd::ChooseLanguage, None, ctx),
"shortcuts" => self.run(Cmd::Shortcuts, None, ctx),
+ // The Help menu's windows and Download a gallery, for screenshots (#192). updates
+ // asks GitHub, as Help → Check for updates does.
+ "tell-friend" => self.run(Cmd::TellFriend, None, ctx),
+ "updates" => self.run(Cmd::CheckUpdates, None, ctx),
+ "checksum" if first.is_some() => self.run(Cmd::VerifyChecksum, first, ctx),
+ "gallery" => {
+ let dir = self
+ .settings
+ .category_dir(Category::General, &self.downloads);
+ self.gallery_dlg = Some(crate::gallerydlg::GalleryDialog::new(
+ dir,
+ "https://commons.wikimedia.org/wiki/Category:Sunsets",
+ ));
+ }
"speedlimit" => self.run(Cmd::LimiterSettings, None, ctx),
"properties" if first.is_some() => self.run(Cmd::Properties, first, ctx),
"delete" if first.is_some() => self.run(Cmd::Remove, first, ctx),
@@ -1866,6 +1880,8 @@ impl App {
if tab == "panels" {
self.options = self.options.take().map(|o| o.with_panels());
}
+ // A window over a page (screenshots, #192): options:test, options:account.
+ self.options = self.options.take().map(|o| o.with_window(tab));
}
_ => {}
}
diff --git a/crates/app/src/categories.rs b/crates/app/src/categories.rs
index 94f98445..75b4b977 100644
--- a/crates/app/src/categories.rs
+++ b/crates/app/src/categories.rs
@@ -121,16 +121,19 @@ impl CategoryDialog {
"category-types-hint",
);
label(112.0, crate::i18n::mark("Folder:"));
+ // Browse as wide as its label in this language (#192); the box ends 8 px before.
+ let (browse_x, browse_w) =
+ winui::buttons_to_right(&p, 408.0, 8.0, &[("Browse...", 73.0)], 160.0)[0];
winui::edit_light(
ui,
- r(o, 98.0, 98.0, 229.0, 23.0),
+ r(o, 98.0, 98.0, browse_x - 8.0 - 98.0, 23.0),
&mut self.folder,
true,
false,
);
if winui::button_light(
ui,
- r(o, 335.0, 99.0, 73.0, 21.0),
+ r(o, browse_x, 99.0, browse_w, 21.0),
"Browse...",
ButtonKind::Normal,
false,
diff --git a/crates/app/src/checksum.rs b/crates/app/src/checksum.rs
index c35f8cbe..a22f3fa2 100644
--- a/crates/app/src/checksum.rs
+++ b/crates/app/src/checksum.rs
@@ -177,8 +177,23 @@ impl ChecksumDialog {
} else {
(crate::i18n::mark("OK"), crate::i18n::mark("Cancel"))
};
- let go =
- winui::button_light(ui, r(o, 265.0, 87.0, 73.0, 21.0), primary, kind, false);
+ // As wide as their labels in this language (#192).
+ let [go_at, close_at] = winui::buttons_to_right(
+ &p,
+ 419.0,
+ 8.0,
+ &[(primary, 73.0), (secondary, 73.0)],
+ 160.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
+ let go = winui::button_light(
+ ui,
+ r(o, go_at.0, 87.0, go_at.1, 21.0),
+ primary,
+ kind,
+ false,
+ );
let go = winui::why_disabled(
go,
!valid,
@@ -193,7 +208,7 @@ impl ChecksumDialog {
.clicked();
let close = winui::button_light(
ui,
- r(o, 346.0, 87.0, 73.0, 21.0),
+ r(o, close_at.0, 87.0, close_at.1, 21.0),
secondary,
ButtonKind::Normal,
false,
diff --git a/crates/app/src/dialogs.rs b/crates/app/src/dialogs.rs
index ee122494..8543d1b4 100644
--- a/crates/app/src/dialogs.rs
+++ b/crates/app/src/dialogs.rs
@@ -1184,9 +1184,24 @@ impl FileInfo {
} else {
(ButtonKind::Normal, ButtonKind::Default)
};
+ // The row as wide as its labels in this language need (#192), ending where it
+ // ends in English.
+ let [later_at, start_at, cancel_at] = winui::button_row(
+ &p,
+ &[
+ ("Download Later", 97.0, 109.0),
+ ("Start Download", 225.0, 109.0),
+ ("Cancel", 352.0, 109.0),
+ ],
+ 19.0,
+ 11.0,
+ 200.0,
+ )[..] else {
+ unreachable!("three buttons")
+ };
let later = winui::button(
ui,
- r(o, 97.0, 206.0 + dy, 109.0, 21.0),
+ r(o, later_at.0, 206.0 + dy, later_at.1, 21.0),
"Download Later",
later_kind,
false,
@@ -1195,7 +1210,7 @@ impl FileInfo {
let later = winui::why_disabled(later, blocked.is_some(), blocked.unwrap_or(""));
let start = winui::button(
ui,
- r(o, 225.0, 206.0 + dy, 109.0, 21.0),
+ r(o, start_at.0, 206.0 + dy, start_at.1, 21.0),
"Start Download",
start_kind,
true,
@@ -1204,7 +1219,7 @@ impl FileInfo {
let start = winui::why_disabled(start, blocked.is_some(), blocked.unwrap_or(""));
let cancel = winui::button(
ui,
- r(o, 352.0, 206.0 + dy, 109.0, 21.0),
+ r(o, cancel_at.0, 206.0 + dy, cancel_at.1, 21.0),
"Cancel",
ButtonKind::Normal,
false,
@@ -1239,9 +1254,12 @@ impl FileInfo {
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);
winui::button(
ui,
- r(o, 480.0, 128.0, 73.0, 21.0),
+ r(o, px, 128.0, pw, 21.0),
// i18n: verb: open the part already downloaded
"Preview",
ButtonKind::Disabled,
@@ -1415,15 +1433,31 @@ impl Complete {
"complete-saved",
);
- let btn = |ui: &mut Ui, x: f32, label: &str, kind| {
- winui::button(ui, r(o, x, 157.0, 90.0, 21.0), label, kind, false, None)
+ let btn = |ui: &mut Ui, (x, w): (f32, f32), label: &str, kind| {
+ winui::button(ui, r(o, x, 157.0, w, 21.0), label, kind, false, None)
+ };
+ // As wide as their labels in this language (#192): a longer one pushes those
+ // after it right, Close last at the window's edge.
+ let [open_at, with_at, folder_at, close_at] = winui::button_row_from_left(
+ &p,
+ &[
+ ("Open", 12.0, 90.0),
+ ("Open with...", 115.0, 90.0),
+ ("Open folder", 219.0, 90.0),
+ ("Close", 354.0, 90.0),
+ ],
+ 13.0,
+ 444.0,
+ 200.0,
+ )[..] else {
+ unreachable!("four buttons")
};
// i18n: verb: opens the downloaded file
- let open = btn(ui, 12.0, "Open", ButtonKind::Default);
- let with = btn(ui, 115.0, "Open with...", ButtonKind::Normal);
- let folder = btn(ui, 219.0, "Open folder", ButtonKind::Normal);
+ let open = btn(ui, open_at, "Open", ButtonKind::Default);
+ let with = btn(ui, with_at, "Open with...", ButtonKind::Normal);
+ let folder = btn(ui, folder_at, "Open folder", ButtonKind::Normal);
// i18n: verb: closes this window
- let close = btn(ui, 354.0, "Close", ButtonKind::Normal);
+ let close = btn(ui, close_at, "Close", ButtonKind::Normal);
winui::checkbox(
ui,
o + vec2(24.0, 191.0),
@@ -1870,9 +1904,20 @@ impl TurnOffCountdown {
)],
);
winui::text(&p, o.x + 11.0, o.y + 34.0, &line, black);
+ // As wide as their labels in this language (#192): a longer one pushes Cancel
+ // right.
+ let [now_at, cancel_at] = winui::button_row_from_left(
+ &p,
+ &[("Turn off now", 94.0, 90.0), ("Cancel", 194.0, 73.0)],
+ 10.0,
+ 363.0,
+ 200.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
let now = winui::button_light(
ui,
- r(o, 94.0, 63.0, 90.0, 21.0),
+ r(o, now_at.0, 63.0, now_at.1, 21.0),
"Turn off now",
ButtonKind::Normal,
false,
@@ -1880,7 +1925,7 @@ impl TurnOffCountdown {
.clicked();
let cancel = winui::button_light(
ui,
- r(o, 194.0, 63.0, 73.0, 21.0),
+ r(o, cancel_at.0, 63.0, cancel_at.1, 21.0),
"Cancel",
ButtonKind::Default,
false,
@@ -2494,10 +2539,20 @@ impl DeleteCategory {
{
self.remove = true;
}
+ // As wide as their labels in this language (#192).
+ let [delete_at, cancel_at] = winui::buttons_to_right(
+ &p,
+ 488.0,
+ 8.0,
+ &[("Delete", 73.0), ("Cancel", 73.0)],
+ 140.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
// i18n: button: deletes the category
let delete = winui::button_light(
ui,
- r(o, 334.0, 118.0, 73.0, 21.0),
+ r(o, delete_at.0, 118.0, delete_at.1, 21.0),
"Delete",
ButtonKind::Default,
false,
@@ -2505,7 +2560,7 @@ impl DeleteCategory {
.clicked();
let cancel = winui::button_light(
ui,
- r(o, 415.0, 118.0, 73.0, 21.0),
+ r(o, cancel_at.0, 118.0, cancel_at.1, 21.0),
"Cancel",
ButtonKind::Normal,
false,
diff --git a/crates/app/src/extension.rs b/crates/app/src/extension.rs
index 0f2b67dd..fd299875 100644
--- a/crates/app/src/extension.rs
+++ b/crates/app/src/extension.rs
@@ -163,11 +163,21 @@ impl Extension {
},
ink,
);
+ let label = if page.is_none() {
+ // i18n: button in the browser extension's window: open the tutorial that adds the extension
+ "Show me how"
+ } else {
+ // i18n: button in the browser extension's window: open the extension's page in that browser
+ "Add the extension"
+ };
+ // As wide as its label in this language (#192).
+ let (add_x, add_w) =
+ winui::buttons_to_right(&p, W - 18.0, 8.0, &[(label, 150.0)], 220.0)[0];
// This browser's extension is there already: said, before its button.
if is_seen(&self.seen, name) {
winui::text_right(
&p,
- o.x + W - 18.0 - 150.0 - 10.0,
+ o.x + add_x - 10.0,
o.y + y + 16.0,
&format!(
"\u{2714} {}",
@@ -177,16 +187,9 @@ impl Extension {
winui::SUCCESS(),
);
}
- let label = if page.is_none() {
- // i18n: button in the browser extension's window: open the tutorial that adds the extension
- "Show me how"
- } else {
- // i18n: button in the browser extension's window: open the extension's page in that browser
- "Add the extension"
- };
let add = winui::button(
ui,
- r(o, W - 18.0 - 150.0, y, 150.0, 25.0),
+ r(o, add_x, y, add_w, 25.0),
label,
if k == 0 {
ButtonKind::Accent
@@ -218,6 +221,9 @@ impl Extension {
// extension could reach the app, so that comes first, with the fix.
let y = h - 84.0;
if !self.registered {
+ // As wide as its label in this language (#192); the paragraph ends 10 px before it.
+ let (fix_x, fix_w) =
+ winui::buttons_to_right(&p, W - 18.0, 8.0, &[("Set it up", 110.0)], 180.0)[0];
winui::paragraph(
&p,
o.x + 18.0,
@@ -226,12 +232,12 @@ impl Extension {
"Browser integration isn't set up on this computer, so no browser can reach Mister Download Manager yet.",
),
winui::ERROR(),
- o.x + W - 18.0 - 120.0,
+ o.x + fix_x - 10.0,
14.0,
);
let fix = winui::button(
ui,
- r(o, W - 18.0 - 110.0, y - 4.0, 110.0, 25.0),
+ r(o, fix_x, y - 4.0, fix_w, 25.0),
// i18n: button in the browser extension's window: register MDM's helper with the browsers
"Set it up",
ButtonKind::Accent,
@@ -279,9 +285,18 @@ impl Extension {
{
crate::help::open_page(mdm_ipc::extension::GUIDE_DOC);
}
+ // As wide as their labels in this language (#192), Don't ask again only while no
+ // extension has reached MDM.
+ let row: Vec<(&str, f32)> = if self.connected {
+ vec![("Close", 90.0)]
+ } else {
+ vec![("Don't ask again", 130.0), ("Close", 90.0)]
+ };
+ let placed = winui::buttons_to_right(&p, W - 18.0, 8.0, &row, 200.0);
+ let close_at = placed[placed.len() - 1];
let close = winui::button(
ui,
- r(o, W - 18.0 - 90.0, y, 90.0, 25.0),
+ r(o, close_at.0, y, close_at.1, 25.0),
"Close",
ButtonKind::Default,
false,
@@ -294,7 +309,7 @@ impl Extension {
// i18n: button in the browser extension's window: stop offering it at each start
let never = winui::button(
ui,
- r(o, W - 18.0 - 90.0 - 8.0 - 130.0, y, 130.0, 25.0),
+ r(o, placed[0].0, y, placed[0].1, 25.0),
"Don't ask again",
ButtonKind::Normal,
false,
diff --git a/crates/app/src/extractq.rs b/crates/app/src/extractq.rs
index 93cf3aba..7bd25957 100644
--- a/crates/app/src/extractq.rs
+++ b/crates/app/src/extractq.rs
@@ -606,9 +606,19 @@ impl PasswordDialog {
self.focused = true;
}
let has = !self.password.is_empty();
+ // As wide as their labels in this language (#192).
+ let [ok_at, skip_at] = winui::buttons_to_right(
+ &ui.painter().clone(),
+ 369.0,
+ 8.0,
+ &[("Extract", 73.0), ("Cancel", 73.0)],
+ 160.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
let ok = winui::button_light(
ui,
- r(o, 215.0, 80.0, 73.0, 21.0),
+ r(o, ok_at.0, 80.0, ok_at.1, 21.0),
// i18n: button: extract the archive with the password typed
"Extract",
if has {
@@ -621,7 +631,7 @@ impl PasswordDialog {
.clicked();
let skip = winui::button_light(
ui,
- r(o, 296.0, 80.0, 73.0, 21.0),
+ r(o, skip_at.0, 80.0, skip_at.1, 21.0),
"Cancel",
ButtonKind::Normal,
false,
diff --git a/crates/app/src/find.rs b/crates/app/src/find.rs
index 4a7c1f3a..6abbcc16 100644
--- a/crates/app/src/find.rs
+++ b/crates/app/src/find.rs
@@ -146,9 +146,12 @@ impl Find {
true,
);
let can = !q.text.trim().is_empty() && (q.name || q.description || q.site);
+ // As wide as its label in this language (#192), short of Cancel.
+ let (find_x, find_w) =
+ winui::button_around(&ui.painter().clone(), "Find", 73.0, 73.0, 11.0, 190.0);
let find = winui::button_light(
ui,
- r(o, 73.0, 207.0, 73.0, 21.0),
+ r(o, find_x, 207.0, find_w, 21.0),
// i18n: verb: button that starts the search
"Find",
if can {
diff --git a/crates/app/src/gallerydlg.rs b/crates/app/src/gallerydlg.rs
index 3532cbb1..c8170d96 100644
--- a/crates/app/src/gallerydlg.rs
+++ b/crates/app/src/gallerydlg.rs
@@ -186,8 +186,13 @@ impl GalleryDialog {
"Galleries use gallery-dl: install it with your system's packages (Homebrew, pip), then choose it in Helpers.",
)
};
- if can_install {
- status_right = 390.0;
+ // The Install button, as wide as its label in this language (#192), and the line
+ // up to 9 px before it.
+ let install_at = can_install.then(|| {
+ winui::buttons_to_right(&p, 489.0, 8.0, &[("Install gallery-dl", 90.0)], 200.0)[0]
+ });
+ if let Some((x, _)) = install_at {
+ status_right = x - 9.0;
}
let rc = winui::fit(
ui,
@@ -200,10 +205,10 @@ impl GalleryDialog {
"gallery-offer",
);
winui::readable(ui, rc, "gallery-status", msg);
- if can_install
+ if let Some((x, w)) = install_at
&& winui::button(
ui,
- r(o, 399.0, 57.0, 90.0, 21.0),
+ r(o, x, 57.0, w, 21.0),
// i18n: button: download and install the gallery-dl program
"Install gallery-dl",
ButtonKind::Normal,
@@ -340,9 +345,27 @@ impl GalleryDialog {
"gallery-limit-hint",
);
+ // The bottom row, each button as wide as its label in this language (#192): Helpers at the
+ // left, as wide as the room before Download Now allows.
+ let [now_at, later_at, cancel_at] = winui::buttons_to_right(
+ &p,
+ 489.0,
+ 8.0,
+ &[("Download Now", 105.0), ("Later", 73.0), ("Cancel", 73.0)],
+ 160.0,
+ )[..] else {
+ unreachable!("three buttons")
+ };
+ let helpers_at = winui::buttons_from_left(
+ &p,
+ 11.0,
+ 8.0,
+ &[("Helpers...", 90.0)],
+ now_at.0 - 8.0 - 11.0,
+ )[0];
if winui::button(
ui,
- r(o, 11.0, 182.0, 90.0, 21.0),
+ r(o, helpers_at.0, 182.0, helpers_at.1, 21.0),
"Helpers...",
ButtonKind::Normal,
false,
@@ -361,7 +384,7 @@ impl GalleryDialog {
};
let now = winui::button(
ui,
- r(o, 222.0, 182.0, 105.0, 21.0),
+ r(o, now_at.0, 182.0, now_at.1, 21.0),
"Download Now",
kind(true),
false,
@@ -371,7 +394,7 @@ impl GalleryDialog {
|| (ready && winui::enter_pressed(ui));
let later = winui::button(
ui,
- r(o, 335.0, 182.0, 73.0, 21.0),
+ r(o, later_at.0, 182.0, later_at.1, 21.0),
"Later",
kind(false),
false,
@@ -380,7 +403,7 @@ impl GalleryDialog {
.clicked();
let cancel = winui::button(
ui,
- r(o, 416.0, 182.0, 73.0, 21.0),
+ r(o, cancel_at.0, 182.0, cancel_at.1, 21.0),
"Cancel",
ButtonKind::Normal,
false,
diff --git a/crates/app/src/help.rs b/crates/app/src/help.rs
index b21fbcd1..13089f53 100644
--- a/crates/app/src/help.rs
+++ b/crates/app/src/help.rs
@@ -412,11 +412,52 @@ impl Updates {
download = Some(rel.clone());
}
}
- // Under the answer: how Update now is going, else the automatic check's switch.
- // In English, as the text pens take it (a right-to-left window placed the status
- // over its buttons when given the mirrored rect).
- let status_rc =
- egui::Rect::from_min_size(o + vec2(11.0, bottom), vec2(255.0, 21.0));
+ // Update now when this copy's file is in the signed release (and it hasn't just
+ // failed); else Download opens the release's page.
+ let asset = download.as_ref().and_then(|rel| {
+ crate::update::asset_for(install, &rel.version, &rel.assets)
+ .filter(|_| !matches!(self.status, Some(UpdateStatus::Failed(_))))
+ });
+ let close_label = if self.job.is_some() {
+ // i18n: button: stop downloading the update
+ crate::i18n::mark("Cancel")
+ } else if download.is_some() {
+ // i18n: button: not now (download the update later)
+ crate::i18n::mark("Later")
+ } else {
+ crate::i18n::mark("OK")
+ };
+ // The first button: Retry after a failed check, Update now or Download for a new
+ // version.
+ let first = if matches!(result, Some(Err(_))) {
+ Some("Retry")
+ } else if download.is_some() {
+ Some(if asset.is_some() {
+ "Update now"
+ } else {
+ "Download"
+ })
+ } else {
+ None
+ };
+ // The buttons as wide as their labels in this language (#192), the row ending
+ // where it ends in English.
+ let row: Vec<(&str, f32)> = first
+ .into_iter()
+ .chain([close_label])
+ .map(|l| (l, 73.0))
+ .collect();
+ let placed = winui::buttons_to_right(&p, 429.0, 9.0, &row, 150.0);
+ let (first_at, close_at) = (placed[0], placed[placed.len() - 1]);
+ // Under the answer: how Update now is going, else the automatic check's switch,
+ // up to 8 px before the buttons (as in English with two). In English, as the text
+ // pens take it (a right-to-left window placed the status over its buttons when
+ // given the mirrored rect).
+ let status_right = (first_at.0 - 8.0).min(266.0);
+ let status_rc = egui::Rect::from_min_size(
+ o + vec2(11.0, bottom),
+ vec2(status_right - 11.0, 21.0),
+ );
if let Some(job) = &self.job {
let fraction = job.progress.fraction();
let line = crate::i18n::fmt(
@@ -469,23 +510,14 @@ impl Updates {
// i18n: check box in the update window: look for a new version every time MDM starts
"Check for updates at every start",
true,
- Some(o.x + 266.0),
+ Some(o.x + status_right),
);
}
- let close_label = if self.job.is_some() {
- // i18n: button: stop downloading the update
- crate::i18n::mark("Cancel")
- } else if download.is_some() {
- // i18n: button: not now (download the update later)
- crate::i18n::mark("Later")
- } else {
- crate::i18n::mark("OK")
- };
// Enter presses the default button, as in the other dialogs.
let mut enter = winui::enter_pressed(ui);
// A check that failed can be tried again.
+ let at = r(o, first_at.0, bottom, first_at.1, 21.0);
if matches!(result, Some(Err(_))) {
- let at = r(o, 274.0, bottom, 73.0, 21.0);
// i18n: button: check for updates again
let retry = winui::button(ui, at, "Retry", ButtonKind::Default, false, None);
if retry.clicked() || enter {
@@ -495,11 +527,6 @@ impl Updates {
}
}
if let Some(rel) = &download {
- // Update now when this copy's file is in the signed release (and it
- // hasn't just failed); else Download opens the release's page.
- let asset = crate::update::asset_for(install, &rel.version, &rel.assets)
- .filter(|_| !matches!(self.status, Some(UpdateStatus::Failed(_))));
- let at = r(o, 274.0, bottom, 73.0, 21.0);
if let Some(asset) = asset {
let idle = self.job.is_none();
let kind = if idle {
@@ -533,7 +560,7 @@ impl Updates {
};
let close = winui::button(
ui,
- r(o, 356.0, bottom, 73.0, 21.0),
+ r(o, close_at.0, bottom, close_at.1, 21.0),
close_label,
kind,
false,
@@ -892,6 +919,17 @@ impl TellFriend {
);
crate::dialogs::grow_to(ui.ctx(), "tell-a-friend", lines, 5);
let o = o + vec2(0.0, extra);
+ // The buttons as wide as their labels in this language (#192), the row ending
+ // where it ends in English.
+ let [copy_at, email_at, close_at] = winui::buttons_to_right(
+ &p,
+ 409.0,
+ 9.0,
+ &[("Copy", 73.0), ("Email", 73.0), ("Close", 73.0)],
+ 130.0,
+ )[..] else {
+ unreachable!("three buttons")
+ };
if let Some((said, failed)) = self.said {
// Short of the buttons beside it (a long translation: "...", whole on hover).
let c = if failed {
@@ -906,13 +944,13 @@ impl TellFriend {
o.y + 150.0,
crate::i18n::t(said),
c,
- o.x + 166.0,
+ o.x + copy_at.0 - 6.0,
"copied",
);
}
let copy = winui::button(
ui,
- r(o, 172.0, 136.0, 73.0, 21.0),
+ r(o, copy_at.0, 136.0, copy_at.1, 21.0),
"Copy",
ButtonKind::Default,
false,
@@ -922,7 +960,7 @@ impl TellFriend {
|| winui::enter_pressed(ui);
let email = winui::button(
ui,
- r(o, 254.0, 136.0, 73.0, 21.0),
+ r(o, email_at.0, 136.0, email_at.1, 21.0),
"Email",
ButtonKind::Normal,
false,
@@ -931,7 +969,7 @@ impl TellFriend {
.clicked();
let close = winui::button(
ui,
- r(o, 336.0, 136.0, 73.0, 21.0),
+ r(o, close_at.0, 136.0, close_at.1, 21.0),
"Close",
ButtonKind::Normal,
false,
diff --git a/crates/app/src/helpers.rs b/crates/app/src/helpers.rs
index a30e2ee0..1fe9b291 100644
--- a/crates/app/src/helpers.rs
+++ b/crates/app/src/helpers.rs
@@ -347,9 +347,23 @@ impl Helpers {
winui::text(&p, o.x + 16.0, o.y + y + 20.0, later, muted);
let y = y + 28.0;
if self.job.is_none() {
+ // As wide as their labels in this language (#192), the row ending where it ends in
+ // English.
+ let [not_now_at, yes_at] = winui::button_row(
+ &p,
+ &[
+ ("Not now", 196.0, 90.0),
+ ("Yes, download them (recommended)", 292.0, 212.0),
+ ],
+ 6.0,
+ 16.0,
+ 360.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
let not_now = winui::button(
ui,
- r(o, 196.0, y, 90.0, 25.0),
+ r(o, not_now_at.0, y, not_now_at.1, 25.0),
"Not now",
ButtonKind::Normal,
false,
@@ -358,7 +372,7 @@ impl Helpers {
// i18n: the first start's helpers window: download yt-dlp and ffmpeg (the recommended answer)
let yes = winui::button(
ui,
- r(o, 292.0, y, 212.0, 25.0),
+ r(o, yes_at.0, y, yes_at.1, 25.0),
"Yes, download them (recommended)",
ButtonKind::Accent,
false,
@@ -370,10 +384,19 @@ impl Helpers {
*answer = Some(false);
}
} else {
+ let [again_at, close_at] = winui::button_row(
+ &p,
+ &[("Try again", 318.0, 90.0), ("Close", 414.0, 90.0)],
+ 6.0,
+ 16.0,
+ 200.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
if failed && !running {
let again = winui::button(
ui,
- r(o, 318.0, y, 90.0, 25.0),
+ r(o, again_at.0, y, again_at.1, 25.0),
"Try again",
ButtonKind::Normal,
false,
@@ -385,7 +408,7 @@ impl Helpers {
}
let close = winui::button(
ui,
- r(o, 414.0, y, 90.0, 25.0),
+ r(o, close_at.0, y, close_at.1, 25.0),
"Close",
ButtonKind::Default,
false,
@@ -537,9 +560,22 @@ impl Programs {
("helper", k),
);
let busy = self.checking.is_some();
+ // As wide as their labels in this language (#192), side by side from the left.
+ let [other_at, own_at] = winui::button_row_from_left(
+ &p,
+ &[
+ ("Use another program...", 14.0, 180.0),
+ ("Use MDM's own copy", 202.0, 180.0),
+ ],
+ 8.0,
+ 486.0,
+ 260.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
if winui::button(
ui,
- r(o, 14.0, y - o.y + 46.0, 180.0, 21.0),
+ r(o, other_at.0, y - o.y + 46.0, other_at.1, 21.0),
// i18n: Video helpers: button: pick a program (yt-dlp or ffmpeg) already on the computer
"Use another program...",
if busy {
@@ -561,7 +597,7 @@ impl Programs {
}
if winui::button(
ui,
- r(o, 202.0, y - o.y + 46.0, 180.0, 21.0),
+ r(o, own_at.0, y - o.y + 46.0, own_at.1, 21.0),
// i18n: Video helpers: button: go back to the copy MDM downloads and checks itself
"Use MDM's own copy",
if mine && !busy {
diff --git a/crates/app/src/list.rs b/crates/app/src/list.rs
index 44b90cd2..83252550 100644
--- a/crates/app/src/list.rs
+++ b/crates/app/src/list.rs
@@ -1321,11 +1321,18 @@ fn filter_box(ui: &mut Ui, st: &mut ListState) {
st.filters[col] = (keep.len() < vals.len()).then(|| {
Filter::Values(vals.iter().copied().filter(|v| keep.contains(v)).collect())
});
+ // As wide as its label in this language (#192), short of Close.
+ let w = winui::button_fit_width(
+ ui.painter(),
+ "Show all",
+ 90.0,
+ FILTER_W - 90.0 - 8.0 - 10.0,
+ );
if winui::button(
ui,
r(Rect::from_min_size(
pos2(o.x + 10.0, o.y + h - 28.0),
- egui::vec2(90.0, 21.0),
+ egui::vec2(w, 21.0),
)),
"Show all",
winui::ButtonKind::Normal,
diff --git a/crates/app/src/options.rs b/crates/app/src/options.rs
index c406bf91..8fe9dca3 100644
--- a/crates/app/src/options.rs
+++ b/crates/app/src/options.rs
@@ -200,6 +200,17 @@ impl OptionsDialog {
self
}
+ /// With General → Test browser integration's window over it, or Accounts → Add's (`/show
+ /// options:test`, `options:account`: screenshots, #192).
+ pub fn with_window(mut self, name: &str) -> Self {
+ match name {
+ "test" => self.sub = Some(Sub::Test(crate::extension::checks(&self.s))),
+ "account" => self.sub = Some(Sub::Account(AccountEdit::default())),
+ _ => {}
+ }
+ self
+ }
+
pub fn new(
settings: &Settings,
downloads: &std::path::Path,
@@ -458,15 +469,28 @@ impl OptionsDialog {
let off = |ui: &mut Ui, rc: Rect, label: &str| {
winui::button_light(ui, rc, label, ButtonKind::Disabled, false);
};
+ // Both as wide as their labels in this language (#192), within the group box.
+ let [test_at, add_at] = winui::button_row(
+ &p,
+ &[
+ ("Test browser integration...", 30.0, 180.0),
+ ("Add browser...", 286.0, 106.0),
+ ],
+ 8.0,
+ 30.0,
+ 260.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
off(
ui,
- r(o, 286.0, 328.0, 106.0, 21.0),
+ r(o, add_at.0, 328.0, add_at.1, 21.0),
crate::i18n::mark("Add browser..."),
);
// MDM's: what stands between a browser and MDM, checked in order.
if winui::button_light(
ui,
- r(o, 30.0, 328.0, 180.0, 21.0),
+ r(o, test_at.0, 328.0, test_at.1, 21.0),
"Test browser integration...",
ButtonKind::Normal,
false,
@@ -476,11 +500,16 @@ impl OptionsDialog {
self.sub = Some(Sub::Test(crate::extension::checks(&self.s)));
}
winui::etched_h(&p, o.x + 34.0, o.y + 356.0, 357.0);
+ // The buttons at the right as wide as their labels in this language (#192), their
+ // captions ending 6 px before them.
+ let fit_right =
+ |label: &str| winui::buttons_to_right(&p, 392.0, 0.0, &[(label, 73.0)], 160.0)[0];
+ let keys_at = fit_right("Keys...");
let label = crate::i18n::t("Customize keys to prevent or force downloading with MDM");
// Inside the browsers' group box: it starts no further out than the group's frame.
let (rect, cut) = winui::text_right_within(
&p,
- o.x + 313.0,
+ o.x + keys_at.0 - 6.0,
o.y + 379.0,
label,
LIGHT_TEXT(),
@@ -491,7 +520,7 @@ impl OptionsDialog {
}
if winui::button_light(
ui,
- r(o, 319.0, 365.0, 73.0, 21.0),
+ r(o, keys_at.0, 365.0, keys_at.1, 21.0),
"Keys...",
ButtonKind::Normal,
false,
@@ -509,13 +538,20 @@ impl OptionsDialog {
off(ui, r(o, 289.0, 406.0, 103.0, 21.0), "Edit...");
// The download button over videos in the browsers (our own panel, Sub::Panels).
let label = crate::i18n::t("Customize MDM Download panels in browsers");
- let (rect, cut) = winui::text_right(&p, o.x + 313.0, o.y + 452.0, label, LIGHT_TEXT());
+ let panels_at = fit_right("Edit...");
+ let (rect, cut) = winui::text_right(
+ &p,
+ o.x + panels_at.0 - 6.0,
+ o.y + 452.0,
+ label,
+ LIGHT_TEXT(),
+ );
if cut {
winui::full_on_hover(ui, rect, ("general-right", 452), label);
}
if winui::button_light(
ui,
- r(o, 319.0, 438.0, 73.0, 21.0),
+ r(o, panels_at.0, 438.0, panels_at.1, 21.0),
// i18n: verb: edit the item
"Edit...",
ButtonKind::Normal,
@@ -556,9 +592,11 @@ impl OptionsDialog {
"auto-types",
true,
);
+ // Default as wide as its label in this language (#192), growing to the left.
+ let default_at = winui::buttons_to_right(&p, 389.0, 0.0, &[("Default", 73.0)], 200.0)[0];
if winui::button_light(
ui,
- r(o, 316.0, 175.0, 73.0, 21.0),
+ r(o, default_at.0, 175.0, default_at.1, 21.0),
// i18n: button: put back the default list
"Default",
ButtonKind::Normal,
@@ -582,16 +620,24 @@ impl OptionsDialog {
"excluded-sites",
true,
);
- text(
+ let spaces = text(
&p,
o.x + 21.0,
o.y + 293.0,
crate::i18n::t("(separate names by spaces)"),
LIGHT_TEXT(),
);
+ // Short of the note before it.
+ let default_at = winui::button_row(
+ &p,
+ &[("Default", 316.0, 73.0)],
+ 0.0,
+ winui::rect(spaces).right() - o.x + 8.0,
+ 200.0,
+ )[0];
if winui::button_light(
ui,
- r(o, 316.0, 284.0, 73.0, 21.0),
+ r(o, default_at.0, 284.0, default_at.1, 21.0),
// i18n: button: put back the default list
"Default",
ButtonKind::Normal,
@@ -608,9 +654,12 @@ impl OptionsDialog {
crate::i18n::t("Don't start downloading automatically from the following addresses:"),
LIGHT_TEXT(),
);
+ let (list_x, list_w) =
+ winui::button_row_from_left(&p, &[("Edit list ...", 22.0, 135.0)], 0.0, 389.0, 260.0)
+ [0];
if winui::button_light(
ui,
- r(o, 22.0, 334.0, 135.0, 21.0),
+ r(o, list_x, 334.0, list_w, 21.0),
"Edit list ...",
ButtonKind::Normal,
false,
@@ -684,10 +733,19 @@ impl OptionsDialog {
self.category = i;
self.cat_dir = display_dir(&self.s.category_dir(cats[i], downloads));
}
- // New / Edit... (D-021): a category of the user's; a built-in one's folder.
+ // New / Edit... (D-021): a category of the user's; a built-in one's folder. One width for
+ // both, as wide as the longer label in this language (#192), into the room after the
+ // list (it ends at 242).
+ let (col_x, col_w) = winui::buttons_to_right(
+ &p,
+ 392.0,
+ 0.0,
+ &[(winui::widest_label(&p, &["New", "Edit..."]), 73.0)],
+ 142.0,
+ )[0];
if winui::button_light(
ui,
- r(o, 319.0, 105.0, 73.0, 21.0),
+ r(o, col_x, 105.0, col_w, 21.0),
// i18n: button: create a new item
"New",
ButtonKind::Normal,
@@ -700,7 +758,7 @@ impl OptionsDialog {
}
if winui::button_light(
ui,
- r(o, 319.0, 137.0, 73.0, 21.0),
+ r(o, col_x, 137.0, col_w, 21.0),
// i18n: verb: edit the item
"Edit...",
ButtonKind::Normal,
@@ -726,9 +784,12 @@ impl OptionsDialog {
"Default download directory for \"{category}\" category",
));
winui::text_in_window(ui, &p, o.x + 30.0, o.y + 230.0, &dir_line, LIGHT_TEXT());
+ // Browse as wide as its label in this language (#192); the box ends 7 px before it.
+ let (browse_x, browse_w) =
+ winui::buttons_to_right(&p, 392.0, 0.0, &[("Browse", 73.0)], 160.0)[0];
winui::edit_light_on(
ui,
- r(o, 31.0, 239.0, 281.0, 23.0),
+ r(o, 31.0, 239.0, browse_x - 7.0 - 31.0, 23.0),
&mut self.cat_dir,
true,
false,
@@ -736,7 +797,7 @@ impl OptionsDialog {
);
if winui::button_light(
ui,
- r(o, 319.0, 240.0, 73.0, 21.0),
+ r(o, browse_x, 240.0, browse_w, 21.0),
// i18n: verb: choose a folder
"Browse",
ButtonKind::Normal,
@@ -777,10 +838,12 @@ impl OptionsDialog {
// D-004: no temporary directory — parts are written next to the file, so there is
// nothing to assemble at the end.
let none = crate::i18n::t("Not used: file parts are written next to the file");
- readonly(ui, r(o, 30.0, 349.0, 281.0, 23.0), none);
+ let (browse_x, browse_w) =
+ winui::buttons_to_right(&p, 390.0, 0.0, &[("Browse", 73.0)], 160.0)[0];
+ readonly(ui, r(o, 30.0, 349.0, browse_x - 6.0 - 30.0, 23.0), none);
winui::button_light(
ui,
- r(o, 317.0, 350.0, 73.0, 21.0),
+ r(o, browse_x, 350.0, browse_w, 21.0),
// i18n: verb: choose a folder
"Browse",
ButtonKind::Disabled,
@@ -848,9 +911,12 @@ impl OptionsDialog {
398.0,
);
let s = &mut self.s;
+ // Edit... as wide as its label in this language (#192), its caption before it.
+ let (edit_x, edit_w) =
+ winui::buttons_to_right(&p, 392.0, 0.0, &[("Edit...", 73.0)], 160.0)[0];
winui::text_right(
&p,
- o.x + 306.0,
+ o.x + edit_x - 13.0,
o.y + 104.0,
crate::i18n::t("Customize \"Download progress\" dialog"),
LIGHT_DISABLED(),
@@ -858,7 +924,7 @@ impl OptionsDialog {
// The progress dialog customisation dialog is not built yet.
winui::button_light(
ui,
- r(o, 319.0, 89.0, 73.0, 21.0),
+ r(o, edit_x, 89.0, edit_w, 21.0),
// i18n: verb: edit the item
"Edit...",
ButtonKind::Disabled,
@@ -958,14 +1024,14 @@ impl OptionsDialog {
winui::etched_h(&p, o.x + 21.0, o.y + 426.0, 381.0);
winui::text_right(
&p,
- o.x + 302.0,
+ o.x + edit_x - 17.0,
o.y + 451.0,
crate::i18n::t("Virus checking settings"),
LIGHT_DISABLED(),
);
winui::button_light(
ui,
- r(o, 319.0, 436.0, 73.0, 21.0),
+ r(o, edit_x, 436.0, edit_w, 21.0),
// i18n: verb: edit the item
"Edit...",
ButtonKind::Disabled,
@@ -1067,10 +1133,19 @@ impl OptionsDialog {
}),
)
.collect();
+ // New, Delete and Edit: one width, as wide as the longest label in this language (#192),
+ // the list ending 8 px before them (its Number column ends at 291).
+ let (col_x, col_w) = winui::buttons_to_right(
+ &p,
+ 392.0,
+ 0.0,
+ &[(winui::widest_label(&p, &["New", "Delete", "Edit"]), 73.0)],
+ 92.0,
+ )[0];
let (dbl, del_key) = report(
ui,
o,
- r(o, 30.0, 184.0, 281.0, 100.0),
+ r(o, 30.0, 184.0, col_x - 8.0 - 30.0, 100.0),
// i18n: column titles: the server, and the number of connections allowed to it
&[
(crate::i18n::mark("Server"), 241.0),
@@ -1088,7 +1163,7 @@ impl OptionsDialog {
.filter(|i| *i < self.s.conn_exceptions.len());
let new = winui::button_light(
ui,
- r(o, 319.0, 195.0, 73.0, 21.0),
+ r(o, col_x, 195.0, col_w, 21.0),
// i18n: button: create a new item
"New",
ButtonKind::Normal,
@@ -1101,12 +1176,13 @@ impl OptionsDialog {
ButtonKind::Disabled
};
// i18n: verb: delete the item
- let del = winui::button_light(ui, r(o, 319.0, 224.0, 73.0, 21.0), "Delete", kind, false)
+ let del = winui::button_light(ui, r(o, col_x, 224.0, col_w, 21.0), "Delete", kind, false)
.clicked()
|| del_key;
let edit =
// i18n: verb: edit the item
- winui::button_light(ui, r(o, 319.0, 254.0, 73.0, 21.0), "Edit", kind, false).clicked();
+ winui::button_light(ui, r(o, col_x, 254.0, col_w, 21.0), "Edit", kind, false)
+ .clicked();
if new {
self.sub = Some(Sub::Exception(None, String::new(), "1".into()));
}
@@ -1218,10 +1294,21 @@ impl OptionsDialog {
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 =
+ 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 s = &mut self.s;
if winui::button_light(
ui,
- r(o, 307.0, 61.0, 93.0, 21.0),
+ r(o, get_x, 61.0, get_w, 21.0),
"Get System",
ButtonKind::Normal,
false,
@@ -1726,9 +1813,23 @@ impl OptionsDialog {
"opt-logins",
);
let sel = self.login_rows.selected.filter(|i| *i < rows.len());
+ // As wide as their labels in this language (#192), under the list (it ends at 404).
+ let [new_at, edit_at, remove_at] = winui::button_row_from_left(
+ &ui.painter().clone(),
+ &[
+ ("New", 31.0, 73.0),
+ ("Edit", 125.0, 73.0),
+ ("Remove", 220.0, 73.0),
+ ],
+ 21.0,
+ 404.0,
+ 140.0,
+ )[..] else {
+ unreachable!("three buttons")
+ };
let new = winui::button_light(
ui,
- r(o, 31.0, 381.0, 73.0, 21.0),
+ r(o, new_at.0, 381.0, new_at.1, 21.0),
// i18n: button: create a new item
"New",
ButtonKind::Normal,
@@ -1742,10 +1843,16 @@ impl OptionsDialog {
};
let edit =
// i18n: verb: edit the item
- winui::button_light(ui, r(o, 125.0, 381.0, 73.0, 21.0), "Edit", kind, false).clicked();
+ winui::button_light(ui, r(o, edit_at.0, 381.0, edit_at.1, 21.0), "Edit", kind, false).clicked();
// i18n: verb: remove the item
- let remove = winui::button_light(ui, r(o, 220.0, 381.0, 73.0, 21.0), "Remove", kind, false)
- .clicked()
+ let remove = winui::button_light(
+ ui,
+ r(o, remove_at.0, 381.0, remove_at.1, 21.0),
+ "Remove",
+ kind,
+ false,
+ )
+ .clicked()
|| del_key;
if new {
self.sub = Some(Sub::Login(
@@ -2163,9 +2270,24 @@ impl OptionsDialog {
} else {
ButtonKind::Disabled
};
- let browse =
- winui::button_light(ui, r(o, 106.0, 371.0, 73.0, 21.0), "Browse...", kind, false)
- .clicked();
+ // Both as wide as their labels in this language (#192), each around its English centre.
+ let browse_at = winui::button_around(&p, "Browse...", 106.0, 73.0, 21.0, 233.0);
+ let play_at = winui::button_around(
+ &p,
+ "Play",
+ 241.0,
+ 73.0,
+ browse_at.0 + browse_at.1 + 8.0,
+ 404.0,
+ );
+ let browse = winui::button_light(
+ ui,
+ r(o, browse_at.0, 371.0, browse_at.1, 21.0),
+ "Browse...",
+ kind,
+ false,
+ )
+ .clicked();
let has_file = sel.is_some_and(|i| !self.s.sounds[i].1.is_empty());
let play_kind = if has_file {
ButtonKind::Normal
@@ -2174,7 +2296,7 @@ impl OptionsDialog {
};
let play =
// i18n: verb: plays the sound
- winui::button_light(ui, r(o, 241.0, 371.0, 73.0, 21.0), "Play", play_kind, false)
+ winui::button_light(ui, r(o, play_at.0, 371.0, play_at.1, 21.0), "Play", play_kind, false)
.clicked();
if let Some(i) = sel {
if browse || pick_file == Some(i) {
@@ -2549,11 +2671,21 @@ impl OptionsDialog {
}
let first = checks.iter().find(|c| !c.ok);
let y = h - 46.0;
+ // As wide as their labels in this language (#192), short of Close.
+ let [fix_at, set_up_at] = winui::button_row_from_left(
+ &p,
+ &[("How to fix it", 14.0, 110.0), ("Set it up", 132.0, 110.0)],
+ 8.0,
+ 440.0 - 14.0 - 73.0 - 8.0,
+ 200.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
if let Some(c) = first {
if let Some(why) = c.why
&& winui::button_light(
ui,
- r(o, 14.0, y, 110.0, 25.0),
+ r(o, fix_at.0, y, fix_at.1, 25.0),
// i18n: button in Test browser integration: open the help page's section for the problem
"How to fix it",
ButtonKind::Normal,
@@ -2567,7 +2699,7 @@ impl OptionsDialog {
&& mdm_ipc::portable_dir().is_none()
&& winui::button_light(
ui,
- r(o, 132.0, y, 110.0, 25.0),
+ r(o, set_up_at.0, y, set_up_at.1, 25.0),
// i18n: button in Test browser integration: register MDM's helper with the browsers
"Set it up",
ButtonKind::Normal,
@@ -2906,17 +3038,29 @@ fn account_dialog(ui: &mut Ui, o: Pos2, e: &mut AccountEdit) -> Outcome<settings
}
if let S::Waiting { code, page, until } = &state {
// The code, large, to type at the service's page.
+ let code_font = egui::FontId::monospace(crate::theme::metrics().font_code);
p.text(
o + vec2(14.0, 78.0),
egui::Align2::LEFT_TOP,
code,
- egui::FontId::monospace(crate::theme::metrics().font_code),
+ code_font.clone(),
LIGHT_TEXT(),
);
+ // The buttons as wide as their labels in this language (#192), short of the code.
+ let code_end = 14.0 + winui::text_width_font(&p, code_font, code);
+ let [copy_at, open_at] = winui::button_row(
+ &p,
+ &[("Copy code", 200.0, 90.0), ("Open the page", 296.0, 110.0)],
+ 6.0,
+ (code_end + 12.0).min(200.0),
+ 200.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
// i18n: button: copy the sign-in code
if winui::button_light(
ui,
- r(o, 200.0, 80.0, 90.0, 21.0),
+ r(o, copy_at.0, 80.0, copy_at.1, 21.0),
"Copy code",
ButtonKind::Normal,
false,
@@ -2928,7 +3072,7 @@ fn account_dialog(ui: &mut Ui, o: Pos2, e: &mut AccountEdit) -> Outcome<settings
// i18n: button: open the service's page where the code is typed
if winui::button_light(
ui,
- r(o, 296.0, 80.0, 110.0, 21.0),
+ r(o, open_at.0, 80.0, open_at.1, 21.0),
"Open the page",
ButtonKind::Normal,
false,
@@ -2968,11 +3112,19 @@ fn account_dialog(ui: &mut Ui, o: Pos2, e: &mut AccountEdit) -> Outcome<settings
crate::i18n::t("Paste your API key (from the service's Account page):")
};
text(&p, o.x + 14.0, o.y + 178.0, label, LIGHT_TEXT());
- winui::password_light(ui, r(o, 14.0, 186.0, 280.0, 21.0), &mut e.token, !busy);
+ // As wide as its label in this language (#192); the box ends 6 px before it.
+ let (use_x, use_w) =
+ winui::buttons_to_right(&p, 406.0, 0.0, &[("Use the token", 106.0)], 200.0)[0];
+ winui::password_light(
+ ui,
+ r(o, 14.0, 186.0, use_x - 6.0 - 14.0, 21.0),
+ &mut e.token,
+ !busy,
+ );
// i18n: button: sign in with the token typed in
if winui::button_light(
ui,
- r(o, 300.0, 186.0, 106.0, 21.0),
+ r(o, use_x, 186.0, use_w, 21.0),
"Use the token",
kind(!busy && !e.token.trim().is_empty()),
false,
@@ -2984,7 +3136,13 @@ fn account_dialog(ui: &mut Ui, o: Pos2, e: &mut AccountEdit) -> Outcome<settings
// i18n: button: open the service's page that shows the user's API token
if winui::button_light(
ui,
- r(o, 14.0, 212.0, 160.0, 21.0),
+ r(
+ o,
+ 14.0,
+ 212.0,
+ winui::button_fit_width(&p, "Find my token", 160.0, 392.0),
+ 21.0,
+ ),
"Find my token",
ButtonKind::Normal,
false,
diff --git a/crates/app/src/progress.rs b/crates/app/src/progress.rs
index 1bcadd57..1e3beb61 100644
--- a/crates/app/src/progress.rs
+++ b/crates/app/src/progress.rs
@@ -421,9 +421,29 @@ impl Progress {
} else {
ButtonKind::Normal
};
+ // The row as wide as its labels in this language need (#192), each laid out for the
+ // longer of its two labels so it keeps its size when they change; Cancel stays at the
+ // window's edge.
+ let [details_at, pause_at, cancel_at] = winui::button_row(
+ &p,
+ &[
+ (
+ winui::widest_label(&p, &["<< Hide details", "Show details >>"]),
+ 30.0,
+ 138.0,
+ ),
+ (winui::widest_label(&p, &["Pause", "Resume"]), 311.0, 82.0),
+ ("Cancel", 422.0, 73.0),
+ ],
+ 8.0,
+ 30.0,
+ 200.0,
+ )[..] else {
+ unreachable!("three buttons")
+ };
if winui::button(
ui,
- r(o, 30.0, 206.0, 138.0, 22.0),
+ r(o, details_at.0, 206.0, details_at.1, 22.0),
details_label,
kind,
false,
@@ -446,7 +466,7 @@ impl Progress {
};
if winui::button(
ui,
- r(o, 311.0, 206.0, 82.0, 22.0),
+ r(o, pause_at.0, 206.0, pause_at.1, 22.0),
label,
pkind,
false,
@@ -462,7 +482,7 @@ impl Progress {
}
if winui::button(
ui,
- r(o, 422.0, 206.0, 73.0, 22.0),
+ r(o, cancel_at.0, 206.0, cancel_at.1, 22.0),
"Cancel",
ButtonKind::Normal,
false,
diff --git a/crates/app/src/properties.rs b/crates/app/src/properties.rs
index bec00e86..c8440dee 100644
--- a/crates/app/src/properties.rs
+++ b/crates/app/src/properties.rs
@@ -402,9 +402,17 @@ impl Properties {
winui::full_on_hover(ui, rect, "props-result", &result);
}
}
+ // As wide as its label in this language (#192), into the room before OK.
+ let (open_x, open_w) = winui::button_row_from_left(
+ &ui.painter().clone(),
+ &[("Open", 259.0, 73.0)],
+ 8.0,
+ 385.0,
+ 120.0,
+ )[0];
let open = winui::button_light(
ui,
- r(o, 259.0, 390.0, 73.0, 21.0),
+ r(o, open_x, 390.0, open_w, 21.0),
// i18n: verb: opens the file
"Open",
if complete {
diff --git a/crates/app/src/rssdlg.rs b/crates/app/src/rssdlg.rs
index c04c42ed..1378093d 100644
--- a/crates/app/src/rssdlg.rs
+++ b/crates/app/src/rssdlg.rs
@@ -131,16 +131,19 @@ impl RssWindow {
crate::i18n::t("Feed address:"),
winui::TEXT(),
);
+ // Add feed as wide as its label in this language (#192); the box ends 10 px before it.
+ let (add_x, add_w) =
+ winui::buttons_to_right(&p, 740.0, 10.0, &[("Add feed", 120.0)], 200.0)[0];
winui::edit(
ui,
- r(o, 140.0, 42.0, 470.0, 22.0),
+ r(o, 140.0, 42.0, add_x - 10.0 - 140.0, 22.0),
&mut self.address,
true,
false,
);
let add = winui::button(
ui,
- r(o, 620.0, 42.0, 120.0, 22.0),
+ r(o, add_x, 42.0, add_w, 22.0),
// i18n: RSS feeds window: button that subscribes to the feed whose address is typed
"Add feed",
ButtonKind::Normal,
@@ -432,9 +435,20 @@ impl RssWindow {
);
},
);
+ // As wide as their labels in this language (#192), under the list (it ends at 222) and
+ // short of the rule's box beside it (from 240).
+ let [new_at, delete_at] = winui::button_row_from_left(
+ &p,
+ &[("New rule", 22.0, 96.0), ("Delete", 126.0, 96.0)],
+ 8.0,
+ 232.0,
+ 160.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
let new = winui::button(
ui,
- r(o, 22.0, 414.0, 96.0, 21.0),
+ r(o, new_at.0, 414.0, new_at.1, 21.0),
// i18n: RSS feeds window, Download rules: make a new rule
"New rule",
ButtonKind::Normal,
@@ -453,7 +467,7 @@ impl RssWindow {
let sel = self.rules.selected.filter(|i| *i < store.rules.len());
let delete = winui::button(
ui,
- r(o, 126.0, 414.0, 96.0, 21.0),
+ r(o, delete_at.0, 414.0, delete_at.1, 21.0),
"Delete",
if sel.is_some() {
ButtonKind::Normal
diff --git a/crates/app/src/scheduler.rs b/crates/app/src/scheduler.rs
index cfd621b3..c4d8e6cd 100644
--- a/crates/app/src/scheduler.rs
+++ b/crates/app/src/scheduler.rs
@@ -366,9 +366,26 @@ impl Scheduler {
);
let tree = r(o, 11.0, 44.0, 173.0, 379.0 + DY);
let delete_key = self.tree(ui, icons, tree);
+ // The bottom row (the queue's buttons under the tree, the window's beside it), each as
+ // wide as its label in this language (#192): a longer one moves its neighbours along.
+ let row = winui::button_row(
+ &ui.painter().clone(),
+ &[
+ ("&New queue", 21.0, 73.0),
+ ("&Delete", 102.0, 73.0),
+ ("&Start now", 216.0, 73.0),
+ ("S&top", 297.0, 73.0),
+ ("&Help", 390.0, 73.0),
+ ("&Apply", 484.0, 73.0),
+ ("&Close", 565.0, 73.0),
+ ],
+ 8.0,
+ 21.0,
+ 200.0,
+ );
let new_queue = winui::button_light(
ui,
- r(o, 21.0, 432.0 + DY, 73.0, 21.0),
+ r(o, row[0].0, 432.0 + DY, row[0].1, 21.0),
"&New queue",
ButtonKind::Normal,
false,
@@ -377,7 +394,7 @@ impl Scheduler {
let deletable = self.selected >= 2 && self.selected < self.queues.len();
let delete = winui::button_light(
ui,
- r(o, 102.0, 432.0 + DY, 73.0, 21.0),
+ r(o, row[1].0, 432.0 + DY, row[1].1, 21.0),
// i18n: verb: delete the queue
"&Delete",
if deletable {
@@ -388,7 +405,15 @@ impl Scheduler {
false,
)
.clicked();
- winui::etched_v(&p, o.x + 197.0, o.y + 11.0, 442.0 + DY);
+ // The line between the panes runs down beside the buttons; it stops above them where a
+ // longer label takes a button across it.
+ let across = row[1].0 + row[1].1 > 197.0 - 4.0 || row[2].0 < 197.0 + 4.0;
+ let line_h = if across {
+ 432.0 + DY - 6.0 - 11.0
+ } else {
+ 442.0 + DY
+ };
+ winui::etched_v(&p, o.x + 197.0, o.y + 11.0, line_h);
// ---- right pane ---------------------------------------------------------------
let on_queue = self.selected < self.queues.len();
@@ -444,20 +469,20 @@ impl Scheduler {
ButtonKind::Disabled
}
};
- let btn = |ui: &mut Ui, x: f32, label: &str, k: ButtonKind| {
- winui::button_light(ui, r(o, x, 432.0 + DY, 73.0, 21.0), label, k, false).clicked()
+ let btn = |ui: &mut Ui, (x, w): (f32, f32), label: &str, k: ButtonKind| {
+ winui::button_light(ui, r(o, x, 432.0 + DY, w, 21.0), label, k, false).clicked()
};
// i18n: verb: start the queue now
let start = btn(
ui,
- 216.0,
+ row[2],
crate::i18n::mark("&Start now"),
kind(on_queue && !is_running),
);
// i18n: verb: stop the queue
- let stop = btn(ui, 297.0, crate::i18n::mark("S&top"), kind(is_running));
+ let stop = btn(ui, row[3], crate::i18n::mark("S&top"), kind(is_running));
// i18n: noun: button that opens the help
- if btn(ui, 390.0, crate::i18n::mark("&Help"), ButtonKind::Normal) {
+ if btn(ui, row[4], crate::i18n::mark("&Help"), ButtonKind::Normal) {
crate::help::open_page("queues-and-scheduler.md#the-scheduler-window");
}
let dirty = {
@@ -465,9 +490,9 @@ impl Scheduler {
(&q, &l) != (&self.applied.0, &self.applied.1)
};
// i18n: verb: save the changes
- let apply = btn(ui, 484.0, crate::i18n::mark("&Apply"), kind(dirty));
+ let apply = btn(ui, row[5], crate::i18n::mark("&Apply"), kind(dirty));
// i18n: verb: close the window
- let close = btn(ui, 565.0, crate::i18n::mark("&Close"), ButtonKind::Normal);
+ let close = btn(ui, row[6], crate::i18n::mark("&Close"), ButtonKind::Normal);
if modal {
return Outcome::Open;
diff --git a/crates/app/src/torrentdlg.rs b/crates/app/src/torrentdlg.rs
index b041fa4f..e0efbf47 100644
--- a/crates/app/src/torrentdlg.rs
+++ b/crates/app/src/torrentdlg.rs
@@ -540,11 +540,20 @@ impl TorrentDialog {
self.file_list(ui, r(o, 11.0, 58.0, 578.0, 262.0));
- // Select all / none, and what is chosen.
+ // Select all / none, each as wide as its label in this language (#192), and what is chosen.
let has = self.meta.is_some();
+ let [all_at, none_at] = winui::buttons_from_left(
+ &p,
+ 11.0,
+ 6.0,
+ &[("Select all", 90.0), ("Select none", 90.0)],
+ 160.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
if winui::button(
ui,
- r(o, 11.0, 328.0, 90.0, 21.0),
+ r(o, all_at.0, 328.0, all_at.1, 21.0),
"Select all",
kind(has, false),
false,
@@ -557,7 +566,7 @@ impl TorrentDialog {
}
if winui::button(
ui,
- r(o, 107.0, 328.0, 90.0, 21.0),
+ r(o, none_at.0, 328.0, none_at.1, 21.0),
"Select none",
kind(has, false),
false,
@@ -634,20 +643,31 @@ impl TorrentDialog {
}
}
+ // The bottom row, each button as wide as its label in this language (#192).
+ let [now_at, later_at, cancel_at] = winui::buttons_to_right(
+ &p,
+ 589.0,
+ 6.0,
+ &[("Download Now", 105.0), ("Later", 91.0), ("Cancel", 91.0)],
+ 160.0,
+ )[..] else {
+ unreachable!("three buttons")
+ };
// #39: its files' start first, to watch a video while it downloads (also later, from
- // its right-click menu).
- winui::checkbox(
+ // its right-click menu). Its caption stops before the buttons.
+ winui::checkbox_until(
ui,
pos2(o.x + 14.0, o.y + 432.0),
&mut self.in_order,
// i18n: Add torrent, a checkbox: download the files from their start, to watch a video while it downloads
"Download in order",
has,
+ Some(o.x + now_at.0),
);
let ready = has && count > 0 && !self.folder.trim().is_empty() && !busy;
let now = winui::button(
ui,
- r(o, 290.0, 428.0, 105.0, 21.0),
+ r(o, now_at.0, 428.0, now_at.1, 21.0),
"Download Now",
kind(ready, true),
false,
@@ -657,7 +677,7 @@ impl TorrentDialog {
|| (ready && winui::enter_pressed(ui));
let later = winui::button(
ui,
- r(o, 401.0, 428.0, 91.0, 21.0),
+ r(o, later_at.0, 428.0, later_at.1, 21.0),
// i18n: button: add it now, start downloading later
"Later",
kind(ready, false),
@@ -667,7 +687,7 @@ impl TorrentDialog {
.clicked();
let cancel = winui::button(
ui,
- r(o, 498.0, 428.0, 91.0, 21.0),
+ r(o, cancel_at.0, 428.0, cancel_at.1, 21.0),
"Cancel",
ButtonKind::Normal,
false,
diff --git a/crates/app/src/winui.rs b/crates/app/src/winui.rs
index 09a3c405..42677f88 100644
--- a/crates/app/src/winui.rs
+++ b/crates/app/src/winui.rs
@@ -2540,14 +2540,27 @@ pub fn button_rect_for(p: &Painter, rc: Rect, label: &str, max_width: f32) -> Re
}
/// How wide a [`button`] must be for its translated `label` to show whole, with the room it
-/// keeps inside its border: at least `min` (its English width: English labels fit IDM's
-/// buttons, so English never changes), at most `max` (past it the label ends in "..." and
-/// shows whole on hover, as on every button).
+/// keeps inside its border: at least `min` (its English width: English labels fit it, so English
+/// never changes), at most `max` (past it the label ends in "..." and shows whole on hover, as on
+/// every button).
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 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
+/// label needs less.
+fn label_width(p: &Painter, label: &str, english: f32) -> f32 {
let shown = crate::i18n::t(label).replace('&', "");
- (text_width(p, &shown) + 4.0 + 12.0)
- .ceil()
- .clamp(min, max.max(min))
+ let text = text_width(p, &shown);
+ let want = (text + 4.0 + 12.0).ceil();
+ // Whole on the button as it is ([`fit_label`]): it stays.
+ if text <= english - 4.0 {
+ want.min(english)
+ } else {
+ want
+ }
}
/// A row of [`button`]s laid out for their translated labels, `gap` apart, the first starting
@@ -2596,6 +2609,150 @@ pub fn buttons_to_right(
out
}
+/// A row of [`button`]s at their English places, `(label, English x, English width)` from left
+/// to right (IDM's rows, their gaps not all alike), laid out for their translated labels: the row
+/// keeps its right end, and starts no further left than English x `from` (what is beside it).
+/// Each button is as wide as [`button_fit_width`] says (at most `max`), widening to the left; one
+/// that comes closer than `gap` to the one before it (its English gap, if smaller) pushes it left,
+/// and one pushed past `from` pushes those after it back right, each moved no further than it
+/// must. When the row would not fit, the buttons wider than their label needs give back that room
+/// first (to their label, at least 73 px, Windows' button), then the widest are narrowed, their
+/// labels cut with "..." (whole on hover). Their English (x, width) in the order given, for
+/// [`r`]; in English every button keeps its place. ([`button_row_from_left`]: a row that keeps
+/// its left end.)
+pub fn button_row(
+ p: &Painter,
+ buttons: &[(&str, f32, f32)],
+ gap: f32,
+ from: f32,
+ max: f32,
+) -> Vec<(f32, f32)> {
+ let row: Vec<(f32, f32, f32)> = buttons
+ .iter()
+ .map(|(label, x, w)| (*x, *w, label_width(p, label, *w)))
+ .collect();
+ place_row(&row, gap, from, max)
+}
+
+/// [`button_row`] for a row that keeps its left end and ends no further right than English x
+/// `to`: its buttons widen to the right.
+pub fn button_row_from_left(
+ p: &Painter,
+ buttons: &[(&str, f32, f32)],
+ gap: f32,
+ to: f32,
+ max: f32,
+) -> Vec<(f32, f32)> {
+ // The same row seen in a mirror (x → −x): its left end becomes the right one.
+ let mirrored: Vec<(f32, f32, f32)> = buttons
+ .iter()
+ .rev()
+ .map(|(label, x, w)| (-(x + w), *w, label_width(p, label, *w)))
+ .collect();
+ place_row(&mirrored, gap, -to, max)
+ .into_iter()
+ .rev()
+ .map(|(x, w)| (-(x + w), w))
+ .collect()
+}
+
+/// [`button_row`]'s arithmetic: each button's English (x, width) and the width its label needs.
+fn place_row(row: &[(f32, f32, f32)], gap: f32, from: f32, max: f32) -> Vec<(f32, f32)> {
+ let n = row.len();
+ if n == 0 {
+ return Vec::new();
+ }
+ // Each at least `gap` (or its English gap) from the next.
+ let gaps: Vec<f32> = (1..n)
+ .map(|i| (row[i].0 - (row[i - 1].0 + row[i - 1].1)).min(gap))
+ .collect();
+ // As wide as the label needs, never narrower than in English.
+ let mut widths: Vec<f32> = row
+ .iter()
+ .map(|&(_, w, fit)| fit.clamp(w, max.max(w)))
+ .collect();
+ // Too long for its room even side by side: the overflow taken back one pixel at a time,
+ // first from the room labels don't need (down to their label, or 73 px), then from the widest
+ // of the widened buttons (down to their English width).
+ let right = row[n - 1].0 + row[n - 1].1;
+ let room = right - from - gaps.iter().sum::<f32>();
+ // Never narrower than this: its English width, or less where its label needs less (73 px
+ // at least, Windows' button).
+ let least: Vec<f32> = row
+ .iter()
+ .map(|&(_, w, fit)| w.min(fit.max(73.0)))
+ .collect();
+ // What its label needs (at least `least`).
+ let needs: Vec<f32> = row
+ .iter()
+ .zip(&least)
+ .map(|(&(_, _, fit), &l)| fit.max(l))
+ .collect();
+ let mut over = (widths.iter().sum::<f32>() - room).ceil();
+ // The button with the most room above `low` (or the widest with some), if any; the last
+ // first when alike.
+ let most = |widths: &[f32], low: &[f32], by_width: bool| -> Option<usize> {
+ (0..n)
+ .filter(|&i| widths[i] - low[i] >= 1.0)
+ .max_by(|&a, &b| {
+ let key = |i: usize| {
+ if by_width {
+ widths[i]
+ } else {
+ widths[i] - low[i]
+ }
+ };
+ key(a).total_cmp(&key(b)).then(a.cmp(&b))
+ })
+ };
+ while over > 0.0 {
+ let Some(i) = most(&widths, &needs, false).or_else(|| most(&widths, &least, true)) else {
+ break;
+ };
+ widths[i] -= 1.0;
+ over -= 1.0;
+ }
+ // From the right end: each keeps its English right edge while it can, else stands its gap
+ // before the next.
+ let mut xs = vec![0.0; n];
+ let mut limit = f32::INFINITY;
+ for i in (0..n).rev() {
+ xs[i] = (row[i].0 + row[i].1).min(limit) - widths[i];
+ if i > 0 {
+ limit = xs[i] - gaps[i - 1];
+ }
+ }
+ // Then from `from`: those pushed past it come back right, as little as they must.
+ let mut least_x = from;
+ for i in 0..n {
+ xs[i] = xs[i].max(least_x);
+ least_x = xs[i] + widths[i] + gaps.get(i).copied().unwrap_or(0.0);
+ }
+ xs.into_iter().zip(widths).collect()
+}
+
+/// A lone [`button`] at English `x`, `w` wide, widened for its translated `label` around its
+/// centre, between English x `from` and `to` (what is beside it), moved inwards where it would
+/// reach either. Its English (x, width); in English, its place.
+pub fn button_around(p: &Painter, label: &str, x: f32, w: f32, from: f32, to: f32) -> (f32, f32) {
+ let width = button_fit_width(p, label, w, (to - from).max(w));
+ let left = (x + (w - width) / 2.0).floor();
+ (left.min(to - width).max(from), width)
+}
+
+/// Of a button's labels in turn (Pause and Resume), the one whose translation is the widest: the
+/// one to lay the button out for, so it keeps its size as its label changes.
+pub fn widest_label<'a>(p: &Painter, labels: &[&'a str]) -> &'a str {
+ labels
+ .iter()
+ .copied()
+ .max_by(|a, b| {
+ let shown_width = |l: &str| text_width(p, &crate::i18n::t(l).replace('&', ""));
+ shown_width(a).total_cmp(&shown_width(b))
+ })
+ .unwrap_or("")
+}
+
/// `label` as it fits on a button `rc`: whole, or cut with "..." (true) when it would reach the
/// border (English labels fit IDM's buttons, so English never changes).
fn fit_label(p: &Painter, label: &str, rc: Rect) -> (String, bool) {
@@ -5281,6 +5438,172 @@ mod tests {
});
}
+ #[test]
+ fn a_row_keeps_its_english_places_and_uneven_gaps() {
+ // Download File Info's row: gaps of 19 and 18 px, ending at 461.
+ let row = [
+ (97.0, 109.0, 90.0),
+ (225.0, 109.0, 95.0),
+ (352.0, 109.0, 50.0),
+ ];
+ assert_eq!(
+ place_row(&row, 19.0, 11.0, 200.0),
+ vec![(97.0, 109.0), (225.0, 109.0), (352.0, 109.0)]
+ );
+ // The middle one grows: it widens to the left and pushes the first, the gaps kept.
+ let row = [
+ (97.0, 109.0, 90.0),
+ (225.0, 109.0, 150.0),
+ (352.0, 109.0, 50.0),
+ ];
+ assert_eq!(
+ place_row(&row, 19.0, 11.0, 200.0),
+ vec![(56.0, 109.0), (184.0, 150.0), (352.0, 109.0)]
+ );
+ // A button with room before it grows into it without moving the others.
+ let row = [
+ (30.0, 138.0, 100.0),
+ (311.0, 82.0, 120.0),
+ (422.0, 73.0, 60.0),
+ ];
+ assert_eq!(
+ place_row(&row, 8.0, 30.0, 200.0),
+ vec![(30.0, 138.0), (273.0, 120.0), (422.0, 73.0)]
+ );
+ // The last one grows into the room before it, then pushes, `gap` apart.
+ let row = [(311.0, 82.0, 60.0), (422.0, 73.0, 120.0)];
+ assert_eq!(
+ place_row(&row, 8.0, 0.0, 200.0),
+ vec![(285.0, 82.0), (375.0, 120.0)]
+ );
+ // At most `max`.
+ let row = [(311.0, 82.0, 60.0), (422.0, 73.0, 300.0)];
+ assert_eq!(place_row(&row, 8.0, 0.0, 150.0)[1], (345.0, 150.0));
+ // The Scheduler's row: the first, at the row's start, grows; those it reaches move right
+ // as little as they must, the rest keep their places.
+ let english = [21.0, 102.0, 216.0, 297.0, 390.0, 484.0, 565.0];
+ let row: Vec<(f32, f32, f32)> = english
+ .iter()
+ .enumerate()
+ .map(|(i, &x)| (x, 73.0, if i == 0 { 116.0 } else { 60.0 }))
+ .collect();
+ let xs: Vec<f32> = place_row(&row, 8.0, 21.0, 200.0)
+ .iter()
+ .map(|p| p.0)
+ .collect();
+ assert_eq!(xs, [21.0, 145.0, 226.0, 307.0, 390.0, 484.0, 565.0]);
+ }
+
+ #[test]
+ fn a_full_row_takes_room_from_buttons_wider_than_their_label() {
+ // The crash report window's row: 588 px from 16 to 604, gaps of 6, no room to spare.
+ let english = [
+ (16.0, 170.0),
+ (192.0, 110.0),
+ (308.0, 110.0),
+ (424.0, 112.0),
+ (542.0, 62.0),
+ ];
+ let with = |fits: [f32; 5]| -> Vec<(f32, f32, f32)> {
+ english
+ .iter()
+ .zip(fits)
+ .map(|(&(x, w), f)| (x, w, f))
+ .collect()
+ };
+ // English: as it is.
+ let row = with([100.0, 80.0, 75.0, 110.0, 50.0]);
+ assert_eq!(place_row(&row, 6.0, 16.0, 260.0), english.to_vec());
+ // The fourth needs 166: the room is taken from those with the most to spare (the first,
+ // then the third); the row keeps both its ends and its gaps.
+ let row = with([110.0, 100.0, 95.0, 166.0, 50.0]);
+ let placed = place_row(&row, 6.0, 16.0, 260.0);
+ assert_eq!(placed[0], (16.0, 121.0));
+ assert_eq!(placed[1].1, 110.0);
+ assert_eq!(placed[2].1, 105.0);
+ assert_eq!(placed[3].1, 166.0);
+ assert_eq!(placed[4], (542.0, 62.0));
+ for w in placed.windows(2) {
+ assert_eq!(w[1].0 - (w[0].0 + w[0].1), 6.0);
+ }
+ // Not even then: no button goes under 73 px or its label, and the widest widened ones
+ // are narrowed (back to their English width at most).
+ let row = with([200.0, 150.0, 150.0, 250.0, 50.0]);
+ let placed = place_row(&row, 6.0, 16.0, 260.0);
+ let total: f32 = placed.iter().map(|p| p.1).sum::<f32>() + 4.0 * 6.0;
+ assert_eq!(placed[0].0, 16.0);
+ assert_eq!(total, 588.0);
+ assert!(placed.iter().zip(&english).all(|(p, e)| p.1 >= e.1));
+ assert!(
+ placed
+ .iter()
+ .zip(&row)
+ .all(|(p, r)| p.1 < r.2.max(r.1 + 1.0))
+ );
+ }
+
+ #[test]
+ fn a_label_that_fits_keeps_its_button_as_it_is() {
+ with_painter(|p| {
+ // Whole with less than the usual room around it (Download a gallery's English
+ // Install button): not widened, alone or in a row.
+ let label = "Install gallery-dl";
+ let text = text_width(p, label);
+ let tight = (text + 6.0).ceil();
+ assert_eq!(button_fit_width(p, label, tight, 300.0), tight);
+ assert_eq!(
+ button_row(p, &[(label, 100.0, tight)], 8.0, 0.0, 300.0),
+ vec![(100.0, tight)]
+ );
+ // Cut: as wide as the label and the usual room.
+ let cut = (text + 2.0).floor();
+ assert_eq!(button_fit_width(p, label, cut, 300.0), (text + 16.0).ceil());
+ });
+ }
+
+ #[test]
+ fn a_row_from_the_left_widens_to_the_right() {
+ with_painter(|p| {
+ let long = "A label much longer than its English button";
+ let want = (text_width(p, long) + 16.0).ceil();
+ // Short labels: their English places.
+ let row = [("OK", 11.0, 90.0), ("Cancel", 107.0, 90.0)];
+ assert_eq!(
+ button_row_from_left(p, &row, 6.0, 400.0, 300.0),
+ vec![(11.0, 90.0), (107.0, 90.0)]
+ );
+ assert_eq!(
+ button_row(p, &row, 6.0, 0.0, 300.0),
+ vec![(11.0, 90.0), (107.0, 90.0)]
+ );
+ // A long first one pushes the second right, the gap kept.
+ let row = [(long, 11.0, 90.0), ("Cancel", 107.0, 90.0)];
+ let placed = button_row_from_left(p, &row, 6.0, 600.0, 400.0);
+ assert_eq!(placed, vec![(11.0, want), (11.0 + want + 6.0, 90.0)]);
+ // The same as a row ending at the right: the first grows to the left.
+ let placed = button_row(p, &row, 6.0, -400.0, 400.0);
+ assert_eq!(placed, vec![(101.0 - want, want), (107.0, 90.0)]);
+ // Toggling labels: laid out for the widest translation.
+ assert_eq!(widest_label(p, &["OK", long]), long);
+ // A lone button widens around its centre, inside its room. (Labels from variables:
+ // the catalog's extractor takes literal ones as texts to translate.)
+ let short = "OK";
+ assert_eq!(
+ button_around(p, short, 480.0, 73.0, 460.0, 562.0),
+ (480.0, 73.0)
+ );
+ assert_eq!(
+ button_around(p, long, 480.0, 73.0, 460.0, 562.0),
+ (460.0, 102.0)
+ );
+ let label = "Preview the part downloaded";
+ let w = (text_width(p, label) + 16.0).ceil();
+ let (x, got) = button_around(p, label, 480.0, 73.0, 400.0, 600.0);
+ assert_eq!(got, w);
+ assert!((x + w / 2.0 - 516.5).abs() <= 1.0);
+ });
+ }
+
#[test]
fn a_widened_button_grows_into_the_room_before_it_in_rtl_too() {
with_painter(|p| {
diff --git a/i18n/en.tsv b/i18n/en.tsv
index d27ba80b..4a11cd6e 100644
--- a/i18n/en.tsv
+++ b/i18n/en.tsv
@@ -1341,7 +1341,7 @@
#. message or event log entry in the main window
#. & marks the keyboard shortcut letter: keep one & before a letter of the translation
Hide &categories Hide &categories
-#. text in a download's progress window; button in a download's progress window
+#. button in a download's progress window
Hide tab Hide tab
#. text in a download's progress window; text in standard windows
#. tooltip of a button in a download's progress window: hides the window to the notification area (system tray); the download goes on
diff --git a/tools/i18n/extract.py b/tools/i18n/extract.py
index 46e19fd6..7ee97762 100644
--- a/tools/i18n/extract.py
+++ b/tools/i18n/extract.py
@@ -57,6 +57,8 @@ SINKS = {
"header": (3, ""), "group": (6, ""), "disabled_label": (3, ""), "page_title": (4, ""),
# A greyed control's reason on hover (winui::why_disabled).
"why_disabled": (2, ""),
+ # A button's width measured for its label (winui::button_fit_width): the label of a button.
+ "button_fit_width": (1, ""),
}
SINK_CALL = re.compile(
r"\b(?:winui::|MenuEntry::|crate::i18n::|i18n::)?(" + "|".join(SINKS) + r")\s*\(")
@@ -90,7 +92,7 @@ ROLES = {
"Radio": "menu choice", "Sub": "submenu", "off": "menu command", "by": "menu choice",
"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)",
+ "why_disabled": "tooltip (why a control is greyed)", "button_fit_width": "button",
}
CONTEXT_ROLES = {
"menu": "menu command", "toolbar": "toolbar button", "column": "column title",