mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Fix text selection of centered and right-aligned text (#8076)
* Fixes https://github.com/emilk/egui/issues/8049 * Bug introduced in https://github.com/emilk/egui/pull/7831
This commit is contained in:
committed by
lucasmerlin
parent
daae4ce652
commit
4e1567cecb
@@ -7,17 +7,21 @@ pub struct TextLayoutDemo {
|
||||
overflow_character: Option<char>,
|
||||
extra_letter_spacing: f32,
|
||||
line_height_pixels: u32,
|
||||
halign: egui::Align,
|
||||
justify: bool,
|
||||
lorem_ipsum: bool,
|
||||
}
|
||||
|
||||
impl Default for TextLayoutDemo {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
max_rows: 6,
|
||||
break_anywhere: true,
|
||||
max_rows: 1000,
|
||||
break_anywhere: false,
|
||||
overflow_character: Some('…'),
|
||||
extra_letter_spacing: 0.0,
|
||||
line_height_pixels: 0,
|
||||
halign: egui::Align::LEFT,
|
||||
justify: false,
|
||||
lorem_ipsum: true,
|
||||
}
|
||||
}
|
||||
@@ -48,6 +52,8 @@ impl crate::View for TextLayoutDemo {
|
||||
overflow_character,
|
||||
extra_letter_spacing,
|
||||
line_height_pixels,
|
||||
halign,
|
||||
justify,
|
||||
lorem_ipsum,
|
||||
} = self;
|
||||
|
||||
@@ -109,6 +115,18 @@ impl crate::View for TextLayoutDemo {
|
||||
});
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Horizontal align:");
|
||||
ui.horizontal(|ui| {
|
||||
ui.selectable_value(halign, egui::Align::LEFT, "Left");
|
||||
ui.selectable_value(halign, egui::Align::Center, "Center");
|
||||
ui.selectable_value(halign, egui::Align::RIGHT, "Right");
|
||||
});
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Justify:");
|
||||
ui.checkbox(justify, "Fill row width");
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Text:");
|
||||
ui.horizontal(|ui| {
|
||||
ui.selectable_value(lorem_ipsum, true, "Lorem Ipsum");
|
||||
@@ -145,8 +163,14 @@ impl crate::View for TextLayoutDemo {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// NOTE: `Label` overrides some of the wrapping settings, e.g. wrap width
|
||||
ui.label(job);
|
||||
// NOTE: `Label` overrides some of the wrapping settings,
|
||||
// e.g. wrap width, halign, and justify.
|
||||
ui.with_layout(
|
||||
egui::Layout::top_down(*halign).with_cross_justify(*justify),
|
||||
|ui| {
|
||||
ui.label(job);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user