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
This commit is contained in:
Emil Ernerfeldt 2024-06-25 10:15:04 +02:00 committed by GitHub
parent 5a6d68c5f6
commit 07735a6465
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 2 deletions

View File

@ -182,8 +182,21 @@ impl Label {
} }
(pos, galley, response) (pos, galley, response)
} else { } else {
layout_job.wrap = // Apply wrap_mode, but don't overwrite anything important
text::TextWrapping::from_wrap_mode_and_width(wrap_mode, available_width); // 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() { if ui.is_grid() {
// TODO(emilk): remove special Grid hacks like these // TODO(emilk): remove special Grid hacks like these