From 3416f3b91f608d370fc66e00460ccfba57b52d01 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 24 Oct 2020 10:10:08 +0200 Subject: [PATCH] [style] Wrap tooltip text earlier --- egui/src/containers/popup.rs | 7 ++++++- egui/src/style.rs | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/egui/src/containers/popup.rs b/egui/src/containers/popup.rs index ec50d179..de3efbb4 100644 --- a/egui/src/containers/popup.rs +++ b/egui/src/containers/popup.rs @@ -31,5 +31,10 @@ fn show_popup( .order(Order::Tooltip) .fixed_pos(window_pos) .interactable(false) - .show(ctx, |ui| Frame::popup(&ctx.style()).show(ui, add_contents)) + .show(ctx, |ui| { + Frame::popup(&ctx.style()).show(ui, |ui| { + ui.set_max_width(ui.style().spacing.tooltip_width); + add_contents(ui); + }) + }) } diff --git a/egui/src/style.rs b/egui/src/style.rs index 0fb24681..fcbd25f8 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -67,6 +67,9 @@ pub struct Spacing { /// Checkboxes, radio button and collapsing headers have an icon at the start. /// This is the spacing between the icon and the text pub icon_spacing: f32, + + /// Width of a tooltip (`on_hover_ui`, `on_hover_text` etc). + pub tooltip_width: f32, } impl Spacing { @@ -231,6 +234,7 @@ impl Default for Spacing { slider_width: 140.0, icon_width: 16.0, icon_spacing: 1.0, + tooltip_width: 400.0, } } } @@ -348,6 +352,7 @@ impl Spacing { slider_width, icon_width, icon_spacing, + tooltip_width, } = self; ui_slider_vec2(ui, item_spacing, 0.0..=10.0, "item_spacing"); @@ -359,6 +364,7 @@ impl Spacing { ui.add(Slider::f32(slider_width, 0.0..=1000.0).text("slider_width")); ui.add(Slider::f32(icon_width, 0.0..=60.0).text("icon_width")); ui.add(Slider::f32(icon_spacing, 0.0..=10.0).text("icon_spacing")); + ui.add(Slider::f32(tooltip_width, 0.0..=10.0).text("tooltip_width")); } }