From 07735a646519455237d79d56bcd98570deef8f19 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 25 Jun 2024 10:15:04 +0200 Subject: [PATCH] Fix: respect existing text layout wrap settings in Label (#4704) * Broke in github.com/emilk/egui/pull/4556 * Closes https://github.com/emilk/egui/issues/4701 --- crates/egui/src/widgets/label.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widgets/label.rs b/crates/egui/src/widgets/label.rs index de6cc98dfe2..c6d44a3e14f 100644 --- a/crates/egui/src/widgets/label.rs +++ b/crates/egui/src/widgets/label.rs @@ -182,8 +182,21 @@ impl Label { } (pos, galley, response) } else { - layout_job.wrap = - text::TextWrapping::from_wrap_mode_and_width(wrap_mode, available_width); + // Apply wrap_mode, but don't overwrite anything important + // the user may have set manually on the layout_job: + match wrap_mode { + TextWrapMode::Extend => { + layout_job.wrap.max_width = f32::INFINITY; + } + TextWrapMode::Wrap => { + layout_job.wrap.max_width = available_width; + } + TextWrapMode::Truncate => { + layout_job.wrap.max_width = available_width; + layout_job.wrap.max_rows = 1; + layout_job.wrap.break_anywhere = true; + } + } if ui.is_grid() { // TODO(emilk): remove special Grid hacks like these