diff --git a/crates/ui-egui/src/analysispane.rs b/crates/ui-egui/src/analysispane.rs index 842bdd7047..4c19a9dd6f 100644 --- a/crates/ui-egui/src/analysispane.rs +++ b/crates/ui-egui/src/analysispane.rs @@ -1828,10 +1828,9 @@ fn trend(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { }); } else { let was_stack = f.stack; - ui.horizontal(|ui| { - ui.radio_value(&mut f.stack, true, tl!("Layers, a date each")); - ui.radio_value(&mut f.stack, false, tl!("One layer: a Zarr variable or a raster's bands")); - }); + // One under the other: the second is too long to share a line in a narrow pane. + ui.radio_value(&mut f.stack, true, tl!("Layers, a date each")); + ui.radio_value(&mut f.stack, false, tl!("One layer: a Zarr variable or a raster's bands")); // Dates typed for one kind of series don't carry over to the other. if f.stack != was_stack { f.dates.clear(); @@ -1871,7 +1870,7 @@ fn trend(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { // A catalog's cube takes its dates from its items or its store. if f.cube.is_none() { let input_label = ui.label(tl!("Dates")); - ui.add(egui::TextEdit::singleline(&mut f.dates).hint_text(tl!("from the names")).desired_width(240.0)) + ui.add(egui::TextEdit::singleline(&mut f.dates).hint_text(tl!("from the names")).desired_width(crate::widgets::fit(ui, 240.0))) .labelled_by(input_label.id); ui.end_row(); } @@ -1885,7 +1884,8 @@ fn trend(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { let shown = tests.iter().find(|t| t.0 == f.test).map_or("", |t| t.1); egui::ComboBox::from_id_salt("trend_test") .selected_text(tl!(shown)) - .width(240.0) + .width(crate::widgets::fit(ui, 240.0)) + .truncate() .show_ui(ui, |ui| { for (code, label) in tests { ui.selectable_value(&mut f.test, code.to_string(), tl!(label)); @@ -2307,7 +2307,14 @@ fn script_below(app: &RustGisApp, ui: &Ui) -> f32 { let results = if app.workflow.script_out.is_empty() { 0.0 } else { script_out_height(ui) + gap }; // The row that says where the cursor is (#2831). let cursor = script_cursor_height(ui) + gap; - ui.spacing().interact_size.y + gap * 3.0 + cursor + last + results + // The buttons' row: as tall as it was last drawn, which is more than a row where it wraps. + let actions = ui.data(|d| d.get_temp::(script_actions_key())).unwrap_or(0.0).max(ui.spacing().interact_size.y); + actions + gap * 3.0 + cursor + last + results +} + +/// Where the Script pane keeps how tall its buttons' row was last drawn. +fn script_actions_key() -> egui::Id { + egui::Id::unique("script_actions_height") } /// Runs the Script pane's `script`: on the desktop its tools on a thread of their own first, the @@ -2579,7 +2586,7 @@ fn script(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, fit: bool) { .on_hover_text(tl!("The cursor's line and column, and how many characters are selected")); } }); - ui.horizontal(|ui| { + let actions = ui.horizontal_wrapped(|ui| { // As egui reads the keys: ⌘ on a Mac, the browser's too (from its user agent). let mac = ui.ctx().os().is_mac(); let shortcut = if mac { "⌘+Enter" } else { "Ctrl+Enter" }; @@ -2615,6 +2622,8 @@ fn script(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, fit: bool) { clear_keeping_undo(app, ui, box_id); } }); + // How tall the buttons' row was: it wraps in a narrow pane, and the box leaves it room. + ui.data_mut(|d| d.insert_temp(script_actions_key(), actions.response.rect.height())); // Above the results' scroll, so it stays in view: its number and how long it took, and on // the right when it started, as the Geoprocessing History tells it (UTC: the app has no time // zone). diff --git a/crates/ui-egui/src/assistantpane.rs b/crates/ui-egui/src/assistantpane.rs index b5475528b8..35491b3ff8 100644 --- a/crates/ui-egui/src/assistantpane.rs +++ b/crates/ui-egui/src/assistantpane.rs @@ -79,7 +79,9 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { .id_salt("assistant_settings_scroll") .auto_shrink([false, true]) .min_scrolled_height(0.0) - .max_height((ui.available_height() - 8.0).max(0.0)) + // The conversation keeps room for a few lines below, where it scrolls; in a short pane, + // less, so the settings keep most of it. + .max_height((ui.available_height() - 8.0 - CONVERSATION_ROOM.min(ui.available_height() * 0.3)).max(0.0)) .show(ui, |ui| { egui::Frame::NONE.inner_margin(egui::Margin::symmetric(12, 4)).show(ui, |ui| settings(app, ui, t)); }); @@ -95,6 +97,9 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { }); } +/// The height the conversation keeps under open settings, at most: never over 30% of the pane. +const CONVERSATION_ROOM: f32 = 96.0; + fn composer_panel(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, busy: bool, ctx: &egui::Context) { egui::Panel::bottom("assistant_composer") .frame(egui::Frame::NONE.fill(t.pane).inner_margin(egui::Margin::symmetric(10, 8))) @@ -260,13 +265,14 @@ fn provider_settings(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, cfg: &mut Co .labelled_by(address_label.id); ui.end_row(); let key_label = ui.label(tl!("API key")); - ui.horizontal(|ui| { + ui.horizontal_wrapped(|ui| { let hint = if preset.is_some_and(|p| p.keyless) { tl!("not needed") } else { tl!("paste your key") }; + let width = crate::widgets::fit(ui, 150.0); ui.add( egui::TextEdit::singleline(&mut cfg.key) .id(egui::Id::unique(FIELDS[2])) .password(!app.assistant.show_key) - .desired_width(150.0) + .desired_width(width) .hint_text(hint), ) .labelled_by(key_label.id); @@ -870,7 +876,8 @@ fn transcript(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, ctx: &egui::Context ui.add_space(8.0); let mut chosen = None; for s in SUGGESTIONS { - let b = egui::Button::new(RichText::new(tl!(s)).small()).corner_radius(12); + // Wrapped: a suggestion is wider than a narrow pane. + let b = egui::Button::new(RichText::new(tl!(s)).small()).corner_radius(12).wrap(); if ui.add(b).clicked() { chosen = Some(tl!(s).to_string()); } @@ -1480,6 +1487,10 @@ pub(crate) mod tests { ); h.run_steps(4); h.get_by_label("Tokens for this message: 1 234 in, 5 out"); + // Below the provider's settings, which leave the conversation its room: folded, they make + // room for it. + h.get_by_label("AI provider").click(); + h.run_steps(4); h.get_by_label("Show the tokens each message uses").click(); h.run_steps(4); assert!(h.query_by_label("Tokens for this message: 1 234 in, 5 out").is_none()); diff --git a/crates/ui-egui/src/backstage.rs b/crates/ui-egui/src/backstage.rs index fadf298bee..e2842a0410 100644 --- a/crates/ui-egui/src/backstage.rs +++ b/crates/ui-egui/src/backstage.rs @@ -105,8 +105,9 @@ fn start(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { ui.add_space(24.0); ui.label(egui::RichText::new(tl!("New Project")).font(semibold(15.0))); ui.add_space(8.0); - ui.horizontal(|ui| { - ui.spacing_mut().item_spacing = vec2(18.0, 0.0); + // The cards wrap to another row where the window is narrow. + ui.horizontal_wrapped(|ui| { + ui.spacing_mut().item_spacing = vec2(18.0, 18.0); if card(ui, t, "Map", "A blank map with a basemap", "new_map") { let _ = app.run_by_user("project.new", Value::Null); if !crate::saveprompt::waiting(app) { diff --git a/crates/ui-egui/src/catalogsui.rs b/crates/ui-egui/src/catalogsui.rs index 9d252f6627..cc1a67ef07 100644 --- a/crates/ui-egui/src/catalogsui.rs +++ b/crates/ui-egui/src/catalogsui.rs @@ -377,9 +377,10 @@ pub fn sourcecoop(app: &mut RustGisApp, ui: &mut egui::Ui) { let busy = app.ui.catalogs.waiting.is_some(); let mut ask = None; if !locked { - ui.horizontal(|ui| { + ui.horizontal_wrapped(|ui| { let input_label = ui.label(tl!("Account")); - ui.add(egui::TextEdit::singleline(&mut app.ui.catalogs.account).hint_text(tl!("featured products")).desired_width(220.0)) + let width = crate::widgets::fit(ui, 220.0); + ui.add(egui::TextEdit::singleline(&mut app.ui.catalogs.account).hint_text(tl!("featured products")).desired_width(width)) .labelled_by(input_label.id); if ui.add_enabled(!busy, egui::Button::new(tl!("List Products"))).clicked() { let a = app.ui.catalogs.account.trim().to_string(); diff --git a/crates/ui-egui/src/editpanes.rs b/crates/ui-egui/src/editpanes.rs index dd768eb551..42987248a4 100644 --- a/crates/ui-egui/src/editpanes.rs +++ b/crates/ui-egui/src/editpanes.rs @@ -94,17 +94,18 @@ fn layer_names(app: &RustGisApp, pred: impl Fn(&rustgis_engine::map::Layer) -> b app.session.map().layers.iter().filter(|l| pred(l)).map(|l| l.name.clone()).collect() } -fn combo(ui: &mut Ui, id: &str, name: &str, value: &mut String, options: &[String]) { +/// A box choosing `value` from `options`, named `name` for its tooltip and screen readers. +fn combo(ui: &mut Ui, id: &str, name: &str, value: &mut String, options: &[String]) -> egui::Response { egui::ComboBox::from_id_salt(id) .selected_text(value.as_str()) - .width(170.0) + .width(crate::widgets::fit(ui, 170.0)) .show_ui(ui, |ui| { for o in options { ui.selectable_value(value, o.clone(), o.as_str()); } }) .response - .on_hover_text(tl!(name)); + .on_hover_text(tl!(name)) } pub fn editing(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { @@ -610,13 +611,18 @@ pub fn design(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { app.session.map().layer_by_name(n).map(|l| l.dataset.fields.iter().map(|f| f.name.clone()).collect()).unwrap_or_default() }; let (of, df) = (fields_of(app, &app.forms.rel_origin), fields_of(app, &app.forms.rel_dest)); + // A row each: two boxes side by side don't fit a narrow pane. egui::Grid::new("rel").num_columns(2).spacing(vec2(6.0, 4.0)).show(ui, |ui| { - combo(ui, "rel_o", "Origin", &mut app.forms.rel_origin, &layers); - combo(ui, "rel_ok", "Origin key", &mut app.forms.rel_origin_key, &of); - ui.end_row(); - combo(ui, "rel_d", "Destination", &mut app.forms.rel_dest, &layers); - combo(ui, "rel_dk", "Destination key", &mut app.forms.rel_dest_key, &df); - ui.end_row(); + for (id, name, value, options) in [ + ("rel_o", "Origin", &mut app.forms.rel_origin, &layers), + ("rel_ok", "Origin key", &mut app.forms.rel_origin_key, &of), + ("rel_d", "Destination", &mut app.forms.rel_dest, &layers), + ("rel_dk", "Destination key", &mut app.forms.rel_dest_key, &df), + ] { + let label = ui.label(tl!(name)); + combo(ui, id, name, value, options).labelled_by(label.id); + ui.end_row(); + } }); ui.add(egui::TextEdit::singleline(&mut app.forms.rel_name).hint_text(tl!("Relationship name")).desired_width(180.0)); if ui.button(tl!("Relate")).clicked() { diff --git a/crates/ui-egui/src/labelpane.rs b/crates/ui-egui/src/labelpane.rs index 9aec98d4ae..63aba42a2a 100644 --- a/crates/ui-egui/src/labelpane.rs +++ b/crates/ui-egui/src/labelpane.rs @@ -292,7 +292,7 @@ fn classes(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, c: &Class, t: &Tokens) ui.add_enabled_ui(!editing, |ui| { let count = extras(l).count(); let at = c.name.and_then(|n| extras(l).position(|k| k.name == n)); - ui.horizontal(|ui| { + ui.horizontal_wrapped(|ui| { let full = l.labels.classes.len() >= MAX_LABEL_CLASSES; let max = MAX_LABEL_CLASSES.to_string(); let new = ui @@ -331,7 +331,11 @@ fn classes(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, c: &Class, t: &Tokens) } } // At the far end and in red: it is the one that deletes, and its name is close to - // Rename's. + // Rename's. On a row of its own where the pane is too narrow for it beside the rest. + let font = egui::TextStyle::Button.resolve(ui.style()); + if ui.available_size_before_wrap().x < crate::widgets::text_w(ui, tl!("Remove"), font) + 2.0 * ui.spacing().button_padding.x { + ui.end_row(); + } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { let remove = ui .add_enabled(at.is_some(), egui::Button::new(RichText::new(tl!("Remove")).color(t.red))) diff --git a/crates/ui-egui/src/layout_reach.rs b/crates/ui-egui/src/layout_reach.rs index ce0d3cbbb1..0b260490e0 100644 --- a/crates/ui-egui/src/layout_reach.rs +++ b/crates/ui-egui/src/layout_reach.rs @@ -40,173 +40,8 @@ const SLACK: f32 = 2.5; /// Problems there are today, as [`problems`] names them. Only take lines out: a new problem is /// fixed, not listed, and a line whose problem is gone fails the test. const KNOWN: &[&str] = &[ - r#"dialog sourcecoop at 1280: cut off Button "List Products""#, - r#"dialog sourcecoop at 900: cut off Button "List Products""#, - r#"layer properties display at 1280: cut off SpinButton "Transparency""#, - r#"layer properties display at 900: cut off SpinButton "Transparency""#, - r#"pane Assistant at 1280: cut off Button "Show""#, - r#"pane Assistant at 1280: cut off Button "Which 5 countries have the largest GDP?" and 4 more"#, - r#"pane Assistant at 900: cut off Button "Show""#, - r#"pane Assistant at 900: cut off Button "Which 5 countries have the largest GDP?""#, - r#"pane Assistant at 900: cut off Button "Zoom to Tokyo" and 3 more"#, - r#"pane Design at 1280: cut off ComboBox "Destination key""#, - r#"pane Design at 1280: cut off ComboBox "Origin key""#, - r#"pane Design at 900: cut off ComboBox "Destination key""#, - r#"pane Design at 900: cut off ComboBox "Origin key""#, - r#"pane Geoprocessing at 1280: cut off Button "Aggregate Points to Grid""#, - r#"pane Geoprocessing at 1280: cut off Button "Buffer""#, - r#"pane Geoprocessing at 1280: cut off Button "Calculate Geometry Attributes""#, - r#"pane Geoprocessing at 1280: cut off Button "Check DEM""#, - r#"pane Geoprocessing at 1280: cut off Button "Check Geometry""#, - r#"pane Geoprocessing at 1280: cut off Button "Clip""#, - r#"pane Geoprocessing at 1280: cut off Button "Dissolve""#, - r#"pane Geoprocessing at 1280: cut off Button "Erase""#, - r#"pane Geoprocessing at 1280: cut off Button "Export Features""#, - r#"pane Geoprocessing at 1280: cut off Button "Feature Envelope To Polygon""#, - r#"pane Geoprocessing at 1280: cut off Button "Feature To Point""#, - r#"pane Geoprocessing at 1280: cut off Button "Feature Vertices To Points""#, - r#"pane Geoprocessing at 1280: cut off Button "Generate Tessellation""#, - r#"pane Geoprocessing at 1280: cut off Button "IDW Interpolation""#, - r#"pane Geoprocessing at 1280: cut off Button "Identity""#, - r#"pane Geoprocessing at 1280: cut off Button "Install Whitebox and GeoLibre tools""#, - r#"pane Geoprocessing at 1280: cut off Button "Intersect""#, - r#"pane Geoprocessing at 1280: cut off Button "Join Field""#, - r#"pane Geoprocessing at 1280: cut off Button "Kernel Density""#, - r#"pane Geoprocessing at 1280: cut off Button "Merge""#, - r#"pane Geoprocessing at 1280: cut off Button "Minimum Bounding Geometry""#, - r#"pane Geoprocessing at 1280: cut off Button "Near""#, - r#"pane Geoprocessing at 1280: cut off Button "OD Cost Matrix""#, - r#"pane Geoprocessing at 1280: cut off Button "Ordinary Kriging""#, - r#"pane Geoprocessing at 1280: cut off Button "Pivot Table""#, - r#"pane Geoprocessing at 1280: cut off Button "Points Along Lines""#, - r#"pane Geoprocessing at 1280: cut off Button "Polygon To Line""#, - r#"pane Geoprocessing at 1280: cut off Button "Raster to PMTiles""#, - r#"pane Geoprocessing at 1280: cut off Button "Repair Geometry""#, - r#"pane Geoprocessing at 1280: cut off Button "Select Layer By Attribute""#, - r#"pane Geoprocessing at 1280: cut off Button "Select Layer By Location""#, - r#"pane Geoprocessing at 1280: cut off Button "Service Area""#, - r#"pane Geoprocessing at 1280: cut off Button "Simplify""#, - r#"pane Geoprocessing at 1280: cut off Button "Spatial Join""#, - r#"pane Geoprocessing at 1280: cut off Button "Split Line At Vertices""#, - r#"pane Geoprocessing at 1280: cut off Button "Split""#, - r#"pane Geoprocessing at 1280: cut off Button "Summarize Within""#, - r#"pane Geoprocessing at 1280: cut off Button "Summary Statistics""#, - r#"pane Geoprocessing at 1280: cut off Button "Symmetrical Difference""#, - r#"pane Geoprocessing at 1280: cut off Button "Tabulate Area""#, - r#"pane Geoprocessing at 1280: cut off Button "Tabulate Intersection""#, - r#"pane Geoprocessing at 1280: cut off Button "Texture Shading""#, - r#"pane Geoprocessing at 1280: cut off Button "Tissot's Indicatrix""#, - r#"pane Geoprocessing at 1280: cut off Button "Union""#, - r#"pane Geoprocessing at 1280: cut off Button "Unsplit Line""#, - r#"pane Geoprocessing at 1280: cut off Button "Update""#, - r#"pane Geoprocessing at 1280: cut off Button "Vector to PMTiles""#, - r#"pane Geoprocessing at 1280: cut off Button "XY Table To Point""#, - r#"pane Geoprocessing at 1280: cut off Button "Zonal Statistics""#, - r#"pane Geoprocessing at 900: cut off Button "Aggregate Points to Grid""#, - r#"pane Geoprocessing at 900: cut off Button "Buffer""#, - r#"pane Geoprocessing at 900: cut off Button "Calculate Geometry Attributes""#, - r#"pane Geoprocessing at 900: cut off Button "Check DEM""#, - r#"pane Geoprocessing at 900: cut off Button "Check Geometry""#, - r#"pane Geoprocessing at 900: cut off Button "Clip""#, - r#"pane Geoprocessing at 900: cut off Button "Dissolve""#, - r#"pane Geoprocessing at 900: cut off Button "Erase""#, - r#"pane Geoprocessing at 900: cut off Button "Export Features""#, - r#"pane Geoprocessing at 900: cut off Button "Feature Envelope To Polygon""#, - r#"pane Geoprocessing at 900: cut off Button "Feature To Point""#, - r#"pane Geoprocessing at 900: cut off Button "Feature Vertices To Points""#, - r#"pane Geoprocessing at 900: cut off Button "Generate Tessellation""#, - r#"pane Geoprocessing at 900: cut off Button "IDW Interpolation""#, - r#"pane Geoprocessing at 900: cut off Button "Identity""#, - r#"pane Geoprocessing at 900: cut off Button "Install Whitebox and GeoLibre tools""#, - r#"pane Geoprocessing at 900: cut off Button "Intersect""#, - r#"pane Geoprocessing at 900: cut off Button "Join Field""#, - r#"pane Geoprocessing at 900: cut off Button "Kernel Density""#, - r#"pane Geoprocessing at 900: cut off Button "Merge""#, - r#"pane Geoprocessing at 900: cut off Button "Minimum Bounding Geometry""#, - r#"pane Geoprocessing at 900: cut off Button "Near""#, - r#"pane Geoprocessing at 900: cut off Button "OD Cost Matrix""#, - r#"pane Geoprocessing at 900: cut off Button "Ordinary Kriging""#, - r#"pane Geoprocessing at 900: cut off Button "Pivot Table""#, - r#"pane Geoprocessing at 900: cut off Button "Points Along Lines""#, - r#"pane Geoprocessing at 900: cut off Button "Polygon To Line""#, - r#"pane Geoprocessing at 900: cut off Button "Raster to PMTiles""#, - r#"pane Geoprocessing at 900: cut off Button "Repair Geometry""#, - r#"pane Geoprocessing at 900: cut off Button "Select Layer By Attribute""#, - r#"pane Geoprocessing at 900: cut off Button "Select Layer By Location""#, - r#"pane Geoprocessing at 900: cut off Button "Service Area""#, - r#"pane Geoprocessing at 900: cut off Button "Simplify""#, - r#"pane Geoprocessing at 900: cut off Button "Spatial Join""#, - r#"pane Geoprocessing at 900: cut off Button "Split Line At Vertices""#, - r#"pane Geoprocessing at 900: cut off Button "Split""#, - r#"pane Geoprocessing at 900: cut off Button "Summarize Within""#, - r#"pane Geoprocessing at 900: cut off Button "Summary Statistics""#, - r#"pane Geoprocessing at 900: cut off Button "Symmetrical Difference""#, - r#"pane Geoprocessing at 900: cut off Button "Tabulate Area""#, - r#"pane Geoprocessing at 900: cut off Button "Tabulate Intersection""#, - r#"pane Geoprocessing at 900: cut off Button "Texture Shading""#, - r#"pane Geoprocessing at 900: cut off Button "Tissot's Indicatrix""#, - r#"pane Geoprocessing at 900: cut off Button "Union""#, - r#"pane Geoprocessing at 900: cut off Button "Unsplit Line""#, - r#"pane Geoprocessing at 900: cut off Button "Update""#, - r#"pane Geoprocessing at 900: cut off Button "Vector to PMTiles""#, - r#"pane Geoprocessing at 900: cut off Button "XY Table To Point""#, - r#"pane Geoprocessing at 900: cut off Button "Zonal Statistics""#, - r#"pane Labeling at 1280: overlap Button "Move Down" and Button "Remove""#, - r#"pane Labeling at 900: overlap Button "Move Down" and Button "Remove""#, + // A pane this wide leaves the map less room than one tab. r#"pane Notebook at 900: cut off Button "World""#, - r#"pane Script at 1280: cut off Button "Clear""#, - r#"pane Script at 900: cut off Button "Clear""#, - r#"pane Symbology at 1280: cut off SpinButton "Transparency""#, - r#"pane Symbology at 900: cut off SpinButton "Transparency""#, - r#"ribbon Settings at 1280: cut off CheckBox "Download Datum Grids""#, - r#"ribbon Settings at 900: cut off CheckBox "Download Datum Grids""#, - r#"start open at 1280: cut off Button "QGIS Project…""#, - r#"start open at 900: cut off Button "GeoLibre Project…""#, - r#"start open at 900: cut off Button "Open…""#, - r#"start open at 900: cut off Button "QGIS Project…""#, - r#"view designer at 1280: cut off Button "Copy Command""#, - r#"view designer at 900: cut off Button "Copy Command""#, - r#"view designer at 900: cut off Button "Export…""#, - r#"view designer at 900: cut off Button "Fit""#, - r#"view designer at 900: cut off Button "Import…""#, - r#"view designer, pane at 1280: cut off Button "Copy Command""#, - r#"view designer, pane at 1280: cut off Button "Export…""#, - r#"view designer, pane at 1280: cut off Button "Import…""#, - r#"view designer, pane at 1280: cut off SpinButton "Transparency""#, - r#"view designer, pane at 900: cut off Button "Arrange""#, - r#"view designer, pane at 900: cut off Button "Copy Command""#, - r#"view designer, pane at 900: cut off Button "Export…""#, - r#"view designer, pane at 900: cut off Button "Fit""#, - r#"view designer, pane at 900: cut off Button "Import…""#, - r#"view designer, pane at 900: cut off Button "Open""#, - r#"view designer, pane at 900: cut off Button "Save""#, - r#"view designer, pane at 900: cut off Button "▶ Run""#, - r#"view designer, pane at 900: cut off SpinButton "Transparency""#, - r#"view table at 900: cut off Button "×""#, - r#"view table at 900: cut off CheckBox "Selected only""#, - r#"view table at 900: cut off TextInput "Filter rows…""#, - r#"view table, pane at 1280: cut off Button "×""#, - r#"view table, pane at 1280: cut off CheckBox "Selected only""#, - r#"view table, pane at 1280: cut off SpinButton "Transparency""#, - r#"view table, pane at 1280: cut off TextInput "Filter rows…""#, - r#"view table, pane at 900: cut off Button "Add field""#, - r#"view table, pane at 900: cut off Button "Calculate Geometry""#, - r#"view table, pane at 900: cut off Button "Calculate field""#, - r#"view table, pane at 900: cut off Button "Clear selection""#, - r#"view table, pane at 900: cut off Button "Delete selected rows""#, - r#"view table, pane at 900: cut off Button "Select By Attributes""#, - r#"view table, pane at 900: cut off Button "Switch selection""#, - r#"view table, pane at 900: cut off Button "Zoom to selection""#, - r#"view table, pane at 900: cut off Button "×""#, - r#"view table, pane at 900: cut off CheckBox "Selected only""#, - r#"view table, pane at 900: cut off SpinButton "Transparency""#, - r#"view table, pane at 900: cut off TextInput "Filter rows…""#, - r#"workflows trend at 1280: cut off ComboBox "Test""#, - r#"workflows trend at 1280: cut off RadioButton "One layer: a Zarr variable or a raster's bands""#, - r#"workflows trend at 1280: cut off TextInput "Dates""#, - r#"workflows trend at 900: cut off ComboBox "Test""#, - r#"workflows trend at 900: cut off RadioButton "One layer: a Zarr variable or a raster's bands""#, - r#"workflows trend at 900: cut off TextInput "Dates""#, ]; /// A control drawn in the last frame. @@ -373,7 +208,10 @@ fn problems(h: &mut Harness, surface: &str, bare: &Bare) -> Vec { let mut clips: HashMap<(LayerId, [i32; 4]), (&Control, &Control, usize)> = HashMap::new(); // The controls each edge cuts: in one scrolled area, so they are compared whole. let mut members: HashMap<(LayerId, [i32; 4]), Vec<&Control>> = HashMap::new(); - for c in here.iter().filter(|c| c.cut().x <= SLACK && c.cut().y > SLACK) { + // The Script pane's box scrolls its own text inside a view the pane sizes: cut off at the top + // or bottom, with a few lines in view, is how it is used. Only it is let through. + let scrolls_itself = |c: &Control| c.id == egui::Id::unique("script_text") && c.seen.height() >= 3.0 * 16.0; + for c in here.iter().filter(|c| c.cut().x <= SLACK && c.cut().y > SLACK && !scrolls_itself(c)) { let past = |e: f32, v: f32, sign: f32| if (v - e) * sign > SLACK { e.round() as i32 } else { i32::MIN }; let edges = [ past(c.seen.min.x, c.rect.min.x, -1.0), @@ -602,6 +440,12 @@ fn surfaces() -> Vec { let designer = ("ui.modelDesigner", Value::Null); let symbology = ("ui.pane.symbology", Value::Null); let with_pane = |a: &RustGisApp| a.ui.right.is_some(); + // A script longer than the pane: the box grows to the buttons, which must stay in reach. + all.push(( + "pane Script, long script".into(), + vec![("ui.pane.script", Value::Null)], + Box::new(|a| a.ui.right == Some(RightPane::Script)), + )); all.push(("left catalog".into(), vec![("ui.pane.catalog", Value::Null)], Box::new(|a| a.ui.left == Some(LeftPane::Catalog)))); all.push(("left sources".into(), vec![("ui.pane.sources", Value::Null)], Box::new(|a| a.ui.left == Some(LeftPane::Sources)))); all.push(("view table".into(), vec![table.clone()], Box::new(|a| a.session.table_layer.is_some()))); @@ -730,6 +574,9 @@ fn app(surface: &str) -> RustGisApp { app.session.map_mut().basemap = Default::default(); } app.assistant.agents_found = Some(Default::default()); + if surface == "pane Script, long script" { + app.workflow.script = (0..80).map(|i| format!("map.zoomIn {{\"step\": {i}}}\n")).collect(); + } app.ui.left = Some(LeftPane::Contents); app.ui.language = "en".into(); app diff --git a/crates/ui-egui/src/modeldesigner.rs b/crates/ui-egui/src/modeldesigner.rs index 41a1341b9f..5197847981 100644 --- a/crates/ui-egui/src/modeldesigner.rs +++ b/crates/ui-egui/src/modeldesigner.rs @@ -680,106 +680,118 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) { } fn toolbar(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, problems: &[model::Problem]) { - ui.horizontal_centered(|ui| { - // A shell with its own interface has no view tabs, and on a phone the buttons at the far - // end are past the window's edge: the way back to the map comes first. - let back = egui::Button::new(tl!("Back to the map")).min_size(vec2(0.0, crate::chrome::FINGER)); - if app.chrome.is_some() && ui.add(back).clicked() { + // Close and the way back to the map stay in sight; the rest scrolls sideways where the view + // is narrower than the toolbar. + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + if crate::widgets::icon_button(ui, "close", tl!("Close Model Designer")).clicked() { + request(app, Pending::Close); + } + // A shell with its own interface has a button of its own for this, first in the row. + if app.chrome.is_none() && crate::widgets::icon_button(ui, "map", tl!("Back to the map")).clicked() { app.mb.active = false; - // Opened over a layout, the layout would show in its place. A close that fails is - // said by `run`, as any command's failure is. - if app.session.active_layout.is_some() { - let _ = app.run("layout.close", serde_json::Value::Null); - } } - let (r, _) = ui.allocate_exact_size(vec2(22.0, 22.0), Sense::hover()); - icons::paint(ui.painter(), r, "modelbuilder", t.icon, t.accent); - ui.add(egui::TextEdit::singleline(&mut app.mb.name).hint_text(tl!("Untitled model")).desired_width(170.0).font(semibold(13.0))); - if app.mb.dirty() { - ui.label(egui::RichText::new("●").color(t.amber)).on_hover_text(tl!("Unsaved changes")); - } - ui.separator(); - if ui.button(tl!("New")).on_hover_text(tl!("Start an empty model")).clicked() { - request(app, Pending::New); - } - let models: Vec = app.session.project.models.iter().map(|m| m.name.clone()).collect(); - ui.add_enabled_ui(!models.is_empty(), |ui| { - ui.menu_button(tl!("Open"), |ui| { - for m in &models { - if ui.button(m).clicked() { - if app.mb.saved_as.as_deref() != Some(m) { - request(app, Pending::Open(m.clone())); - } - ui.close(); - } + ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| { + // A shell with its own interface has no view tabs: the way back to the map comes first, + // finger-sized. + let back = egui::Button::new(tl!("Back to the map")).min_size(vec2(0.0, crate::chrome::FINGER)); + if app.chrome.is_some() && ui.add(back).clicked() { + app.mb.active = false; + // Opened over a layout, the layout would show in its place. A close that fails is + // said by `run`, as any command's failure is. + if app.session.active_layout.is_some() { + let _ = app.run("layout.close", serde_json::Value::Null); } - }) - .response - .on_hover_text(tl!("Open a model of this project")); - }); - if ui.button(tl!("Save")).on_hover_text(tl!("Save the model in the project")).clicked() { - save(app); - } - ui.separator(); - let can_run = problems.is_empty(); - let run = ui.add_enabled(can_run, egui::Button::new(egui::RichText::new(format!("▶ {}", tl!("Run"))).strong())); - let run = if can_run { - run.on_hover_text(tl!("Run the model")) - } else { - run.on_disabled_hover_text(tl!("Fix the problems listed below first")) - }; - if run.clicked() { - run_model(app); - } - ui.separator(); - if ui.button(tl!("Arrange")).on_hover_text(tl!("Lay the nodes out along the flow")).clicked() && !app.mb.graph.nodes.is_empty() { - app.mb.edit(); - model::layout(&mut app.mb.graph); - app.mb.fit = true; - } - if ui.button(tl!("Fit")).on_hover_text(tl!("Show the whole model")).clicked() { - app.mb.fit = true; - } - ui.add_enabled_ui(!app.mb.undo.is_empty(), |ui| { - if crate::widgets::icon_button(ui, "undo", tl!("Undo (Ctrl+Z)")).clicked() { - app.mb.undo(); } - }); - ui.add_enabled_ui(!app.mb.redo.is_empty(), |ui| { - if crate::widgets::icon_button(ui, "redo", tl!("Redo (Ctrl+Y)")).clicked() { - app.mb.redo(); - } - }); - ui.separator(); - if ui.button(tl!("Import…")).on_hover_text(tl!("Open a model file (*.model.json)")).clicked() { - import(app); - } - ui.add_enabled_ui(!app.mb.graph.nodes.is_empty(), |ui| { - if ui.button(tl!("Export…")).on_hover_text(tl!("Save the model as a file (*.model.json)")).clicked() { - export(app); - } - if ui - .button(tl!("Copy Command")) - .on_hover_text(tl!("Copy a model.run command that runs this model, for the Script pane or Python")) - .clicked() - { - let name = serde_json::to_string(app.mb.name.trim()).unwrap_or_default(); - // A model from a file runs by name, as saved, so the engine holds it to its rules. - let text = match (&app.mb.saved_as, app.mb.imported) { - (Some(saved), true) => format!("model.run {}", json!({"name": saved})), - _ => format!("model.run {{\"name\": {name}, \"graph\": {}}}", serde_json::to_string(&app.mb.graph).unwrap_or_default()), + crate::widgets::scrolling_row(ui, "model_toolbar", |ui| { + let (r, _) = ui.allocate_exact_size(vec2(22.0, 22.0), Sense::hover()); + icons::paint(ui.painter(), r, "modelbuilder", t.icon, t.accent); + ui.add( + egui::TextEdit::singleline(&mut app.mb.name).hint_text(tl!("Untitled model")).desired_width(170.0).font(semibold(13.0)), + ); + if app.mb.dirty() { + ui.label(egui::RichText::new("●").color(t.amber)).on_hover_text(tl!("Unsaved changes")); + } + ui.separator(); + if ui.button(tl!("New")).on_hover_text(tl!("Start an empty model")).clicked() { + request(app, Pending::New); + } + let models: Vec = app.session.project.models.iter().map(|m| m.name.clone()).collect(); + ui.add_enabled_ui(!models.is_empty(), |ui| { + ui.menu_button(tl!("Open"), |ui| { + for m in &models { + if ui.button(m).clicked() { + if app.mb.saved_as.as_deref() != Some(m) { + request(app, Pending::Open(m.clone())); + } + ui.close(); + } + } + }) + .response + .on_hover_text(tl!("Open a model of this project")); + }); + if ui.button(tl!("Save")).on_hover_text(tl!("Save the model in the project")).clicked() { + save(app); + } + ui.separator(); + let can_run = problems.is_empty(); + let run = ui.add_enabled(can_run, egui::Button::new(egui::RichText::new(format!("▶ {}", tl!("Run"))).strong())); + let run = if can_run { + run.on_hover_text(tl!("Run the model")) + } else { + run.on_disabled_hover_text(tl!("Fix the problems listed below first")) }; - ui.ctx().copy_text(text); - app.mb.log(tl!("Copied the command."), LogKind::Ok); - } - }); - ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - if crate::widgets::icon_button(ui, "close", tl!("Close Model Designer")).clicked() { - request(app, Pending::Close); - } - if crate::widgets::icon_button(ui, "map", tl!("Back to the map")).clicked() { - app.mb.active = false; - } + if run.clicked() { + run_model(app); + } + ui.separator(); + if ui.button(tl!("Arrange")).on_hover_text(tl!("Lay the nodes out along the flow")).clicked() + && !app.mb.graph.nodes.is_empty() + { + app.mb.edit(); + model::layout(&mut app.mb.graph); + app.mb.fit = true; + } + if ui.button(tl!("Fit")).on_hover_text(tl!("Show the whole model")).clicked() { + app.mb.fit = true; + } + ui.add_enabled_ui(!app.mb.undo.is_empty(), |ui| { + if crate::widgets::icon_button(ui, "undo", tl!("Undo (Ctrl+Z)")).clicked() { + app.mb.undo(); + } + }); + ui.add_enabled_ui(!app.mb.redo.is_empty(), |ui| { + if crate::widgets::icon_button(ui, "redo", tl!("Redo (Ctrl+Y)")).clicked() { + app.mb.redo(); + } + }); + ui.separator(); + if ui.button(tl!("Import…")).on_hover_text(tl!("Open a model file (*.model.json)")).clicked() { + import(app); + } + ui.add_enabled_ui(!app.mb.graph.nodes.is_empty(), |ui| { + if ui.button(tl!("Export…")).on_hover_text(tl!("Save the model as a file (*.model.json)")).clicked() { + export(app); + } + if ui + .button(tl!("Copy Command")) + .on_hover_text(tl!("Copy a model.run command that runs this model, for the Script pane or Python")) + .clicked() + { + let name = serde_json::to_string(app.mb.name.trim()).unwrap_or_default(); + // A model from a file runs by name, as saved, so the engine holds it to its rules. + let text = match (&app.mb.saved_as, app.mb.imported) { + (Some(saved), true) => format!("model.run {}", json!({"name": saved})), + _ => format!( + "model.run {{\"name\": {name}, \"graph\": {}}}", + serde_json::to_string(&app.mb.graph).unwrap_or_default() + ), + }; + ui.ctx().copy_text(text); + app.mb.log(tl!("Copied the command."), LogKind::Ok); + } + }); + }); }); }); } diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index 7f002d7904..5e7f298163 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -5347,9 +5347,15 @@ pub(crate) fn reference_scale_row(app: &mut RustGisApp, ui: &mut Ui, l: &Layer) /// (#1803) show it. pub(crate) fn transparency_row(app: &mut RustGisApp, ui: &mut Ui, l: &Layer) { let mut tr = l.transparency; - ui.horizontal(|ui| { + // The slider goes under its label where the pane is too narrow for both. + ui.horizontal_wrapped(|ui| { let input_label = ui.label(tl!("Transparency")); - ui.spacing_mut().slider_width = 150.0; + // Its value box beside it. + const VALUE: f32 = 70.0; + if ui.available_size_before_wrap().x < 100.0 + VALUE { + ui.end_row(); + } + ui.spacing_mut().slider_width = (ui.available_size_before_wrap().x - VALUE).clamp(60.0, 150.0); let r = ui.add(egui::Slider::new(&mut tr, 0.0..=100.0).update_while_editing(false).suffix(" %").integer()).labelled_by(input_label.id); transparency_drag(app, ui, &r, l, tr); diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index e2b83c4176..c0d0ed0882 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -4178,7 +4178,14 @@ fn settings_tab(app: &mut RustGisApp, ui: &mut Ui) { "When a coordinate system's most accurate datum transformation needs a grid RustGIS doesn't have, download it from PROJ's grid server (cdn.proj.org). Grids already downloaded stay in use when this is off: to stop using them, delete the datum-grids folder in RustGIS's app data and start RustGIS again (grids installed for PROJ are still used)." ) }; - let resp = ui.checkbox(&mut on, tl!("Download Datum Grids")).on_hover_text(tip); + // On one line: the column is as narrow as its widest row, so a wrapped label is a letter a line. + let resp = ui + .scope(|ui| { + ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend); + ui.checkbox(&mut on, tl!("Download Datum Grids")) + }) + .inner + .on_hover_text(tip); if resp.clicked() { let _ = app.run("ui.datumGrids", json!({"on": on})); } diff --git a/crates/ui-egui/src/table.rs b/crates/ui-egui/src/table.rs index da037a5aa4..093b9c15c1 100644 --- a/crates/ui-egui/src/table.rs +++ b/crates/ui-egui/src/table.rs @@ -447,76 +447,91 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) { ); { let ui = &mut header_ui; - let (r, _) = ui.allocate_exact_size(vec2(18.0, 18.0), Sense::hover()); - icons::paint(ui.painter(), r, "table", t.icon, t.accent); - ui.label(egui::RichText::new(&title).font(semibold(13.0))); - ui.label( - egui::RichText::new(crate::i18n::fmt( - "{n} of {total} selected", - &[("n", &selected_n.to_string()), ("total", &total_n.to_string())], - )) - .size(11.5) - .color(t.text_dim), - ); - if hidden_n > 0 - && ui - .add(egui::Button::new( - egui::RichText::new(crate::i18n::fmt("Hidden columns: {n}", &[("n", &hidden_n.to_string())])) - .size(11.5) - .color(t.accent), - )) - .on_hover_text(tl!("Show All Columns")) - .clicked() - { - show_all = true; - } - ui.add_space(10.0); - if is_layer { - small( - ui, - app, - "select_attr", - "Select By Attributes", - "Select rows with a SQL expression.", - "ui.dialog", - json!({"name": "selectByAttributes"}), - false, - ); - small(ui, app, "zoom_sel", "", "Zoom to selection", "select.zoomTo", Value::Null, false); - small(ui, app, "select", "", "Switch selection", "select.switch", Value::Null, false); - small(ui, app, "clear_sel", "", "Clear selection", "select.clear", Value::Null, false); - small(ui, app, "delete", "", "Delete selected rows", "edit.delete", Value::Null, false); - small(ui, app, "field", "", "Add field", "ui.dialog", json!({"name": "addField"}), false); - small(ui, app, "calculate", "", "Calculate field", "ui.dialog", json!({"name": "calculateField"}), false); - // The table's layer, even when another layer is active in Layers. - small( - ui, - app, - "calc_geom", - "", - "Calculate Geometry", - "ui.dialog", - json!({"name": "calculateGeometry", "layer": layer_id}), - false, - ); - ui.add_space(6.0); - ui.checkbox(&mut app.table.selected_only, egui::RichText::new(tl!("Selected only")).size(11.5)); - } else if let ViewKey::Table(id) = key { - // A standalone table: rows and fields, judged as the commands judge them. - let add_row = json!({"table": id}); - let why = app.session.why_blocked("edit.addFeature", &add_row); - small_for(ui, app, "new", "", "Add row", "edit.addFeature", add_row, why); - small(ui, app, "field", "", "Add field", "ui.dialog", json!({"name": "addField", "table": id}), false); - small(ui, app, "calculate", "", "Calculate field", "ui.dialog", json!({"name": "calculateField", "table": id}), false); - ui.add_space(6.0); - } - ui.add(egui::TextEdit::singleline(&mut app.table.filter).hint_text(tl!("Filter rows…")).desired_width(160.0)); + // Close stays at the end in sight; the rest scrolls sideways where the view is + // narrower than the toolbar. ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { if ui.add(egui::Button::new(tl!("×")).frame(false)).on_hover_text(tl!("Close table")).clicked() { app.session.table_layer = None; app.session.table_standalone = None; app.table.editing = None; } + ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| { + crate::widgets::scrolling_row(ui, "table_toolbar", |ui| { + let (r, _) = ui.allocate_exact_size(vec2(18.0, 18.0), Sense::hover()); + icons::paint(ui.painter(), r, "table", t.icon, t.accent); + ui.label(egui::RichText::new(&title).font(semibold(13.0))); + ui.label( + egui::RichText::new(crate::i18n::fmt( + "{n} of {total} selected", + &[("n", &selected_n.to_string()), ("total", &total_n.to_string())], + )) + .size(11.5) + .color(t.text_dim), + ); + if hidden_n > 0 + && ui + .add(egui::Button::new( + egui::RichText::new(crate::i18n::fmt("Hidden columns: {n}", &[("n", &hidden_n.to_string())])) + .size(11.5) + .color(t.accent), + )) + .on_hover_text(tl!("Show All Columns")) + .clicked() + { + show_all = true; + } + ui.add_space(10.0); + if is_layer { + small( + ui, + app, + "select_attr", + "Select By Attributes", + "Select rows with a SQL expression.", + "ui.dialog", + json!({"name": "selectByAttributes"}), + false, + ); + small(ui, app, "zoom_sel", "", "Zoom to selection", "select.zoomTo", Value::Null, false); + small(ui, app, "select", "", "Switch selection", "select.switch", Value::Null, false); + small(ui, app, "clear_sel", "", "Clear selection", "select.clear", Value::Null, false); + small(ui, app, "delete", "", "Delete selected rows", "edit.delete", Value::Null, false); + small(ui, app, "field", "", "Add field", "ui.dialog", json!({"name": "addField"}), false); + small(ui, app, "calculate", "", "Calculate field", "ui.dialog", json!({"name": "calculateField"}), false); + // The table's layer, even when another layer is active in Layers. + small( + ui, + app, + "calc_geom", + "", + "Calculate Geometry", + "ui.dialog", + json!({"name": "calculateGeometry", "layer": layer_id}), + false, + ); + ui.add_space(6.0); + ui.checkbox(&mut app.table.selected_only, egui::RichText::new(tl!("Selected only")).size(11.5)); + } else if let ViewKey::Table(id) = key { + // A standalone table: rows and fields, judged as the commands judge them. + let add_row = json!({"table": id}); + let why = app.session.why_blocked("edit.addFeature", &add_row); + small_for(ui, app, "new", "", "Add row", "edit.addFeature", add_row, why); + small(ui, app, "field", "", "Add field", "ui.dialog", json!({"name": "addField", "table": id}), false); + small( + ui, + app, + "calculate", + "", + "Calculate field", + "ui.dialog", + json!({"name": "calculateField", "table": id}), + false, + ); + ui.add_space(6.0); + } + ui.add(egui::TextEdit::singleline(&mut app.table.filter).hint_text(tl!("Filter rows…")).desired_width(160.0)); + }); + }); }); } // The grid borrows the data source (the toolbar's commands may have changed it) until diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index ce086735b8..450990ec08 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -60,6 +60,36 @@ impl Dragged { } } +/// A box's width: `want`, or less where the row has less room, so it doesn't push past the pane. +pub(crate) fn fit(ui: &Ui, want: f32) -> f32 { + ui.available_width().clamp(40.0, want) +} + +/// Lays `add` out in a row that scrolls sideways where it is wider than the space: a toolbar of a +/// fixed height, which can't wrap. Its scroll bar is a thin one under the row, not over the +/// buttons, and a control reached with Tab is scrolled into view. +pub(crate) fn scrolling_row(ui: &mut Ui, id: &str, add: impl FnOnce(&mut Ui) -> R) -> R { + ui.scope(|ui| { + ui.spacing_mut().scroll = + egui::style::ScrollStyle { bar_width: 3.0, bar_inner_margin: 1.0, bar_outer_margin: 0.0, ..egui::style::ScrollStyle::solid() }; + egui::ScrollArea::horizontal() + .id_salt(id) + .scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded) + .show(ui, |ui| { + let out = ui.horizontal_centered(add).inner; + if let Some(focused) = ui.memory(|m| m.focused()).and_then(|id| ui.ctx().read_response(id)) + && focused.gained_focus() + && ui.max_rect().intersects(focused.rect) + { + focused.scroll_to_me(None); + } + out + }) + .inner + }) + .inner +} + /// What a row that can be dragged to another place (`reorder`) senses (#2958): clicks, and drags /// unless a finger is on the screen. While a finger is down the list's drag-to-scroll must win a /// swipe, so the row senses clicks only and `reorder_drag` arms its drag by a long press. The @@ -885,7 +915,12 @@ pub fn ribbon_combo(ui: &mut Ui, id: &str, label: &str, current: &str, options: pub fn primary_button(ui: &mut Ui, label: &str, enabled: bool, min_size: egui::Vec2) -> Response { let t = Tokens::get(ui.ctx()); let font = semibold(13.0); - let size = vec2(min_size.x.max(text_w(ui, label, font.clone()) + 28.0), min_size.y.max(28.0)); + // A label wider than the room wraps, and the button grows taller, rather than wider than its pane. + let room = ui.available_width().max(min_size.x); + let wrapped = ui.painter().layout(label.to_string(), font.clone(), egui::Color32::WHITE, (room - 28.0).max(40.0)); + let lines = wrapped.rows.len(); + let tall = if lines > 1 { wrapped.size().y + 12.0 } else { 0.0 }; + let size = vec2(min_size.x.max((wrapped.size().x + 28.0).min(room)), min_size.y.max(28.0).max(tall)); let (r, resp) = ui.allocate_exact_size(size, if enabled { Sense::click() } else { Sense::hover() }); // Screen readers (and UI tests) find it by its label. resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, enabled, label)); @@ -899,7 +934,11 @@ pub fn primary_button(ui: &mut Ui, label: &str, enabled: bool, min_size: egui::V t.green }; ui.painter().rect_filled(r, CornerRadius::same(6), fill); - centred_label(ui, r, label, font, egui::Color32::WHITE); + if lines > 1 { + ui.painter().galley((r.center() - wrapped.size() / 2.0).round(), wrapped, egui::Color32::WHITE); + } else { + centred_label(ui, r, label, font, egui::Color32::WHITE); + } if enabled { resp.on_hover_cursor(egui::CursorIcon::PointingHand) } else { resp } } @@ -1077,6 +1116,28 @@ pub fn picked_colour(hsva: egui::ecolor::Hsva, before: egui::ecolor::Hsva, old: mod tests { use egui_kittest::kittest::Queryable; + /// A toolbar control reached with Tab past the row's visible part is scrolled into view, so + /// Enter doesn't press a button out of sight. + #[test] + fn a_control_reached_with_tab_scrolls_into_view() { + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(200.0, 60.0)).build_ui(|ui| { + super::scrolling_row(ui, "test_row", |ui| { + for label in ["First button", "Second button", "Third button", "Last button"] { + let _ = ui.button(label); + } + }); + }); + h.run(); + for _ in 0..4 { + h.key_press(egui::Key::Tab); + h.run(); + } + let last = h.get_by_label("Last button"); + assert!(last.is_focused(), "Tab reached the last button"); + let rect = last.rect(); + assert!(rect.max.x <= 200.0 + 0.5 && rect.min.x >= -0.5, "{rect:?} is out of view"); + } + /// #2958: a long press whose row is gone when the finger lifts arms no later press, even when /// the row comes back under a finger already down. #[test] diff --git a/crates/ui-egui/src/workspacepanes.rs b/crates/ui-egui/src/workspacepanes.rs index 43a8047935..cff15affee 100644 --- a/crates/ui-egui/src/workspacepanes.rs +++ b/crates/ui-egui/src/workspacepanes.rs @@ -303,8 +303,9 @@ pub fn tasks(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { /// The Workflow Manager: jobs with their status. pub fn jobs(app: &mut RustGisApp, ui: &mut Ui, _t: &Tokens) { message(app, ui); - ui.horizontal(|ui| { - ui.add(egui::TextEdit::singleline(&mut app.ws.job_name).hint_text(tl!("New job name")).desired_width(170.0)); + ui.horizontal_wrapped(|ui| { + let width = crate::widgets::fit(ui, 170.0); + ui.add(egui::TextEdit::singleline(&mut app.ws.job_name).hint_text(tl!("New job name")).desired_width(width)); if ui.button(tl!("Add Job")).on_hover_text(tl!("The job covers the map view")).clicked() { let name = app.ws.job_name.trim().to_string(); if run(app, "job.new", json!({"name": name, "viewExtent": true})).is_some() {