Skip to content

Commit 5bb20f5

Browse files
authored
Fix links and text selection in horizontal_wrapped layout (#6905)
* Closes <#6904> * [x] I have followed the instructions in the PR template This was broken in #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.
1 parent 71e0b08 commit 5bb20f5

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

crates/egui/src/text_selection/accesskit_text.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn update_accesskit_for_text_widget(
4545
let row_id = parent_id.with(row_index);
4646
ctx.accesskit_node_builder(row_id, |builder| {
4747
builder.set_role(accesskit::Role::TextRun);
48-
let rect = global_from_galley * row.rect();
48+
let rect = global_from_galley * row.rect_without_leading_space();
4949
builder.set_bounds(accesskit::Rect {
5050
x0: rect.min.x.into(),
5151
y0: rect.min.y.into(),

crates/egui/src/widgets/label.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ impl Label {
216216
let pos = pos2(ui.max_rect().left(), ui.cursor().top());
217217
assert!(!galley.rows.is_empty(), "Galleys are never empty");
218218
// collect a response from many rows:
219-
let rect = galley.rows[0].rect().translate(pos.to_vec2());
219+
let rect = galley.rows[0]
220+
.rect_without_leading_space()
221+
.translate(pos.to_vec2());
220222
let mut response = ui.allocate_rect(rect, sense);
221223
for placed_row in galley.rows.iter().skip(1) {
222224
let rect = placed_row.rect().translate(pos.to_vec2());

crates/epaint/src/text/text_layout_types.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,18 @@ pub struct PlacedRow {
576576

577577
impl PlacedRow {
578578
/// Logical bounding rectangle on font heights etc.
579-
/// Use this when drawing a selection or similar!
579+
///
580+
/// This ignores / includes the `LayoutSection::leading_space`.
580581
pub fn rect(&self) -> Rect {
581582
Rect::from_min_size(self.pos, self.row.size)
582583
}
584+
585+
/// Same as [`Self::rect`] but excluding the `LayoutSection::leading_space`.
586+
pub fn rect_without_leading_space(&self) -> Rect {
587+
let x = self.glyphs.first().map_or(self.pos.x, |g| g.pos.x);
588+
let size_x = self.size.x - x;
589+
Rect::from_min_size(Pos2::new(x, self.pos.y), Vec2::new(size_x, self.size.y))
590+
}
583591
}
584592

585593
impl std::ops::Deref for PlacedRow {

0 commit comments

Comments
 (0)