Skip to content

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

Download video: every button fits its text in every language (#172) (#193)

Ahmed Nefzaouie57e23acb198
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8def485..66968fc3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -389,6 +389,13 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
stream's own server, not the page's.
- **Add torrent: the labels fit in every language**: in German, **Speichern unter** ran under
its field.
+- **Download video: the buttons fit their text in every language**
+ ([#172](https://github.com/anefzaoui/misterdownloadmanager/issues/172)): in German **ffmpeg
+ installieren** showed as "ffmpeg installie...", and in Russian **Helpers...** and **Install
+ ffmpeg** were cut too. Each button is now as wide as its translated text (English is unchanged),
+ and the page's title stops before the Install button instead of running under it. In Arabic
+ and the other right-to-left languages, a widened **Hide tab** in a download's window now grows
+ into the room beside it instead of towards the window's edge.
- **A download or magnet link sent while the window is minimized opens at once**
([#162](https://github.com/anefzaoui/misterdownloadmanager/issues/162)): with the main window
minimized (not to the notification area), a download from the browser or a magnet link was
diff --git a/ROADMAP.md b/ROADMAP.md
index 7eeacd75..7d3d32f6 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -27,6 +27,8 @@ Everything below ships together, in one release, as version 0.3.0.
manual install as the fallback
- ✅ A minimized MDM keeps working: queues, the Scheduler, download limits, the kill switch and
saving the list no longer wait for the window to be restored
+- ✅ Download video: every button fits its text in every language (German **ffmpeg installieren**
+ was cut), right to left too ([#172](https://github.com/anefzaoui/misterdownloadmanager/issues/172))
- ✅ The engine tests that failed now and then on a busy computer (a refused connection coming
back, the learned connection limit, a dead address) wait for what they check, not for time
([#136](https://github.com/anefzaoui/misterdownloadmanager/issues/136))
@@ -211,8 +213,6 @@ Everything below ships together, in one release, as version 0.3.0.
### Downloads and windows
-- 📋 Download video: the **Install ffmpeg** button fits its text in every language
- ([#172](https://github.com/anefzaoui/misterdownloadmanager/issues/172))
- 📋 The Scheduler wakes the computer from sleep to run a queue
([#142](https://github.com/anefzaoui/misterdownloadmanager/issues/142))
- 📋 Debrid services, the rest: a per-download "directly instead" choice, "through the service" in
diff --git a/crates/app/src/playlistdlg.rs b/crates/app/src/playlistdlg.rs
index f5cf308b..849245b3 100644
--- a/crates/app/src/playlistdlg.rs
+++ b/crates/app/src/playlistdlg.rs
@@ -483,9 +483,32 @@ impl PlaylistView {
/// Select all, Select none; Stop listing or Load more; how many are chosen.
fn buttons(&mut self, ui: &mut Ui, o: Pos2, n: usize) {
let p = ui.painter().clone();
+ // i18n: button in Download video for a channel: list its next videos
+ let load_more = crate::i18n::mark("Load more");
+ // i18n: button in Download video: go on listing a playlist from where it stopped
+ let list_rest = crate::i18n::mark("List the rest");
+ // i18n: button in Download video: stop listing a playlist's videos (those listed stay)
+ let stop = crate::i18n::mark("Stop listing");
+ let third = if self.listing.is_some() {
+ stop
+ } else if self.paged {
+ load_more
+ } else {
+ list_rest
+ };
+ // Each as wide as its label in this language (#172), side by side from the left.
+ let [all_at, none_at, third_at] = winui::buttons_from_left(
+ &p,
+ 11.0,
+ 8.0,
+ &[("Select all", 90.0), ("Select none", 90.0), (third, 100.0)],
+ 150.0,
+ )[..] else {
+ unreachable!("three buttons")
+ };
let all = winui::button(
ui,
- r(o, 11.0, 222.0, 90.0, 21.0),
+ r(o, all_at.0, 222.0, all_at.1, 21.0),
// i18n: button in Download video for a playlist: tick every video
"Select all",
ButtonKind::Normal,
@@ -495,7 +518,7 @@ impl PlaylistView {
.clicked();
let none = winui::button(
ui,
- r(o, 109.0, 222.0, 90.0, 21.0),
+ r(o, none_at.0, 222.0, none_at.1, 21.0),
// i18n: button in Download video for a playlist: untick every video
"Select none",
ButtonKind::Normal,
@@ -513,9 +536,8 @@ impl PlaylistView {
if self.listing.is_some() {
if winui::button(
ui,
- r(o, 207.0, 222.0, 100.0, 21.0),
- // i18n: button in Download video: stop listing a playlist's videos (those listed stay)
- "Stop listing",
+ r(o, third_at.0, 222.0, third_at.1, 21.0),
+ stop,
ButtonKind::Normal,
false,
None,
@@ -531,14 +553,8 @@ impl PlaylistView {
} else if self.more
&& winui::button(
ui,
- r(o, 207.0, 222.0, 100.0, 21.0),
- if self.paged {
- // i18n: button in Download video for a channel: list its next videos
- "Load more"
- } else {
- // i18n: button in Download video: go on listing a playlist from where it stopped
- "List the rest"
- },
+ r(o, third_at.0, 222.0, third_at.1, 21.0),
+ third,
ButtonKind::Normal,
false,
None,
diff --git a/crates/app/src/videodlg.rs b/crates/app/src/videodlg.rs
index ef9d1f85..a7e3cb13 100644
--- a/crates/app/src/videodlg.rs
+++ b/crates/app/src/videodlg.rs
@@ -451,9 +451,12 @@ impl VideoDialog {
crate::i18n::t("Page address"),
winui::TEXT(),
);
+ // Look up is as wide as its label in this language (#172); the address ends 8 px before.
+ let (look_x, look_w) =
+ winui::buttons_to_right(&p, 489.0, 8.0, &[("Look up", 90.0)], 160.0)[0];
let edit = winui::edit(
ui,
- r(o, 11.0, 28.0, 380.0, 21.0),
+ r(o, 11.0, 28.0, look_x - 8.0 - 11.0, 21.0),
&mut self.page,
true,
false,
@@ -468,7 +471,7 @@ impl VideoDialog {
let can_look = page_ok && !busy && ytdlp.is_some();
let look = winui::button(
ui,
- r(o, 399.0, 28.0, 90.0, 21.0),
+ r(o, look_x, 28.0, look_w, 21.0),
"Look up",
if can_look {
ButtonKind::Default
@@ -542,6 +545,15 @@ impl VideoDialog {
)),
_ => None,
};
+ // The Install button, as wide as its label in this language, and the status line up to
+ // 9 px before it (to the window's edge without one).
+ let install_at = offer
+ .as_ref()
+ .filter(|(_, label, _)| !label.is_empty() && installing.is_none())
+ .map(|(_, label, _)| {
+ winui::buttons_to_right(&p, 489.0, 8.0, &[(label, 90.0)], 200.0)[0]
+ });
+ let status_right = install_at.map_or(489.0, |(x, _)| x - 9.0);
if let Some(t) = installing {
crate::torrentdlg::spinner(ui, pos2(o.x + 18.0, line_y - 4.0), 6.0);
let msg = if t == Tool::YtDlp {
@@ -562,8 +574,14 @@ impl VideoDialog {
} else if self.list.is_some() {
// The list draws its own (PlaylistView::middle).
} else if let Some((v, _)) = &self.video {
- let (rect, cut) =
- winui::text_fit(&p, o.x + 11.0, line_y, &v.title, winui::TEXT(), o.x + 489.0);
+ let (rect, cut) = winui::text_fit(
+ &p,
+ o.x + 11.0,
+ line_y,
+ &v.title,
+ winui::TEXT(),
+ o.x + status_right,
+ );
if cut {
winui::full_on_hover(ui, rect, "video-title", &v.title);
}
@@ -575,16 +593,15 @@ impl VideoDialog {
line_y,
msg,
winui::MUTED(),
- o.x + 390.0,
+ o.x + status_right,
"video-offer",
);
}
if let Some((tool, label, _)) = offer
- && !label.is_empty()
- && installing.is_none()
+ && 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),
label,
ButtonKind::Normal,
false,
@@ -626,9 +643,7 @@ impl VideoDialog {
// A playlist's or a channel's videos (#69), or the video's choices.
if let Some(list) = &mut self.list {
// The status line stops short of an Install button beside it.
- let button = offer.as_ref().is_some_and(|(_, l, _)| !l.is_empty());
- let right = if button { 390.0 } else { 489.0 };
- list.middle(ui, o, installing.is_none().then_some(right));
+ list.middle(ui, o, installing.is_none().then_some(status_right));
} else {
// The choices: the shared row list.
let list = r(o, 11.0, 94.0, 478.0, 150.0);
@@ -785,10 +800,28 @@ impl VideoDialog {
(true, true) => ButtonKind::Default,
(true, false) => ButtonKind::Normal,
};
+ // The bottom row, each button as wide as its label in this language (#172): 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];
// Where yt-dlp and ffmpeg come from: MDM's own copies or the person's (#51).
if winui::button(
ui,
- r(o, 11.0, 358.0, 90.0, 21.0),
+ r(o, helpers_at.0, 358.0, helpers_at.1, 21.0),
// i18n: button in Download video: where MDM takes yt-dlp and ffmpeg from
"Helpers...",
ButtonKind::Normal,
@@ -801,7 +834,7 @@ impl VideoDialog {
}
let now = winui::button(
ui,
- r(o, 222.0, 358.0, 105.0, 21.0),
+ r(o, now_at.0, 358.0, now_at.1, 21.0),
"Download Now",
kind(true),
false,
@@ -814,7 +847,7 @@ impl VideoDialog {
|| (ready && winui::enter_pressed(ui));
let later = winui::button(
ui,
- r(o, 335.0, 358.0, 73.0, 21.0),
+ r(o, later_at.0, 358.0, later_at.1, 21.0),
// i18n: button: add it now, start downloading later
"Later",
kind(false),
@@ -824,7 +857,7 @@ impl VideoDialog {
.clicked();
let cancel = winui::button(
ui,
- r(o, 416.0, 358.0, 73.0, 21.0),
+ r(o, cancel_at.0, 358.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 732e418e..ca447bc7 100644
--- a/crates/app/src/winui.rs
+++ b/crates/app/src/winui.rs
@@ -2423,13 +2423,73 @@ pub fn button(
/// side, with room before it) to fit its translated `label` whole, with the room [`button`]
/// keeps inside the border, at most to `max_width`. English labels fit IDM's buttons, so
/// English never changes; a label that would still not fit ends in "..." and shows whole on
-/// hover, as on every button. (A button with room after it would widen to the right: add that
-/// when one needs it.)
+/// hover, as on every button. (A row of buttons: [`buttons_from_left`], [`buttons_to_right`].)
pub fn button_rect_for(p: &Painter, rc: Rect, label: &str, max_width: f32) -> Rect {
+ let w = button_fit_width(p, label, rc.width(), max_width);
+ // Widened in English, where its right edge stays; on screen in RTL its left edge stays and
+ // it widens to the right, into the room before it (`rect` is its own inverse).
+ let english = rect(rc);
+ rect(Rect::from_min_max(
+ pos2(english.right() - w, english.top()),
+ english.max,
+ ))
+}
+
+/// 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).
+pub fn button_fit_width(p: &Painter, label: &str, min: f32, max: f32) -> f32 {
let shown = crate::i18n::t(label).replace('&', "");
- let want = (text_width(p, &shown) + 4.0 + 12.0).ceil();
- let w = want.clamp(rc.width(), max_width.max(rc.width()));
- Rect::from_min_max(pos2(rc.right() - w, rc.top()), rc.max)
+ (text_width(p, &shown) + 4.0 + 12.0)
+ .ceil()
+ .clamp(min, max.max(min))
+}
+
+/// A row of [`button`]s laid out for their translated labels, `gap` apart, the first starting
+/// at English x `left`: each `(label, English width)` as wide as [`button_fit_width`] says (at
+/// most `max`). Their English (x, width) in the order given, for [`r`]; in English every button
+/// keeps its place.
+pub fn buttons_from_left(
+ p: &Painter,
+ left: f32,
+ gap: f32,
+ buttons: &[(&str, f32)],
+ max: f32,
+) -> Vec<(f32, f32)> {
+ let mut x = left;
+ buttons
+ .iter()
+ .map(|(label, min)| {
+ let w = button_fit_width(p, label, *min, max);
+ let at = (x, w);
+ x += w + gap;
+ at
+ })
+ .collect()
+}
+
+/// [`buttons_from_left`] for a row that ends at English x `right` (the last button's right
+/// edge): it grows to the left.
+pub fn buttons_to_right(
+ p: &Painter,
+ right: f32,
+ gap: f32,
+ buttons: &[(&str, f32)],
+ max: f32,
+) -> Vec<(f32, f32)> {
+ let mut x = right + gap;
+ let mut out: Vec<(f32, f32)> = buttons
+ .iter()
+ .rev()
+ .map(|(label, min)| {
+ let w = button_fit_width(p, label, *min, max);
+ x -= gap + w;
+ (x, w)
+ })
+ .collect();
+ out.reverse();
+ out
}
/// `label` as it fits on a button `rc`: whole, or cut with "..." (true) when it would reach the
@@ -4723,6 +4783,68 @@ pub mod caption {
mod tests {
use super::*;
+ /// `f` with a painter whose Tahoma is the interface font (as on macOS and Linux).
+ fn with_painter(f: impl FnOnce(&Painter)) {
+ let ctx = egui::Context::default();
+ let mut defs = egui::FontDefinitions::default();
+ install_fonts(&mut defs, None);
+ ctx.set_fonts(defs);
+ let mut f = Some(f);
+ let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {
+ if let Some(f) = f.take() {
+ f(ui.painter());
+ }
+ });
+ out.textures_delta.clear();
+ }
+
+ #[test]
+ fn a_row_of_buttons_widens_for_long_labels_only() {
+ with_painter(|p| {
+ // Short labels keep their English places (Download video's bottom row).
+ let row = [("Later", 73.0), ("Cancel", 73.0)];
+ assert_eq!(
+ buttons_to_right(p, 489.0, 8.0, &row, 160.0),
+ vec![(335.0, 73.0), (416.0, 73.0)]
+ );
+ assert_eq!(
+ buttons_from_left(p, 11.0, 8.0, &row, 160.0),
+ vec![(11.0, 73.0), (92.0, 73.0)]
+ );
+ // A long one is as wide as its text and the room inside the border, up to the most
+ // allowed; the row keeps its end and its gaps.
+ let long = "A label much longer than its English button";
+ let want = (text_width(p, long) + 16.0).ceil();
+ let row = [(long, 90.0), ("Cancel", 73.0)];
+ let placed = buttons_to_right(p, 489.0, 8.0, &row, 400.0);
+ assert_eq!(placed[0], (489.0 - 73.0 - 8.0 - want, want));
+ assert_eq!(placed[1], (416.0, 73.0));
+ let placed = buttons_from_left(p, 11.0, 8.0, &row, 400.0);
+ assert_eq!(placed[1].0, 11.0 + want + 8.0);
+ assert_eq!(buttons_to_right(p, 489.0, 8.0, &row, 120.0)[0].1, 120.0);
+ // Its label then fits whole (no "...").
+ let rc = Rect::from_min_size(pos2(0.0, 0.0), vec2(want, 21.0));
+ assert!(!fit_label(p, long, rc).1);
+ });
+ }
+
+ #[test]
+ fn a_widened_button_grows_into_the_room_before_it_in_rtl_too() {
+ with_painter(|p| {
+ let long = "A label much longer than its English button";
+ let english = Rect::from_min_size(pos2(401.0, 135.0), vec2(96.0, 21.0));
+ let ltr = button_rect_for(p, english, long, 300.0);
+ assert_eq!(ltr.right(), 497.0);
+ assert!(ltr.left() < 401.0);
+ // Mirrored: the button is at the window's left, and grows to the right (inwards).
+ let _s = Surface::enter_if(true, 0.0, 600.0);
+ let shown = button_rect_for(p, rect(english), long, 300.0);
+ assert_eq!(shown.left(), 600.0 - 497.0);
+ assert_eq!(shown.width(), ltr.width());
+ assert_eq!(rect(shown), ltr);
+ });
+ }
+
#[test]
fn a_path_is_shortened_in_the_middle_and_keeps_its_file_name() {
let ctx = egui::Context::default();
diff --git a/i18n/en.tsv b/i18n/en.tsv
index 9976a1f9..ee24991b 100644
--- a/i18n/en.tsv
+++ b/i18n/en.tsv
@@ -2023,7 +2023,7 @@
Stop Stop
#. text in the Scheduler window; checkbox in the Scheduler window
Stop download at Stop download at
-#. button in playlistdlg.rs
+#. text in playlistdlg.rs
#. button in Download video: stop listing a playlist's videos (those listed stay)
Stop listing Stop listing
#. text in the tray icon's menu