mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 22:30:03 -04:00
Make Galleys share Rows and store their offsets
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) in galley.rows.iter().enumerate() {
|
||||
for (row_index, (row, offset)) 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(galley_pos.to_vec2());
|
||||
let rect = row.rect.translate(offset.to_vec2() + galley_pos.to_vec2());
|
||||
builder.set_bounds(accesskit::Rect {
|
||||
x0: rect.min.x.into(),
|
||||
y0: rect.min.y.into(),
|
||||
|
||||
@@ -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,7 +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) = galley.rows.get_mut(row_selection.row) {
|
||||
if let Some((row, _)) =
|
||||
galley.rows.get_mut(row_selection.row)
|
||||
{
|
||||
let row = Arc::make_mut(row);
|
||||
for vertex_index in row_selection.vertex_indices {
|
||||
if let Some(vertex) = row
|
||||
.visuals
|
||||
@@ -659,7 +662,7 @@ fn selected_text(galley: &Galley, cursor_range: &CursorRange) -> String {
|
||||
}
|
||||
|
||||
fn estimate_row_height(galley: &Galley) -> f32 {
|
||||
if let Some(row) = galley.rows.first() {
|
||||
if let Some((row, _)) = galley.rows.first() {
|
||||
row.rect.height()
|
||||
} else {
|
||||
galley.size().y
|
||||
|
||||
@@ -31,7 +31,9 @@ pub fn paint_text_selection(
|
||||
let max = max.rcursor;
|
||||
|
||||
for ri in min.row..=max.row {
|
||||
let row = &mut galley.rows[ri];
|
||||
let (row, _) = &mut galley.rows[ri];
|
||||
let row = Arc::make_mut(row);
|
||||
|
||||
let left = if ri == min.row {
|
||||
row.x_offset(min.column)
|
||||
} else {
|
||||
|
||||
@@ -640,7 +640,7 @@ 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() {
|
||||
if let Some((row, _)) = galley.rows.first() {
|
||||
row.height()
|
||||
} else {
|
||||
galley.size().y
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
epaint, pos2, text_selection, vec2, Align, Direction, FontSelection, Galley, Pos2, Response,
|
||||
Sense, Stroke, TextWrapMode, Ui, Widget, WidgetInfo, WidgetText, WidgetType,
|
||||
epaint, pos2, text_selection, Align, Direction, FontSelection, Galley, Pos2, Response, Sense,
|
||||
Stroke, TextWrapMode, Ui, Widget, WidgetInfo, WidgetText, WidgetType,
|
||||
};
|
||||
|
||||
use self::text_selection::LabelSelectionState;
|
||||
@@ -194,10 +194,13 @@ 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(vec2(pos.x, pos.y));
|
||||
let rect = galley.rows[0]
|
||||
.0
|
||||
.rect
|
||||
.translate(galley.rows[0].1.to_vec2() + pos.to_vec2());
|
||||
let mut response = ui.allocate_rect(rect, sense);
|
||||
for row in galley.rows.iter().skip(1) {
|
||||
let rect = row.rect.translate(vec2(pos.x, pos.y));
|
||||
for (row, offset) in galley.rows.iter().skip(1) {
|
||||
let rect = row.rect.translate(offset.to_vec2() + pos.to_vec2());
|
||||
response |= ui.allocate_rect(rect, sense);
|
||||
}
|
||||
(pos, galley, response)
|
||||
|
||||
Reference in New Issue
Block a user