Skip to content

Commit d55ba4a

Browse files
committed
Supporting changes for text editing 1
1 parent 6f9e732 commit d55ba4a

File tree

9 files changed

+51
-15
lines changed

9 files changed

+51
-15
lines changed

Cargo.lock

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,7 @@ name = "epaint"
15181518
version = "0.31.1"
15191519
dependencies = [
15201520
"ab_glyph",
1521+
"accesskit",
15211522
"ahash",
15221523
"backtrace",
15231524
"bytemuck",
@@ -1667,8 +1668,6 @@ dependencies = [
16671668
[[package]]
16681669
name = "fontique"
16691670
version = "0.3.0"
1670-
source = "registry+https://github.com/rust-lang/crates.io-index"
1671-
checksum = "6b5fcb214137f01bc842c4fd633236255c51f8a24c6d3923eb8361c6d0940737"
16721671
dependencies = [
16731672
"bytemuck",
16741673
"fontconfig-cache-parser",
@@ -3089,12 +3088,12 @@ dependencies = [
30893088
[[package]]
30903089
name = "parley"
30913090
version = "0.3.0"
3092-
source = "registry+https://github.com/rust-lang/crates.io-index"
3093-
checksum = "0d1c2b33b240c246f06cfceac48dc6c96040cb177d2aa5348899982b298b5577"
30943091
dependencies = [
3092+
"accesskit",
30953093
"fontique",
30963094
"hashbrown 0.15.2",
30973095
"peniko",
3096+
"serde",
30983097
"skrifa",
30993098
"swash",
31003099
]

crates/egui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ default = ["default_fonts"]
2828

2929
## Exposes detailed accessibility implementation required by platform
3030
## accessibility APIs. Also requires support in the egui integration.
31-
accesskit = ["dep:accesskit"]
31+
accesskit = ["dep:accesskit", "epaint/accesskit"]
3232

3333
## [`bytemuck`](https://docs.rs/bytemuck) enables you to cast [`epaint::Vertex`], [`emath::Vec2`] etc to `&[u8]`.
3434
bytemuck = ["epaint/bytemuck"]

crates/epaint/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ rustdoc-args = ["--generate-link-to-definition"]
2929

3030

3131
[features]
32+
accesskit = ["dep:accesskit", "parley/accesskit"]
33+
3234
default = ["default_fonts"]
3335

3436
## [`bytemuck`](https://docs.rs/bytemuck) enables you to cast [`Vertex`] to `&[u8]`.
@@ -61,7 +63,7 @@ mint = ["emath/mint"]
6163
rayon = ["dep:rayon"]
6264

6365
## Allow serialization using [`serde`](https://docs.rs/serde).
64-
serde = ["dep:serde", "ahash/serde", "emath/serde", "ecolor/serde"]
66+
serde = ["dep:serde", "ahash/serde", "emath/serde", "ecolor/serde", "parley/serde"]
6567

6668
## Change Vertex layout to be compatible with unity
6769
unity = []
@@ -77,15 +79,18 @@ ecolor.workspace = true
7779
ab_glyph = "0.2.11"
7880
#cosmic-text = { git = "https://github.com/valadaptive/cosmic-text/", rev = "564b634" }
7981
#cosmic-text = { path = "../../../cosmic-text" }
80-
parley = { version = "0.3", features = ["system"] }
81-
#parley = { path = "../../../parley/parley", features = ["system"] }
82+
#parley = { version = "0.3", features = ["system"] }
83+
parley = { path = "../../../parley/parley", features = ["system"] }
8284
swash = { version = "0.2" }
8385
ahash.workspace = true
8486
nohash-hasher.workspace = true
8587
parking_lot.workspace = true # Using parking_lot over std::sync::Mutex gives 50% speedups in some real-world scenarios.
8688
profiling = { workspace = true}
8789

8890
#! ### Optional dependencies
91+
92+
accesskit = { workspace = true, optional = true }
93+
8994
bytemuck = { workspace = true, optional = true, features = ["derive"] }
9095

9196
## Enable this when generating docs.

crates/epaint/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Default for TextureId {
120120
/// A [`Shape`] within a clip rectangle.
121121
///
122122
/// Everything is using logical points.
123-
#[derive(Clone, Debug, PartialEq)]
123+
#[derive(Clone, Debug)]
124124
pub struct ClippedShape {
125125
/// Clip / scissor rectangle.
126126
/// Only show the part of the [`Shape`] that falls within this.

crates/epaint/src/mutex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod mutex_impl {
99
/// This is a thin wrapper around [`parking_lot::Mutex`], except if
1010
/// the feature `deadlock_detection` is turned enabled, in which case
1111
/// extra checks are added to detect deadlocks.
12-
#[derive(Default)]
12+
#[derive(Default, Debug)]
1313
pub struct Mutex<T>(parking_lot::Mutex<T>);
1414

1515
/// The lock you get from [`Mutex`].
@@ -35,7 +35,7 @@ mod mutex_impl {
3535
/// This is a thin wrapper around [`parking_lot::Mutex`], except if
3636
/// the feature `deadlock_detection` is turned enabled, in which case
3737
/// extra checks are added to detect deadlocks.
38-
#[derive(Default)]
38+
#[derive(Default, Debug)]
3939
pub struct Mutex<T>(parking_lot::Mutex<T>);
4040

4141
/// The lock you get from [`Mutex`].

crates/epaint/src/shapes/shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use super::{
2323
/// [`Shape::Text`] depends on the current `pixels_per_point` (dpi scale)
2424
/// and so must be recreated every time `pixels_per_point` changes.
2525
#[must_use = "Add a Shape to a Painter"]
26-
#[derive(Clone, Debug, PartialEq)]
26+
#[derive(Clone, Debug)]
2727
pub enum Shape {
2828
/// Paint nothing. This can be useful as a placeholder.
2929
Noop,

crates/epaint/src/shapes/text_shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::*;
55
/// How to paint some text on screen.
66
///
77
/// This needs to be recreated if `pixels_per_point` (dpi scale) changes.
8-
#[derive(Clone, Debug, PartialEq)]
8+
#[derive(Clone, Debug)]
99
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1010
pub struct TextShape {
1111
/// Top left corner of the first character.

crates/epaint/src/text/parley_layout.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use parley::{
77
};
88

99
use crate::{
10+
mutex::Mutex,
1011
text::{Row, RowVisuals},
1112
Mesh,
1213
};
@@ -62,6 +63,9 @@ pub fn layout(fonts: &mut FontsImpl, job: LayoutJob) -> Galley {
6263
return Galley {
6364
job: Arc::new(job),
6465
rows: Default::default(),
66+
parley_layout: Mutex::new(parley::Layout::new()),
67+
#[cfg(feature = "accesskit")]
68+
layout_access: Mutex::new(None),
6569
rect: Rect::from_min_max(Pos2::ZERO, Pos2::ZERO),
6670
mesh_bounds: Rect::NOTHING,
6771
num_vertices: 0,
@@ -280,6 +284,9 @@ pub fn layout(fonts: &mut FontsImpl, job: LayoutJob) -> Galley {
280284
Galley {
281285
job: Arc::new(job),
282286
rows,
287+
parley_layout: Mutex::new(layout),
288+
#[cfg(feature = "accesskit")]
289+
layout_access: Mutex::new(None),
283290
elided: false,
284291
rect: acc_logical_bounds,
285292
mesh_bounds: acc_mesh_bounds,

crates/epaint/src/text/text_layout_types.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::{
88
cursor::{CCursor, LayoutCursor},
99
font::UvRect,
1010
};
11-
use crate::{Color32, FontId, Mesh, Stroke};
11+
use crate::{mutex::Mutex, Color32, FontId, Mesh, Stroke};
1212
use emath::{pos2, Align, NumExt, OrderedFloat, Pos2, Rect, Vec2};
1313

1414
/// Describes the task of laying out text.
@@ -495,7 +495,7 @@ impl TextWrapping {
495495
///
496496
/// The name comes from typography, where a "galley" is a metal tray
497497
/// containing a column of set type, usually the size of a page of text.
498-
#[derive(Clone, Debug, PartialEq)]
498+
#[derive(Clone)]
499499
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
500500
pub struct Galley {
501501
/// The job that this galley is the result of.
@@ -511,6 +511,15 @@ pub struct Galley {
511511
/// can be split up into multiple rows.
512512
pub rows: Vec<Row>,
513513

514+
// TODO: store position offset for hit testing
515+
// This needs to be wrapped in a Mutex because Shape stores it and must be Send+Sync
516+
#[cfg_attr(feature = "serde", serde(skip))]
517+
pub(super) parley_layout: Mutex<parley::Layout<Color32>>,
518+
519+
#[cfg(feature = "accesskit")]
520+
#[cfg_attr(feature = "serde", serde(skip))]
521+
pub(super) layout_access: Mutex<Option<parley::LayoutAccessibility>>,
522+
514523
/// Set to true the text was truncated due to [`TextWrapping::max_rows`].
515524
pub elided: bool,
516525

@@ -541,6 +550,22 @@ pub struct Galley {
541550
pub pixels_per_point: f32,
542551
}
543552

553+
// parley::Layout does not implement Debug
554+
impl std::fmt::Debug for Galley {
555+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
556+
f.debug_struct("Galley")
557+
.field("job", &self.job)
558+
.field("rows", &self.rows)
559+
.field("elided", &self.elided)
560+
.field("rect", &self.rect)
561+
.field("mesh_bounds", &self.mesh_bounds)
562+
.field("num_vertices", &self.num_vertices)
563+
.field("num_indices", &self.num_indices)
564+
.field("pixels_per_point", &self.pixels_per_point)
565+
.finish()
566+
}
567+
}
568+
544569
#[derive(Clone, Debug, PartialEq)]
545570
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
546571
pub struct Row {

0 commit comments

Comments
 (0)