Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion crates/ui-egui/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@ pub fn status_bar(app: &mut RustGisApp, ui: &mut Ui) {
.show(ui, |ui| {
let r = ui.max_rect();
ui.painter().line_segment([pos2(r.min.x - 10.0, r.min.y), pos2(r.max.x + 10.0, r.min.y)], Stroke::new(1.0, t.border));
// Changing readouts never resize the map: layout and paint stay inside the fixed
// strip even when a system font or a coordinate needs more room.
let mut content = ui.new_child(egui::UiBuilder::new().max_rect(r));
content.shrink_clip_rect(r);
let ui = &mut content;
ui.horizontal_centered(|ui| {
ui.spacing_mut().item_spacing = vec2(10.0, 0.0);
// The readouts take the room the right-hand group leaves (as wide as it was last
Expand All @@ -399,7 +404,7 @@ pub fn status_bar(app: &mut RustGisApp, ui: &mut Ui) {
let room = ui.available_width() - ui.data(|d| d.get_temp::<f32>(right)).unwrap_or(0.0) - 10.0;
let size = vec2(room.max(0.0), ui.available_height());
ui.allocate_ui_with_layout(size, egui::Layout::left_to_right(egui::Align::Center), |ui| {
crate::widgets::scrolling_row(ui, "status_readouts", |ui| readouts(app, ui, &t));
crate::widgets::floating_scrolling_row(ui, "status_readouts", |ui| readouts(app, ui, &t));
});
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
// The CPU/GPU backend toggle, then the frame rate (live while the map moves,
Expand Down Expand Up @@ -2657,6 +2662,30 @@ mod tests {
}
}

#[test]
fn scrolling_status_readouts_keep_the_map_height() {
let mut h = egui_kittest::Harness::builder().with_size(vec2(975.0, 550.0)).build_ui_state(
|ui, app: &mut RustGisApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
// A taller font reproduces the system-font metrics on Windows.
ui.style_mut().text_styles.insert(egui::TextStyle::Body, crate::theme::regular(18.0));
app.ui(ui);
},
RustGisApp::with_sample(),
);
for _ in 0..10 {
h.step();
}
let before = h.state().map.view_rect.expect("map").0;
h.input_mut().events.push(egui::Event::PointerMoved(before.center()));
for _ in 0..10 {
h.step();
assert_eq!(h.state().map.view_rect.expect("map").0, before, "a readout must not resize the map");
}
assert!(h.state().map.pointer_lonlat.is_some(), "the pointer reached the map");
}

/// Runs the real toolbar and advances queued history steps on the following frames.
fn history_toolbar(app: RustGisApp, width: f32) -> egui_kittest::Harness<'static, RustGisApp> {
egui_kittest::Harness::builder()
Expand Down
19 changes: 17 additions & 2 deletions crates/ui-egui/src/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,24 @@ pub(crate) fn fit(ui: &Ui, want: f32) -> f32 {
/// 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<R>(ui: &mut Ui, id: &str, add: impl FnOnce(&mut Ui) -> R) -> R {
scrolling_row_inner(ui, id, false, add)
}

/// A row inside a fixed-height strip: its scroll bar floats over the bottom instead of taking
/// height from its controls as it appears.
pub(crate) fn floating_scrolling_row<R>(ui: &mut Ui, id: &str, add: impl FnOnce(&mut Ui) -> R) -> R {
scrolling_row_inner(ui, id, true, add)
}

fn scrolling_row_inner<R>(ui: &mut Ui, id: &str, floating_bar: bool, 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() };
ui.spacing_mut().scroll = egui::style::ScrollStyle {
floating: floating_bar,
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)
Expand Down
Loading