|
3 | 3 | use std::time::{Duration, Instant}; |
4 | 4 |
|
5 | 5 | use egui::{ |
6 | | - Align2, Area, Color32, Frame, Id, Label, Margin, NumExt, Order, Rect, RichText, Sense, Stroke, |
7 | | - TextWrapMode, Ui, Vec2, pos2, |
| 6 | + Align2, Area, Color32, FontSelection, Frame, Id, Label, Margin, NumExt, Order, Rect, RichText, |
| 7 | + Sense, Stroke, TextWrapMode, Ui, Vec2, pos2, text::LayoutJob, |
8 | 8 | }; |
9 | 9 |
|
10 | 10 | use super::NotificationEntry; |
@@ -95,10 +95,22 @@ impl NotificationBanner { |
95 | 95 | let dot_radius = respond.rect.width() / 2.0; |
96 | 96 | painter.circle_filled(respond.rect.center(), dot_radius, level_color); |
97 | 97 |
|
98 | | - let message = |
99 | | - Label::new(RichText::new(&entry.message).color(text_color)) |
100 | | - .wrap_mode(TextWrapMode::Wrap); |
101 | | - ui.add(message); |
| 98 | + const MESSAGE_MAX_ROWS: usize = 4; |
| 99 | + |
| 100 | + let message_text = RichText::new(&entry.message).color(text_color); |
| 101 | + // Limit wrapped rows without adding scrolling to the transient banner. |
| 102 | + let mut message_job = LayoutJob::default(); |
| 103 | + message_text.append_to( |
| 104 | + &mut message_job, |
| 105 | + ui.style(), |
| 106 | + FontSelection::Default, |
| 107 | + ui.text_valign(), |
| 108 | + ); |
| 109 | + message_job.wrap.max_rows = MESSAGE_MAX_ROWS; |
| 110 | + let message_label = Label::new(message_job) |
| 111 | + .wrap_mode(TextWrapMode::Wrap) |
| 112 | + .show_tooltip_when_elided(false); |
| 113 | + ui.add(message_label); |
102 | 114 | }); |
103 | 115 | }) |
104 | 116 | .response |
|
0 commit comments