Skip to content

Commit dbb46bb

Browse files
committed
Notification banner: Set max height to four lines
Set maximum line count to show in notification banner to 4 lines. After that the text will be truncated
1 parent f217411 commit dbb46bb

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

‎crates/app/src/host/ui/notification/banner.rs‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::time::{Duration, Instant};
44

55
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,
88
};
99

1010
use super::NotificationEntry;
@@ -95,10 +95,22 @@ impl NotificationBanner {
9595
let dot_radius = respond.rect.width() / 2.0;
9696
painter.circle_filled(respond.rect.center(), dot_radius, level_color);
9797

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);
102114
});
103115
})
104116
.response

0 commit comments

Comments
 (0)