diff --git a/locales/de.json b/locales/de.json index c9bb2dd..faf3240 100644 --- a/locales/de.json +++ b/locales/de.json @@ -797,5 +797,40 @@ "tools.inspect_repair": "Prüfen und reparieren", "collage.design": "Layout und Ausgabe", "collage.deselect": "Auswahl aufheben", - "collage.preview_hint": "Schnelle Vorschau · Export mit Originalfotos in der gewählten Leinwandgröße." + "collage.preview_hint": "Schnelle Vorschau · Export mit Originalfotos in der gewählten Leinwandgröße.", + "join.grid2": "Klassisches Raster · 2 Spalten", + "join.grid3": "Galerie · 3 Spalten", + "join.featured": "Blickfang · großes erstes Bild", + "collage.size": "Exportgröße", + "collage.spacing": "Weißer Abstand", + "collage.fit": "Fotoanpassung", + "collage.fill": "Zellen füllen", + "collage.contain": "Ganzes Foto anzeigen", + "collage.hint": "Fügen Sie Fotos hinzu, um die nummerierten Plätze in Dateireihenfolge zu füllen. Export als PNG.", + "collage.preview": "Live-Vorschau", + "collage.empty": "Fügen Sie Fotos hinzu, um Ihre Collage hier zu sehen.", + "collage.swap": "Klicken Sie nacheinander auf zwei Fotos, um ihre Positionen zu tauschen.", + "collage.photo": "Foto", + "collage.adjustments": "Fotoanpassungen", + "collage.direct_hint": "Ziehen Sie Fotos, um sie zu tauschen. Wählen Sie ein Foto zum Zoomen oder Drehen; mit „Ausschnitt anpassen“ können Sie den Bildausschnitt ziehen.", + "collage.reorder": "Fotos neu anordnen", + "collage.reframe": "Ausschnitt anpassen", + "collage.zoom": "Zoom", + "collage.rotate": "Um 90° drehen", + "collage.reset": "Foto zurücksetzen", + "collage.frame": "Rahmenform", + "collage.rectangle": "Rechtecke", + "collage.square": "Quadrate", + "collage.rounded": "Abgerundet", + "collage.circle": "Kreise", + "collage.angle": "Feinrotation", + "collage.position_x": "Horizontale Position", + "collage.position_y": "Vertikale Position", + "collage.remove_photo": "Foto entfernen", + "collage.select_hint": "Wählen Sie ein Foto auf der Leinwand aus, um es zu bearbeiten.", + "collage.output": "Export", + "collage.rotate_left": "Um 90° nach links drehen", + "collage.undo": "Rückgängig", + "collage.redo": "Wiederholen", + "collage.gestures": "Ziehen zum Verschieben · Scrollen zum Zoomen · Alt + Ziehen zum Tauschen · Doppelklick zum Zurücksetzen" } diff --git a/locales/es.json b/locales/es.json index f8d01c1..e34a070 100644 --- a/locales/es.json +++ b/locales/es.json @@ -797,5 +797,40 @@ "tools.inspect_repair": "Inspeccionar y reparar", "collage.design": "Diseño y exportación", "collage.deselect": "Cancelar selección", - "collage.preview_hint": "Vista previa rápida · Exporta las fotos originales al tamaño de lienzo elegido." + "collage.preview_hint": "Vista previa rápida · Exporta las fotos originales al tamaño de lienzo elegido.", + "join.grid2": "Cuadrícula clásica · 2 columnas", + "join.grid3": "Galería · 3 columnas", + "join.featured": "Destacada · primera imagen grande", + "collage.size": "Tamaño de exportación", + "collage.spacing": "Espacio blanco", + "collage.fit": "Ajuste de fotos", + "collage.fill": "Rellenar celdas", + "collage.contain": "Mostrar la foto completa", + "collage.hint": "Añade fotos para llenar los espacios numerados según el orden de la lista de archivos. Exporta como PNG.", + "collage.preview": "Vista previa en vivo", + "collage.empty": "Añade fotos para ver aquí tu collage.", + "collage.swap": "Haz clic en una foto y luego en otra para intercambiar sus posiciones.", + "collage.photo": "Foto", + "collage.adjustments": "Ajustes de foto", + "collage.direct_hint": "Arrastra las fotos para intercambiarlas. Selecciona una foto para ampliarla o girarla; usa «Ajustar recorte» para arrastrar su encuadre.", + "collage.reorder": "Reordenar fotos", + "collage.reframe": "Ajustar recorte", + "collage.zoom": "Zoom", + "collage.rotate": "Girar 90°", + "collage.reset": "Restablecer foto", + "collage.frame": "Forma del marco", + "collage.rectangle": "Rectángulos", + "collage.square": "Cuadrados", + "collage.rounded": "Redondeados", + "collage.circle": "Círculos", + "collage.angle": "Giro fino", + "collage.position_x": "Posición horizontal", + "collage.position_y": "Posición vertical", + "collage.remove_photo": "Eliminar foto", + "collage.select_hint": "Selecciona una foto en el lienzo para editarla.", + "collage.output": "Exportar", + "collage.rotate_left": "Girar 90° a la izquierda", + "collage.undo": "Deshacer", + "collage.redo": "Rehacer", + "collage.gestures": "Arrastrar para mover · Desplazar para ampliar · Alt + arrastrar para intercambiar · Doble clic para restablecer" } diff --git a/locales/fr.json b/locales/fr.json index 964f35d..e07b602 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -797,5 +797,40 @@ "tools.inspect_repair": "Inspecter et réparer", "collage.design": "Disposition et export", "collage.deselect": "Annuler la sélection", - "collage.preview_hint": "Aperçu rapide · Export à partir des photos originales à la taille choisie." + "collage.preview_hint": "Aperçu rapide · Export à partir des photos originales à la taille choisie.", + "join.grid2": "Grille classique · 2 colonnes", + "join.grid3": "Galerie · 3 colonnes", + "join.featured": "À la une · première image agrandie", + "collage.size": "Taille d’exportation", + "collage.spacing": "Espacement blanc", + "collage.fit": "Ajustement des photos", + "collage.fill": "Remplir les cases", + "collage.contain": "Afficher toute la photo", + "collage.hint": "Ajoutez des photos pour remplir les emplacements numérotés selon l’ordre de la liste de fichiers. Export au format PNG.", + "collage.preview": "Aperçu en direct", + "collage.empty": "Ajoutez des photos pour voir votre collage ici.", + "collage.swap": "Cliquez sur une photo puis sur une autre pour échanger leurs positions.", + "collage.photo": "Photo", + "collage.adjustments": "Ajustements de la photo", + "collage.direct_hint": "Faites glisser les photos pour les échanger. Sélectionnez une photo pour zoomer ou la faire pivoter ; utilisez « Ajuster le recadrage » pour déplacer son cadrage.", + "collage.reorder": "Réorganiser les photos", + "collage.reframe": "Ajuster le recadrage", + "collage.zoom": "Zoom", + "collage.rotate": "Pivoter de 90°", + "collage.reset": "Réinitialiser la photo", + "collage.frame": "Forme du cadre", + "collage.rectangle": "Rectangles", + "collage.square": "Carrés", + "collage.rounded": "Arrondis", + "collage.circle": "Cercles", + "collage.angle": "Rotation fine", + "collage.position_x": "Position horizontale", + "collage.position_y": "Position verticale", + "collage.remove_photo": "Supprimer la photo", + "collage.select_hint": "Sélectionnez une photo sur le canevas pour la modifier.", + "collage.output": "Exporter", + "collage.rotate_left": "Pivoter de 90° vers la gauche", + "collage.undo": "Annuler", + "collage.redo": "Rétablir", + "collage.gestures": "Glisser pour déplacer · Faire défiler pour zoomer · Alt + glisser pour échanger · Double-clic pour réinitialiser" } diff --git a/src/app.rs b/src/app.rs index 1789865..5c2d0dd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -56,6 +56,8 @@ const PROGRESS_WIDTH: f32 = 220.0; const EDITOR_MAX_WIDTH: f32 = 1320.0; /// Below this width the editor stacks its two panels and scrolls. const TWO_COLUMN_MIN_WIDTH: f32 = 760.0; +/// Short editors scroll rather than squeezing controls into fixed-height cards. +const PANEL_MIN_HEIGHT: f32 = 320.0; /// The least height the collage canvas and inspector get before the page scrolls. const COLLAGE_MIN_HEIGHT: f32 = 320.0; const PANEL_GAP: f32 = 14.0; @@ -84,6 +86,8 @@ const SHUTDOWN_DELAY: Duration = Duration::from_secs(60); const SETTINGS_WIDTH: f32 = 820.0; const SETTINGS_HEIGHT: f32 = 540.0; const SETTINGS_NAV_WIDTH: f32 = 190.0; +/// Below this width, settings use a section picker instead of a sidebar. +const SETTINGS_COMPACT_WIDTH: f32 = 600.0; /// Space kept free around the Settings window on small screens. const SETTINGS_SCREEN_MARGIN: f32 = 80.0; /// Task-list files larger than this are refused. @@ -2062,7 +2066,7 @@ impl FmxApp { ); } }); - ui.checkbox(&mut opts.grayscale, tr("option.grayscale")); + dir::checkbox(ui, &mut opts.grayscale, tr("option.grayscale")); ui.separator(); ui.label(tr("option.watermark")); if let Some(path) = &opts.edit.watermark { @@ -2155,11 +2159,23 @@ impl FmxApp { let input_done = self.input_missing().is_none(); let size = ui.available_size(); match self.settings_heading() { - None => step_panel(ui, size, 1, input_done, title, &help, |ui| { - self.input_ui(ui, true); - }), + None if size.y >= PANEL_MIN_HEIGHT => { + step_panel(ui, size, 1, input_done, title, &help, |ui| { + self.input_ui(ui, true); + }) + } + None => { + theme::page_scroll() + .id_salt("editor_stacked") + .show(ui, |ui| { + step(ui, 1, input_done, title, &help, |ui| { + self.input_ui(ui, false) + }); + }); + } Some((settings_title, settings_help)) if size.x >= TWO_COLUMN_MIN_WIDTH + && size.y >= PANEL_MIN_HEIGHT && self.tool.input_kind() != InputKind::Capture => { let preview = self.preview_mode(); @@ -3872,11 +3888,12 @@ impl FmxApp { } let eased = egui::emath::easing::cubic_out(shown); let screen = ctx.content_rect(); + // `size` is the frame's inner size, so account for its margins. let size = egui::vec2( - SETTINGS_WIDTH.min(screen.width() - SETTINGS_SCREEN_MARGIN), - SETTINGS_HEIGHT.min(screen.height() - SETTINGS_SCREEN_MARGIN), - ) - .max(egui::vec2(480.0, 320.0)); + SETTINGS_WIDTH.min((screen.width() - SETTINGS_SCREEN_MARGIN).max(0.0)), + SETTINGS_HEIGHT.min((screen.height() - SETTINGS_SCREEN_MARGIN).max(0.0)), + ) - egui::vec2(32.0, 20.0); + let size = size.max(egui::Vec2::ZERO); let dark = ctx.global_style().visuals.dark_mode; let modal = egui::Modal::new(egui::Id::unique("settings_dialog")) .area(egui::Modal::default_area(egui::Id::unique("settings_dialog")).fade_in(false)) @@ -3968,70 +3985,107 @@ impl FmxApp { } fn settings_contents(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) { + if ui.available_width() < SETTINGS_COMPACT_WIDTH { + ui.horizontal(|ui| { + ComboBox::from_id_salt("settings_sections_compact") + .selected_text(self.settings_tab.label()) + .show_ui(ui, |ui| { + dir::menu(ui, |ui| { + for tab in SettingsTab::ALL { + ui.selectable_value(&mut self.settings_tab, tab, tab.label()); + } + }); + }); + if widgets::icon_button( + ui, + icons::INFO, + tr("welcome.reopen"), + Kind::Ghost, + Size::Regular, + ) + .clicked() + { + self.show_settings = false; + self.welcome_step = Some(0); + } + }); + ui.add_space(8.0); + self.settings_page_area(ui, ctx); + return; + } ui.horizontal_top(|ui| { // Section list on the start edge, like most apps' preferences. dir::vertical(ui, |ui| { ui.set_width(SETTINGS_NAV_WIDTH); ui.spacing_mut().item_spacing.y = 3.0; - widgets::nav_list(ui, "settings_sections", |ui| { - let mut chosen = None; - for (i, tab) in SettingsTab::ALL.into_iter().enumerate() { - let news = tab == SettingsTab::Updates && self.update_news(); - let selected = self.settings_tab == tab; - let item = widgets::nav_item( - ui, - Some(tab.art()), - tab.label(), - selected, - false, - news.then_some(1), - ); - if selected { - chosen = Some((i, item.rect)); - } - if item.clicked() { - self.settings_tab = tab; + theme::page_scroll() + .id_salt("settings_navigation") + .auto_shrink([false; 2]) + .show(ui, |ui| { + widgets::nav_list(ui, "settings_sections", |ui| { + let mut chosen = None; + for (i, tab) in SettingsTab::ALL.into_iter().enumerate() { + let news = tab == SettingsTab::Updates && self.update_news(); + let selected = self.settings_tab == tab; + let item = widgets::nav_item( + ui, + Some(tab.art()), + tab.label(), + selected, + false, + news.then_some(1), + ); + if selected { + chosen = Some((i, item.rect)); + } + if item.clicked() { + self.settings_tab = tab; + } + } + chosen + }); + // Keep help outside the preferences pages and visible while they scroll. + ui.add_space((ui.available_height() - 58.0).max(12.0)); + ui.separator(); + if ui + .add_sized( + [SETTINGS_NAV_WIDTH, 44.0], + egui::Button::new(icons::label(icons::INFO, tr("welcome.reopen"))) + .frame(false) + .wrap(), + ) + .clicked() + { + self.show_settings = false; + self.welcome_step = Some(0); } - } - chosen - }); - // Keep help outside the preferences pages and visible while they scroll. - ui.add_space((ui.available_height() - 58.0).max(12.0)); - ui.separator(); - if ui - .add_sized( - [SETTINGS_NAV_WIDTH, 44.0], - egui::Button::new(icons::label(icons::INFO, tr("welcome.reopen"))) - .frame(false) - .wrap(), - ) - .clicked() - { - self.show_settings = false; - self.welcome_step = Some(0); - } + }); }); ui.add_space(12.0); let right_width = ui.available_width(); dir::vertical(ui, |ui| { ui.set_width(right_width); ui.set_max_width(right_width); - // Each section fades and rises in. - let tab = self.settings_tab as u8; - widgets::navigation(ui, "settings", 0, tab.into(), tab, |ui, _| { - theme::page_scroll() - .id_salt(("settings_page", tab)) - .auto_shrink([false; 2]) - .show(ui, |ui| { - ui.add_space(4.0); - self.settings_page(ui, ctx); - ui.add_space(8.0); - }); - }); + self.settings_page_area(ui, ctx); }); }); } + fn settings_page_area(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) { + // Each section fades and rises in. + let tab = self.settings_tab as u8; + widgets::navigation(ui, "settings", 0, tab.into(), tab, |ui, _| { + theme::page_scroll() + .id_salt(("settings_page", tab)) + .auto_shrink([false; 2]) + .show(ui, |ui| { + ui.add_space(4.0); + self.settings_page(ui, ctx); + ui.add_space(8.0); + }); + }); + } + /// A short, dismissible introduction for first-time users. fn welcome_window(&mut self, ctx: &egui::Context) { let Some(step) = self.welcome_step else { @@ -5253,7 +5307,7 @@ fn step_panel( ) { let margin = 14; // The frame's margin and stroke on both sides. - let inner = size - egui::Vec2::splat(f32::from(margin) * 2.0 + 2.0); + let inner = (size - egui::Vec2::splat(f32::from(margin) * 2.0 + 2.0)).max(egui::Vec2::ZERO); ui.allocate_ui_with_layout(size, dir::column(), |ui| { card_frame(ui) .inner_margin(Margin::same(margin)) @@ -7168,6 +7222,81 @@ mod tests { } } + #[test] + fn settings_dialog_switches_navigation_between_narrow_and_wide_windows() { + let ctx = egui::Context::default(); + let cc = eframe::CreationContext::_new_kittest(ctx.clone()); + let mut app = FmxApp::new( + &cc, + Launch { + request: instance::Request::Focus, + self_test: true, + single_instance: false, + }, + ); + app.show_settings = true; + theme::apply(&ctx, ThemeChoice::Light, true); + ctx.enable_accesskit(); + + // Reuse the context to cover resizing in both directions. + for (size, compact) in [ + ([360.0, 480.0], true), + ([900.0, 700.0], false), + ([360.0, 480.0], true), + ] { + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, size.into()); + for frame in 0..4 { + let mut output = ctx.run_ui( + egui::RawInput { + screen_rect: Some(screen), + ..Default::default() + }, + |ui| app.settings_window(ui.ctx()), + ); + output.textures_delta.clear(); + if frame != 3 { + continue; + } + let dialog = ctx + .memory(|memory| memory.area_rect(Id::unique("settings_dialog"))) + .expect("settings dialog is rendered"); + assert!( + screen.contains_rect(dialog), + "{dialog:?} outside {screen:?}" + ); + + let tree = output.platform_output.accesskit_update.unwrap(); + let nodes: Vec<_> = tree.nodes.iter().map(|(_, node)| node).collect(); + let section_picker = nodes.iter().any(|node| { + node.role() == egui::Role::ComboBox + && node.value() == Some(app.settings_tab.label()) + }); + assert_eq!(section_picker, compact, "window size {size:?}"); + let tabs: Vec<_> = nodes + .iter() + .filter(|node| node.role() == egui::Role::Tab) + .collect(); + assert_eq!(tabs.len(), if compact { 0 } else { SettingsTab::ALL.len() }); + for tab in SettingsTab::ALL { + assert_eq!( + tabs.iter().any(|node| node.label() == Some(tab.label())), + !compact, + "sidebar section {} at {size:?}", + tab.label(), + ); + } + // The language selector proves the preferences page also rendered. + assert_eq!( + nodes + .iter() + .filter(|node| node.role() == egui::Role::ComboBox) + .count(), + if compact { 2 } else { 1 }, + ); + } + } + } + #[test] fn welcome_pages_fit_small_and_large_windows() { for size in [[360.0, 480.0], [900.0, 700.0]] { diff --git a/src/i18n.rs b/src/i18n.rs index f4fda22..de5e807 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -226,6 +226,19 @@ mod tests { assert_eq!(ru.get("language.name").map(String::as_str), Some("Русский")); } + #[test] + fn collage_translations_cover_all_languages() { + let en = &catalogs()[FALLBACK]; + for ((code, _), map) in LOCALES.iter().zip(catalogs()).skip(1) { + for key in en.keys().filter(|key| { + key.starts_with("collage.") + || matches!(key.as_str(), "join.grid2" | "join.grid3" | "join.featured") + }) { + assert!(map.contains_key(key), "{code}: missing {key}"); + } + } + } + /// Translations may lag behind, but must not invent keys or drop placeholders. #[test] fn translations_match_english_keys_and_placeholders() { diff --git a/src/widgets.rs b/src/widgets.rs index 1da7b48..ce39370 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -1051,7 +1051,12 @@ pub fn pref_row( .data(|d| d.get_temp(id)) .unwrap_or(Vec2::new(160.0, BUTTON_HEIGHT)); let controls_width = controls_size.x; - let text_width = (width - ROW_PAD * 2.0 - ROW_GAP - controls_width).max(120.0); + let stacked = width < ROW_PAD * 2.0 + ROW_GAP + controls_width + 120.0; + let text_width = if stacked { + (width - ROW_PAD * 2.0).max(1.0) + } else { + width - ROW_PAD * 2.0 - ROW_GAP - controls_width + }; let body = TextStyle::Body.resolve(ui.style()); let small = TextStyle::Small.resolve(ui.style()); let wrapped = |text: &str, font: FontId, color: Color32| { @@ -1061,9 +1066,13 @@ pub fn pref_row( let title_g = wrapped(title, body, p.text); let sub_g = (!subtitle.is_empty()).then(|| wrapped(subtitle, small, p.text_weak)); let text_height = title_g.size().y + sub_g.as_ref().map_or(0.0, |g| 2.0 + g.size().y); - let height = (text_height + 24.0) - .max(controls_size.y + 16.0) - .max(ROW_MIN_HEIGHT); + let height = if stacked { + (text_height + controls_size.y + 28.0).max(ROW_MIN_HEIGHT) + } else { + (text_height + 24.0) + .max(controls_size.y + 16.0) + .max(ROW_MIN_HEIGHT) + }; let (rect, response) = ui.allocate_exact_size(Vec2::new(width, height), Sense::hover()); if !first { ui.painter().hline( @@ -1072,7 +1081,11 @@ pub fn pref_row( Stroke::new(1.0, ink(ui).gamma_multiply(0.08)), ); } - let mut y = rect.center().y - text_height / 2.0; + let mut y = if stacked { + rect.top() + 12.0 + } else { + rect.center().y - text_height / 2.0 + }; let x = |w: f32| dir::mirror_x(rect, rect.left() + ROW_PAD, w); let title_w = title_g.size().x; let title_h = title_g.size().y; @@ -1088,11 +1101,13 @@ pub fn pref_row( // starting height, so a stack of controls would run off the row. let area = rect.shrink2(Vec2::new(ROW_PAD, 0.0)); let x = dir::mirror_x(area, area.right() - controls_width, controls_width); + let center_y = if stacked { + rect.bottom() - 8.0 - controls_size.y / 2.0 + } else { + area.center().y + }; let half = controls_size.y.min(area.height()) / 2.0; - let slot = Rect::from_x_y_ranges( - x..=x + controls_width, - area.center().y - half..=area.center().y + half, - ); + let slot = Rect::from_x_y_ranges(x..=x + controls_width, center_y - half..=center_y + half); let mut end = ui.new_child(egui::UiBuilder::new().max_rect(slot).layout(dir::column())); let used = end.horizontal(controls).response.rect.size(); if (used - controls_size).abs().max_elem() > 0.5 { @@ -1621,6 +1636,64 @@ fn paint_section_header( mod tests { use super::*; + #[test] + fn preference_controls_fit_below_wrapped_text_in_narrow_rows() { + let ctx = egui::Context::default(); + crate::icons::install(&ctx); + for frame in 0..3 { + ctx.run_ui(egui::RawInput::default(), |ui| { + ui.allocate_ui_with_layout( + egui::vec2(240.0, 300.0), + egui::Layout::top_down(egui::Align::Min), + |ui| { + let mut control = Rect::NOTHING; + let title = "A preference with a long title that wraps"; + let subtitle = "A longer explanation for this preference."; + let row = pref_row(ui, title, subtitle, |ui| { + control = ui + .add_sized([180.0, 32.0], egui::Button::new("Control")) + .rect; + }) + .rect; + let width = row.width() - ROW_PAD * 2.0; + let title_height = ui + .painter() + .layout( + title.to_owned(), + TextStyle::Body.resolve(ui.style()), + Color32::WHITE, + width, + ) + .size() + .y; + let subtitle_height = ui + .painter() + .layout( + subtitle.to_owned(), + TextStyle::Small.resolve(ui.style()), + Color32::WHITE, + width, + ) + .size() + .y; + if frame > 0 { + assert!( + control.top() + >= row.top() + 12.0 + title_height + 2.0 + subtitle_height + ); + assert!( + row.contains_rect(control), + "control {control:?} outside row {row:?}" + ); + } + }, + ); + }) + .textures_delta + .clear(); + } + } + #[test] fn collapsible_section_runs_in_context() { let ctx = egui::Context::default();