Wrap long transport tooltips within the current window

The tray's 360-point window clipped the end of the AmneziaWG description
because hover labels used egui's default 500-point tooltip width. Give the
shared hint renderer the smaller of the theme width and the viewport
width after popup margins, and explicitly wrap text. Mouse hover,
disabled controls, keyboard focus and touch now use the same layout.

Reproduced the original one-line overflow before the fix. Headless egui
checks now confirm that the complete glyph bounds of the actual AmneziaWG
description fit inside both the viewport and the tooltip clip rectangle
at widths of 360, 320 and 240 points. Checked formatting, strict workspace
Clippy and the macOS workspace test suite. Rebuilt and relaunched the
isolated preview with its existing test network.
This commit is contained in:
Aleksandr Bogomiakov committed 2026-11-26 15:16:56 +02:00
1 parent 16d7f82af5
commit 6e71d8cf8c
2 files changed
+67 -10

No files matched your search

@@ -54,6 +54,58 @@ fn keyboard_focus_explains_an_icon_and_the_shared_font_contains_the_status_glyph
assert!(label(&draw(0.2), "Show secret").is_some()); assert!(label(&draw(0.2), "Show secret").is_some());
} }
#[test]
fn long_protocol_hints_wrap_inside_narrow_windows_on_hover_and_focus() {
const DETAIL: &str =
"Pairwise Amnezia-masked UDP with fresh private profiles on every connection attempt";
for (width, enabled, focus) in [
(360., true, false),
(320., false, false),
(240., true, true),
] {
let ctx = Context::default();
ctx.set_os(egui::os::OperatingSystem::Mac);
ctx.set_fonts(crate::app_fonts());
ctx.style_mut(|s| s.interaction.tooltip_delay = 0.);
let size = egui::vec2(width, 400.);
let draw = |time, events| {
frame(&ctx, size, time, events, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
let button = ui.add_enabled(enabled, egui::Button::new(icon::INFO));
if focus {
button.request_focus();
}
crate::widgets::hint(button, DETAIL);
});
});
})
};
let first = draw(0., vec![]);
let pos = label(&first, icon::INFO).unwrap().center();
draw(0.1, vec![Event::PointerMoved(pos)]);
draw(0.8, vec![]);
let out = draw(1., vec![]);
let (text, clip) = out
.shapes
.iter()
.find_map(|s| match &s.shape {
egui::Shape::Text(t) if t.galley.text() == DETAIL => Some((t, s.clip_rect)),
_ => None,
})
.expect("the full tooltip should be shown");
let ink = text.visual_bounding_rect();
assert!(
text.galley.rows.len() > 1,
"the tooltip stayed on one line at width {width}"
);
assert!(
Rect::from_min_size(Pos2::ZERO, size).contains_rect(ink) && clip.contains_rect(ink),
"window {width}, clip {clip:?}, text {ink:?}"
);
}
}
struct ReadOnly; struct ReadOnly;
impl Client for ReadOnly { impl Client for ReadOnly {
fn busy(&self) -> bool { fn busy(&self) -> bool {
+15 -10
View File
@@ -26,23 +26,28 @@ pub fn hint(response: Response, description: &str) -> Response {
let held = ctx let held = ctx
.data(|d| d.get_temp::<(egui::Id, f64)>(key)) .data(|d| d.get_temp::<(egui::Id, f64)>(key))
.filter(|(id, until)| touch && *id == response.id && now < *until); .filter(|(id, until)| touch && *id == response.id && now < *until);
let contents = |ui: &mut Ui| {
let padding = egui::Frame::popup(ui.style()).total_margin().sum().x;
let available = (ui.ctx().screen_rect().width() - padding).max(1.);
ui.set_max_width(ui.spacing().tooltip_width.min(available));
ui.add(egui::Label::new(description).wrap());
};
if held.is_some() || (!touch && response.has_focus()) { if held.is_some() || (!touch && response.has_focus()) {
egui::show_tooltip_for(ctx, response.layer_id, response.id, &response.rect, |ui| { egui::show_tooltip_for(
ui.set_max_width( ctx,
ui.spacing() response.layer_id,
.tooltip_width response.id,
.min(ctx.screen_rect().width() - 16.), &response.rect,
); contents,
ui.label(description); );
});
if let Some((_, until)) = held { if let Some((_, until)) = held {
ctx.request_repaint_after_secs((until - now) as f32); ctx.request_repaint_after_secs((until - now) as f32);
} }
response response
} else { } else {
response response
.on_hover_text(description) .on_hover_ui(contents)
.on_disabled_hover_text(description) .on_disabled_hover_ui(contents)
} }
} }