misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
Crash report window: the report keeps its lines and reads left to right; its buttons fit (#204) (#213)
Ahmed Nefzaoui9868efa6b786
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e9a13704..ca2f374e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -504,6 +504,14 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see### Fixed+- **The crash report window in other languages**+ ([#204](https://github.com/anefzaoui/misterdownloadmanager/issues/204)): in any language but+ English, the report in its box ran together on a few long lines, as its line breaks were taken+ for a translation's and flowed again. The report now keeps its own lines in every language, and+ in Arabic and Persian it reads left to right, from the box's left edge, as the English data it+ is (the window around it stays right to left). The release notes in **Check for updates** keep+ their lines the same way. **End and restart MDM** showed cut in German, French, Russian and+ Arabic: the buttons are now as wide as their text, the others giving back room they don't need.- **Buttons fit their text in every language, in every window**([#192](https://github.com/anefzaoui/misterdownloadmanager/issues/192)): many windows gavetheir buttons a width made for English, so a longer translation was cut with "..." (Germandiff --git a/ROADMAP.md b/ROADMAP.mdindex dd5fc970..eba92af7 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -13,6 +13,9 @@ Everything below ships together, in one release, as version 0.3.0.### Done+- ✅ The crash report window in every language: the report keeps its lines (German and Arabic+ ran them together) and reads left to right in Arabic and Persian; **End and restart MDM** fits+ its text ([#204](https://github.com/anefzaoui/misterdownloadmanager/issues/204))- ✅ 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, theprogress window, the Scheduler, Options, the Help menu's windows, RSS feeds, the video helpersdiff --git a/crates/app/src/crashui.rs b/crates/app/src/crashui.rsindex 75138186..7909c4aa 100644--- a/crates/app/src/crashui.rs+++ b/crates/app/src/crashui.rs@@ -12,7 +12,7 @@ use std::sync::mpsc::{Receiver, channel};use std::sync::{Arc, Mutex};use std::time::Duration;-use egui::{Pos2, Ui, ViewportBuilder};+use egui::{Pos2, Rect, Ui, ViewportBuilder};use mdm_crash::MonitorArgs;use mdm_crash::github::{self, Found};use mdm_crash::monitor::{self, Event};@@ -414,25 +414,33 @@ impl ReportWindow {crate::i18n::t("The report"),winui::TEXT(),);- let text = made.as_ref().map_or_else(- // i18n: crash report window: shown while the crash dump is being read- || crate::i18n::t("Reading the crash data…").to_owned(),- |m| m.text.clone(),- );winui::field_frame(&p,r(o, 16.0, 208.0, 588.0, 226.0),winui::FieldLook::ReadOnly,);- winui::scroll_text(- ui,- egui::Id::unique("crash-report-text"),- r(o, 18.0, 210.0, 584.0, 222.0),- &text,- winui::TEXT(),- 14.0,- true,- );+ match &made {+ // The report as it is: its lines, left to right in every language (#204).+ Some(m) => winui::scroll_text(+ ui,+ egui::Id::unique("crash-report-text"),+ Rect::from_min_size(o + egui::vec2(18.0, 210.0), egui::vec2(584.0, 222.0)),+ &m.text,+ winui::TEXT(),+ 14.0,+ true,+ ),+ None => {+ winui::text(+ &p,+ o.x + 24.0,+ o.y + 226.0,+ // i18n: crash report window: shown while the crash dump is being read+ crate::i18n::t("Reading the crash data…"),+ winui::MUTED(),+ );+ }+ }// What is happening behind it.let status: Option<String> = if let Some((done, total)) = fetching {@@ -478,18 +486,44 @@ impl ReportWindow {);}- // The buttons.+ // The buttons, each as wide as its label in this language (#204): the row fills the+ // window's width, those wider than their label giving room to those that need it.let y = 500.0;+ let send_label = if found.is_some() {+ // i18n: crash report window button: open the GitHub issue already filed (and copy the report to add it there)+ "Open the reported issue"+ } else {+ // i18n: crash report window button: open GitHub's crash report form filled in+ "Send on GitHub"+ };+ // A frozen MDM can be ended; a gone one started again.+ let frozen = self.job.kind == Kind::Freeze && alive && !self.recovered;+ let restart_label = if frozen {+ // i18n: crash report window button: end the frozen MDM and start it again+ "End and restart MDM"+ } else {+ // i18n: crash report window button: start MDM again+ "Restart MDM"+ };+ let [send_at, copy_at, folder_at, restart_at, close_at] = winui::button_row(+ &p,+ &[+ (send_label, 16.0, 170.0),+ ("Copy report", 192.0, 110.0),+ ("Open folder", 308.0, 110.0),+ (restart_label, 424.0, 112.0),+ ("Close", 542.0, 62.0),+ ],+ 6.0,+ 16.0,+ 260.0,+ )[..] else {+ unreachable!("five buttons")+ };let send = winui::button(ui,- r(o, 16.0, y, 170.0, 25.0),- if found.is_some() {- // i18n: crash report window button: open the GitHub issue already filed (and copy the report to add it there)- "Open the reported issue"- } else {- // i18n: crash report window button: open GitHub's crash report form filled in- "Send on GitHub"- },+ r(o, send_at.0, y, send_at.1, 25.0),+ send_label,if made.is_some() {ButtonKind::Default} else {@@ -501,7 +535,7 @@ impl ReportWindow {.clicked();let copy = winui::button(ui,- r(o, 192.0, y, 110.0, 25.0),+ r(o, copy_at.0, y, copy_at.1, 25.0),// i18n: crash report window button: copy the report's text"Copy report",if made.is_some() {@@ -515,7 +549,7 @@ impl ReportWindow {.clicked();let folder = winui::button(ui,- r(o, 308.0, y, 110.0, 25.0),+ r(o, folder_at.0, y, folder_at.1, 25.0),// i18n: crash report window button: show the report's file in its folder"Open folder",ButtonKind::Normal,@@ -523,19 +557,10 @@ impl ReportWindow {None,).clicked();- // A frozen MDM can be ended; a gone one started again.- let frozen = self.job.kind == Kind::Freeze && alive && !self.recovered;- let restart_label = if frozen {- // i18n: crash report window button: end the frozen MDM and start it again- "End and restart MDM"- } else {- // i18n: crash report window button: start MDM again- "Restart MDM"- };let restart = (!alive || frozen)&& winui::button(ui,- r(o, 424.0, y, 112.0, 25.0),+ r(o, restart_at.0, y, restart_at.1, 25.0),restart_label,ButtonKind::Normal,false,@@ -544,7 +569,7 @@ impl ReportWindow {.clicked();let close = winui::button(ui,- r(o, 542.0, y, 62.0, 25.0),+ r(o, close_at.0, y, close_at.1, 25.0),"Close",ButtonKind::Normal,false,diff --git a/crates/app/src/winui.rs b/crates/app/src/winui.rsindex 42677f88..d794aa03 100644--- a/crates/app/src/winui.rs+++ b/crates/app/src/winui.rs@@ -758,10 +758,11 @@ pub fn progress_bar(p: &Painter, rc: Rect, fraction: Option<f32>, time: f64) {}}-/// Read-only text that scrolls inside `area` (English coordinates, the box's own frame drawn by+/// Read-only data that scrolls inside `area` (English coordinates, the box's own frame drawn by/// the caller): the wheel or a trackpad over it, its scroll bar when the text is longer than the/// box, and with `keys` the window's Up, Down, Page Up, Page Down, Home and End. Where it is-/// scrolled to is kept under `id`.+/// scrolled to is kept under `id`. The text is data (a crash report, release notes): its line+/// breaks are kept and it reads left to right in every language ([`data_paragraph`]).#[allow(clippy::too_many_arguments)]pub fn scroll_text(ui: &mut Ui,@@ -778,7 +779,8 @@ pub fn scroll_text(let visible = ((area.height() - 6.0) / line_h).floor().max(1.0);// Laid out first where nothing shows: the bar takes room only when the text needs it.let measure = p.with_clip_rect(Rect::NOTHING);- let lines = |right: f32| paragraph(&measure, area.left() + PAD, 0.0, s, color, right, line_h);+ let lines =+ |right: f32| data_paragraph(&measure, area.left() + PAD, 0.0, s, color, right, line_h);let mut total = lines(area.right() - PAD) as f32;let bar = total > visible;let text_right = if bar {@@ -823,7 +825,7 @@ pub fn scroll_text(ui.ctx().request_repaint();}let clip = p.with_clip_rect(rect(area.shrink(2.0)));- paragraph(+ data_paragraph(&clip,area.left() + PAD,area.top() + 16.0 - top * line_h,@@ -857,6 +859,7 @@ pub fn scroll_text(/// lines drawn. English keeps its line breaks (broken where IDM breaks it); a translation's/// copy of them is flowed again (`reflow`). A line too long for the room wraps at spaces, or/// between any two characters in scripts written without spaces (Chinese, Japanese, Thai…).+/// (Data, whose line breaks are its own: [`data_paragraph`].)pub fn paragraph(p: &Painter,x: f32,@@ -866,8 +869,6 @@ pub fn paragraph(right: f32,line_h: f32,) -> usize {- let room = (right - x).max(1.0);- let mut lines: Vec<String> = Vec::new();// IDM's English is hard-wrapped; a translation's copy of those breaks is flowed again (a// blank line still starts a new paragraph). English keeps its own lines.let flowed;@@ -877,7 +878,58 @@ pub fn paragraph(flowed = reflow(s);flowed.as_str()};+ let lines = wrap_lines(p, s, (right - x).max(1.0));+ for (i, l) in lines.iter().enumerate() {+ text(p, x, baseline + line_h * i as f32, l, color);+ }+ lines.len()+}++/// Data shown as it is (a crash report, release notes), from English `x` to `right`, first+/// baseline at `baseline`, `line_h` apart; returns the lines drawn. Its line breaks are its own+/// in every language (a line longer than the room wraps, as in [`paragraph`]), and it reads left+/// to right from the left edge of its room, inside a right-to-left window too: data keeps its+/// direction there (the RTL notes above).+pub fn data_paragraph(+ p: &Painter,+ x: f32,+ baseline: f32,+ s: &str,+ color: Color32,+ right: f32,+ line_h: f32,+) -> usize {+ let lines = wrap_lines(p, s, (right - x).max(1.0));+ let left = data_left(x, right);+ for (i, l) in lines.iter().enumerate() {+ let mut job = egui::text::LayoutJob::simple(l.clone(), tahoma(), color, f32::INFINITY);+ job.direction = egui::epaint::text::TextDirection::LeftToRight;+ paint_galley(+ p,+ left,+ baseline + line_h * i as f32,+ p.layout_job(job),+ color,+ );+ }+ lines.len()+}++/// Where data from English `x` to `right` starts on screen: its room's left edge (the mirror of+/// its English right edge in RTL).+fn data_left(x: f32, right: f32) -> f32 {+ rect(Rect::from_min_max(pos2(x, 0.0), pos2(right, 0.0)))+ .left()+ .round()+}++/// `s` broken into the lines it shows in `room` px: at its own line breaks, and where a line is+/// too long, at spaces, or between any two characters in scripts written without spaces.+fn wrap_lines(p: &Painter, s: &str, room: f32) -> Vec<String> {+ let mut lines: Vec<String> = Vec::new();for given in s.split('\n') {+ // A Windows line end (a report written there) breaks the line too.+ let given = given.strip_suffix('\r').unwrap_or(given);let mut line = String::new();for word in given.split_inclusive(' ') {let candidate = format!("{line}{word}");@@ -928,10 +980,7 @@ pub fn paragraph(}lines.push(line.trim_end().to_owned());}- for (i, l) in lines.iter().enumerate() {- text(p, x, baseline + line_h * i as f32, l, color);- }- lines.len()+ lines}/// Where the text before a line's first input box goes in a [`sentence`].@@ -5604,6 +5653,45 @@ mod tests {});}+ #[test]+ fn data_keeps_its_own_lines_and_reads_left_to_right() {+ with_painter(|p| {+ // A report's lines (Windows' line ends too) stay lines; only a long one wraps.+ let report = "Kind: freeze\r\nTime: 2026-11-06 10:00:01\n\n at mdm::app::update\nend";+ assert_eq!(+ wrap_lines(p, report, 1000.0),+ vec![+ "Kind: freeze",+ "Time: 2026-11-06 10:00:01",+ "",+ " at mdm::app::update",+ "end"+ ]+ );+ let long = "one two three four five six seven eight nine ten";+ let lines = wrap_lines(p, long, text_width(p, "one two three") + 1.0);+ assert_eq!(lines[0], "one two three");+ assert!(+ lines+ .iter()+ .all(|l| text_width(p, l) <= text_width(p, "one two three") + 1.0)+ );+ // Drawn: as many lines (a translation's paragraph is flowed again, data never).+ assert_eq!(+ data_paragraph(p, 24.0, 100.0, report, TEXT(), 400.0, 14.0),+ 5+ );+ });+ }++ #[test]+ fn data_starts_at_the_left_of_its_room_in_rtl_too() {+ assert_eq!(data_left(24.0, 400.0), 24.0);+ // English 24..400 in a 600 px window, mirrored: on screen 200..576, read from 200.+ let _s = Surface::enter_if(true, 0.0, 600.0);+ assert_eq!(data_left(24.0, 400.0), 200.0);+ }+#[test]fn a_widened_button_grows_into_the_room_before_it_in_rtl_too() {with_painter(|p| {