Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

UI: captions in a sideways-scrolled bar stay on one line

aiongg9fec15876a67
diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs
index ffaf762c9..23876f3a7 100644
--- a/crates/ui-egui/src/chrome.rs
+++ b/crates/ui-egui/src/chrome.rs
@@ -807,4 +807,18 @@ mod tests {
let after = [rect(&h, FIRST_CONTROL), rect(&h, LAST_CONTROL), rect(&h, "Help"), rect(&h, "Share")];
assert_eq!(after, before);
}
+
+ #[test]
+ fn a_scrolled_bar_keeps_its_captions_on_one_line() {
+ let mut app = app();
+ app.run("file.new", serde_json::json!({})).unwrap();
+ let f = app.run("frame.create", serde_json::json!({"rect": [72, 72, 300, 200], "content": "text", "text": "Hello"})).unwrap();
+ app.run("selection.set", serde_json::json!({"ids": [f["id"]]})).unwrap();
+ let mut h = test_window::open(app, vec2(700.0, 600.0));
+ let bar = test_window::panel_rect(&h, "control_bar").center();
+ wheel(&mut h, bar, vec2(0.0, -3000.0));
+ // The text frame's last group: its caption gets only what is left of the row.
+ let columns = h.get_by_label("Columns").rect();
+ assert!(columns.height() < 20.0 && columns.width() > columns.height(), "Columns wraps: {columns:?}");
+ }
}
diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs
index 9d4d8c196..dd7f3d8b7 100644
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@ -578,6 +578,8 @@ pub fn segmented(ui: &mut Ui, labels: &[&str], active: usize, width: f32) -> Opt
pub fn overflow_scrolling(ui: &mut Ui) {
let style = ui.style_mut();
style.always_scroll_the_only_direction = true;
+ // A caption at the end of a scrolled row gets only what is left of it: extend, don't wrap.
+ style.wrap_mode = Some(egui::TextWrapMode::Extend);
let s = &mut style.spacing.scroll;
*s = egui::style::ScrollStyle::floating();
s.bar_width = 6.0;