This commit is contained in:
Nathan Sobo
2023-10-16 20:15:41 +02:00
parent 1a3650ef2a
commit 847376cd8f
7 changed files with 66 additions and 28 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
use crate::{
black, point, px, Bounds, FontId, Hsla, Pixels, Point, RunStyle, ShapedBoundary, ShapedLine,
black, point, px, Bounds, FontId, Hsla, LineLayout, Pixels, Point, RunStyle, ShapedBoundary,
ShapedRun, UnderlineStyle, WindowContext,
};
use anyhow::Result;
@@ -8,7 +8,7 @@ use std::sync::Arc;
#[derive(Default, Debug, Clone)]
pub struct Line {
layout: Arc<ShapedLine>,
layout: Arc<LineLayout>,
style_runs: SmallVec<[StyleRun; 32]>,
}
@@ -20,7 +20,7 @@ struct StyleRun {
}
impl Line {
pub fn new(layout: Arc<ShapedLine>, runs: &[(usize, RunStyle)]) -> Self {
pub fn new(layout: Arc<LineLayout>, runs: &[(usize, RunStyle)]) -> Self {
let mut style_runs = SmallVec::new();
for (len, style) in runs {
style_runs.push(StyleRun {
+2 -1
View File
@@ -287,7 +287,7 @@ mod tests {
let text = "aa bbb cccc ddddd eeee";
let line = text_system
.layout_line(
.layout_text(
text,
px(16.),
&[
@@ -297,6 +297,7 @@ mod tests {
(1, bold.clone()),
(7, normal.clone()),
],
None,
)
.unwrap();
@@ -1,4 +1,4 @@
use crate::{FontId, Pixels, PlatformTextSystem, ShapedGlyph, ShapedLine, ShapedRun};
use crate::{FontId, LineLayout, Pixels, PlatformTextSystem, ShapedGlyph, ShapedRun};
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
use smallvec::SmallVec;
use std::{
@@ -9,8 +9,8 @@ use std::{
};
pub(crate) struct TextLayoutCache {
prev_frame: Mutex<HashMap<CacheKeyValue, Arc<ShapedLine>>>,
curr_frame: RwLock<HashMap<CacheKeyValue, Arc<ShapedLine>>>,
prev_frame: Mutex<HashMap<CacheKeyValue, Arc<LineLayout>>>,
curr_frame: RwLock<HashMap<CacheKeyValue, Arc<LineLayout>>>,
platform_text_system: Arc<dyn PlatformTextSystem>,
}
@@ -35,7 +35,7 @@ impl TextLayoutCache {
text: &'a str,
font_size: Pixels,
runs: &[(usize, FontId)],
) -> Arc<ShapedLine> {
) -> Arc<LineLayout> {
let key = &CacheKeyRef {
text,
font_size,