1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Nicer looking text selection, especially in light mode (#5017)

* Closes https://github.com/emilk/egui/issues/4727

This changes the text selection painting from being painted on top of
the text, to being painted behind the text, but in front of any text
background. The result is much nicer looking text selection, especially
in light mode:

### The new selections
<img width="198" alt="Screenshot 2024-08-27 at 18 58 35"
src="https://github.com/user-attachments/assets/bd342946-299c-44ab-bc2d-2aa8ddbca8eb">
<img width="187" alt="Screenshot 2024-08-27 at 18 59 26"
src="https://github.com/user-attachments/assets/352bed32-5150-49b9-a9f9-c7679a0d30b2">


### What selections used to look like
<img width="143" alt="Screenshot 2024-08-27 at 19 03 08"
src="https://github.com/user-attachments/assets/f3cbd798-cfed-4ad4-aa3a-d7480efcfa3c">
<img width="143" alt="Screenshot 2024-08-27 at 19 03 23"
src="https://github.com/user-attachments/assets/9925d18d-da82-4a44-8a98-ea6857ecc14f">


### New selection of some text with a background
<img width="134" alt="Screenshot 2024-08-27 at 18 59 12"
src="https://github.com/user-attachments/assets/1d291d7f-efbd-4efd-b6d2-cd63c9fc4fa4">
This commit is contained in:
Emil Ernerfeldt
2024-08-27 19:09:44 +02:00
committed by GitHub
parent 58bc67e02f
commit a59f9ed279
8 changed files with 182 additions and 92 deletions

View File

@@ -703,6 +703,7 @@ fn tessellate_row(
add_row_backgrounds(job, row, &mut mesh);
}
let glyph_index_start = mesh.indices.len();
let glyph_vertex_start = mesh.vertices.len();
tessellate_glyphs(point_scale, job, row, &mut mesh);
let glyph_vertex_end = mesh.vertices.len();
@@ -730,6 +731,7 @@ fn tessellate_row(
RowVisuals {
mesh,
mesh_bounds,
glyph_index_start,
glyph_vertex_range: glyph_vertex_start..glyph_vertex_end,
}
}

View File

@@ -554,6 +554,12 @@ pub struct RowVisuals {
/// Does NOT include leading or trailing whitespace glyphs!!
pub mesh_bounds: Rect,
/// The number of triangle indices added before the first glyph triangle.
///
/// This can be used to insert more triangles after the background but before the glyphs,
/// i.e. for text selection visualization.
pub glyph_index_start: usize,
/// The range of vertices in the mesh that contain glyphs (as opposed to background, underlines, strikethorugh, etc).
///
/// The glyph vertices comes after backgrounds (if any), but before any underlines and strikethrough.
@@ -565,6 +571,7 @@ impl Default for RowVisuals {
Self {
mesh: Default::default(),
mesh_bounds: Rect::NOTHING,
glyph_index_start: 0,
glyph_vertex_range: 0..0,
}
}