mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Don't hide whitespaces in centered and right aligned text edits (#8102)
When enabled, trailing whitespace is included in the row width used for horizontal alignment. This is useful for text editors where hiding trailing spaces feels wrong when typing. By default this is `false`, preserving existing behavior where trailing whitespace is stripped for alignment (so "Hello " centers the same as "Hello"). * follow up to https://github.com/emilk/egui/pull/8082
This commit is contained in:
@@ -162,6 +162,7 @@ pub fn layout(fonts: &mut FontsImpl, pixels_per_point: f32, job: Arc<LayoutJob>)
|
||||
job.halign,
|
||||
job.wrap.max_width,
|
||||
justify_row,
|
||||
job.keep_trailing_whitespace,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -855,6 +856,7 @@ fn halign_and_justify_row(
|
||||
halign: Align,
|
||||
wrap_width: f32,
|
||||
justify: bool,
|
||||
keep_trailing_whitespace: bool,
|
||||
) {
|
||||
#![expect(clippy::useless_let_if_seq)] // False positive
|
||||
|
||||
@@ -873,6 +875,8 @@ fn halign_and_justify_row(
|
||||
let glyph_range = if num_leading_spaces == row.glyphs.len() {
|
||||
// There is only whitespace
|
||||
(0, row.glyphs.len())
|
||||
} else if keep_trailing_whitespace {
|
||||
(num_leading_spaces, row.glyphs.len())
|
||||
} else {
|
||||
let num_trailing_spaces = row
|
||||
.glyphs
|
||||
|
||||
Reference in New Issue
Block a user