mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 23:00:04 -04:00
Properly handle row repositioning
This commit is contained in:
@@ -39,11 +39,11 @@ pub fn update_accesskit_for_text_widget(
|
||||
};
|
||||
|
||||
ctx.with_accessibility_parent(parent_id, || {
|
||||
for (row_index, (row, offset)) in galley.rows.iter().enumerate() {
|
||||
for (row_index, row) in galley.rows.iter().enumerate() {
|
||||
let row_id = parent_id.with(row_index);
|
||||
ctx.accesskit_node_builder(row_id, |builder| {
|
||||
builder.set_role(accesskit::Role::TextRun);
|
||||
let rect = row.rect.translate(offset.to_vec2() + galley_pos.to_vec2());
|
||||
let rect = row.rect().translate(galley_pos.to_vec2());
|
||||
builder.set_bounds(accesskit::Rect {
|
||||
x0: rect.min.x.into(),
|
||||
y0: rect.min.y.into(),
|
||||
@@ -74,14 +74,14 @@ pub fn update_accesskit_for_text_widget(
|
||||
let old_len = value.len();
|
||||
value.push(glyph.chr);
|
||||
character_lengths.push((value.len() - old_len) as _);
|
||||
character_positions.push(glyph.pos.x - row.rect.min.x);
|
||||
character_positions.push(glyph.pos.x - row.pos.x);
|
||||
character_widths.push(glyph.advance_width);
|
||||
}
|
||||
|
||||
if row.ends_with_newline {
|
||||
value.push('\n');
|
||||
character_lengths.push(1);
|
||||
character_positions.push(row.rect.max.x - row.rect.min.x);
|
||||
character_positions.push(row.size.x);
|
||||
character_widths.push(0.0);
|
||||
}
|
||||
word_lengths.push((character_lengths.len() - last_word_start) as _);
|
||||
|
||||
@@ -284,7 +284,7 @@ fn ccursor_from_accesskit_text_position(
|
||||
position: &accesskit::TextPosition,
|
||||
) -> Option<CCursor> {
|
||||
let mut total_length = 0usize;
|
||||
for (i, (row, _)) in galley.rows.iter().enumerate() {
|
||||
for (i, row) in galley.rows.iter().enumerate() {
|
||||
let row_id = id.with(i);
|
||||
if row_id.accesskit_id() == position.node {
|
||||
return Some(CCursor {
|
||||
|
||||
@@ -179,10 +179,10 @@ impl LabelSelectionState {
|
||||
if let epaint::Shape::Text(text_shape) = &mut shape.shape {
|
||||
let galley = Arc::make_mut(&mut text_shape.galley);
|
||||
for row_selection in row_selections {
|
||||
if let Some((row, _)) =
|
||||
if let Some(placed_row) =
|
||||
galley.rows.get_mut(row_selection.row)
|
||||
{
|
||||
let row = Arc::make_mut(row);
|
||||
let row = Arc::make_mut(&mut placed_row.row);
|
||||
for vertex_index in row_selection.vertex_indices {
|
||||
if let Some(vertex) = row
|
||||
.visuals
|
||||
@@ -662,8 +662,8 @@ fn selected_text(galley: &Galley, cursor_range: &CursorRange) -> String {
|
||||
}
|
||||
|
||||
fn estimate_row_height(galley: &Galley) -> f32 {
|
||||
if let Some((row, _)) = galley.rows.first() {
|
||||
row.rect.height()
|
||||
if let Some(placed_row) = galley.rows.first() {
|
||||
placed_row.height()
|
||||
} else {
|
||||
galley.size().y
|
||||
}
|
||||
|
||||
@@ -31,26 +31,27 @@ pub fn paint_text_selection(
|
||||
let max = max.rcursor;
|
||||
|
||||
for ri in min.row..=max.row {
|
||||
let (row, _) = &mut galley.rows[ri];
|
||||
let row = Arc::make_mut(row);
|
||||
let placed_row = &mut galley.rows[ri];
|
||||
|
||||
let left = if ri == min.row {
|
||||
row.x_offset(min.column)
|
||||
placed_row.x_offset(min.column)
|
||||
} else {
|
||||
row.rect.left()
|
||||
0.0
|
||||
};
|
||||
let right = if ri == max.row {
|
||||
row.x_offset(max.column)
|
||||
placed_row.x_offset(max.column)
|
||||
} else {
|
||||
let newline_size = if row.ends_with_newline {
|
||||
row.height() / 2.0 // visualize that we select the newline
|
||||
let newline_size = if placed_row.ends_with_newline {
|
||||
placed_row.height() / 2.0 // visualize that we select the newline
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
row.rect.right() + newline_size
|
||||
placed_row.size.x + newline_size
|
||||
};
|
||||
|
||||
let rect = Rect::from_min_max(pos2(left, row.min_y()), pos2(right, row.max_y()));
|
||||
let rect = Rect::from_min_max(pos2(left, 0.0), pos2(right, placed_row.size.y));
|
||||
|
||||
let row = Arc::make_mut(&mut placed_row.row);
|
||||
let mesh = &mut row.visuals.mesh;
|
||||
|
||||
// Time to insert the selection rectangle into the row mesh.
|
||||
|
||||
@@ -640,8 +640,8 @@ impl WidgetText {
|
||||
Self::RichText(text) => text.font_height(fonts, style),
|
||||
Self::LayoutJob(job) => job.font_height(fonts),
|
||||
Self::Galley(galley) => {
|
||||
if let Some((row, _)) = galley.rows.first() {
|
||||
row.height()
|
||||
if let Some(placed_row) = galley.rows.first() {
|
||||
placed_row.height()
|
||||
} else {
|
||||
galley.size().y
|
||||
}
|
||||
|
||||
@@ -194,13 +194,10 @@ 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]
|
||||
.0
|
||||
.rect
|
||||
.translate(galley.rows[0].1.to_vec2() + pos.to_vec2());
|
||||
let rect = galley.rows[0].rect().translate(pos.to_vec2());
|
||||
let mut response = ui.allocate_rect(rect, sense);
|
||||
for (row, offset) in galley.rows.iter().skip(1) {
|
||||
let rect = row.rect.translate(offset.to_vec2() + pos.to_vec2());
|
||||
for placed_row in galley.rows.iter().skip(1) {
|
||||
let rect = placed_row.rect().translate(pos.to_vec2());
|
||||
response |= ui.allocate_rect(rect, sense);
|
||||
}
|
||||
(pos, galley, response)
|
||||
|
||||
Reference in New Issue
Block a user