Fix links and text selection in horizontal_wrapped layout (#6905)

* Closes <https://github.com/emilk/egui/issues/6904>
* [x] I have followed the instructions in the PR template

This was broken in https://github.com/emilk/egui/pull/5411. Not sure if
this is the best fix or if `PlacedRow::rect` should be updated, but I
think it makes sense that PlacedRow::rect ignores leading space.
This commit is contained in:
Lucas Meurer 2025-05-06 17:40:18 +02:00 committed by GitHub
parent 71e0b0859c
commit 5bb20f511e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 3 deletions

View File

@ -45,7 +45,7 @@ pub fn update_accesskit_for_text_widget(
let row_id = parent_id.with(row_index);
ctx.accesskit_node_builder(row_id, |builder| {
builder.set_role(accesskit::Role::TextRun);
let rect = global_from_galley * row.rect();
let rect = global_from_galley * row.rect_without_leading_space();
builder.set_bounds(accesskit::Rect {
x0: rect.min.x.into(),
y0: rect.min.y.into(),

View File

@ -216,7 +216,9 @@ impl Label {
let pos = pos2(ui.max_rect().left(), ui.cursor().top());
assert!(!galley.rows.is_empty(), "Galleys are never empty");
// collect a response from many rows:
let rect = galley.rows[0].rect().translate(pos.to_vec2());
let rect = galley.rows[0]
.rect_without_leading_space()
.translate(pos.to_vec2());
let mut response = ui.allocate_rect(rect, sense);
for placed_row in galley.rows.iter().skip(1) {
let rect = placed_row.rect().translate(pos.to_vec2());

View File

@ -576,10 +576,18 @@ pub struct PlacedRow {
impl PlacedRow {
/// Logical bounding rectangle on font heights etc.
/// Use this when drawing a selection or similar!
///
/// This ignores / includes the `LayoutSection::leading_space`.
pub fn rect(&self) -> Rect {
Rect::from_min_size(self.pos, self.row.size)
}
/// Same as [`Self::rect`] but excluding the `LayoutSection::leading_space`.
pub fn rect_without_leading_space(&self) -> Rect {
let x = self.glyphs.first().map_or(self.pos.x, |g| g.pos.x);
let size_x = self.size.x - x;
Rect::from_min_size(Pos2::new(x, self.pos.y), Vec2::new(size_x, self.size.y))
}
}
impl std::ops::Deref for PlacedRow {