Skip to content

Fix links and text selection in horizontal_wrapped layout #6905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/egui/src/text_selection/accesskit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
10 changes: 5 additions & 5 deletions crates/egui/src/widgets/label.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::sync::Arc;

use crate::{
epaint, pos2, text_selection, Align, Direction, FontSelection, Galley, Pos2, Response, Sense,
Stroke, TextWrapMode, Ui, Widget, WidgetInfo, WidgetText, WidgetType,
epaint, pos2, text_selection::LabelSelectionState, Align, Direction, FontSelection, Galley,
Pos2, Response, Sense, Stroke, TextWrapMode, Ui, Widget, WidgetInfo, WidgetText, WidgetType,
};

use self::text_selection::LabelSelectionState;

/// Static text.
///
/// Usually it is more convenient to use [`Ui::label`].
Expand Down Expand Up @@ -216,7 +214,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());
Expand Down
10 changes: 9 additions & 1 deletion crates/epaint/src/text/text_layout_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,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 {
Expand Down
Loading