Remove lifetime from SwashCache

This commit is contained in:
Edgar Geier 2023-03-01 22:41:59 +01:00
parent 2b991129e3
commit 4e93853765
No known key found for this signature in database
GPG key ID: 7A65B51FD6B75EF5
10 changed files with 53 additions and 32 deletions

View file

@ -14,6 +14,8 @@ use cosmic::{
use cosmic_text::{Attrs, AttrsList, BufferLine, Metrics, SwashCache};
use std::{cmp, sync::Mutex, time::Instant};
use crate::FONT_SYSTEM;
pub struct Appearance {
background_color: Option<Color>,
text_color: Color,
@ -183,11 +185,16 @@ where
None => text_color,
};
cache.with_pixels(cache_key, glyph_color, |pixel_x, pixel_y, color| {
let x = x_int + pixel_x;
let y = line_y as i32 + y_int + pixel_y;
draw_pixel(&mut pixels, layout_w as i32, layout_h as i32, x, y, color);
});
cache.with_pixels(
&FONT_SYSTEM,
cache_key,
glyph_color,
|pixel_x, pixel_y, color| {
let x = x_int + pixel_x;
let y = line_y as i32 + y_int + pixel_y;
draw_pixel(&mut pixels, layout_w as i32, layout_h as i32, x, y, color);
},
);
}
line_y += self.metrics.line_height;
}
@ -259,7 +266,7 @@ where
}
pub struct State {
cache: Mutex<SwashCache<'static>>,
cache: Mutex<SwashCache>,
}
impl State {
@ -268,7 +275,7 @@ impl State {
let instant = Instant::now();
let state = State {
cache: Mutex::new(SwashCache::new(&crate::FONT_SYSTEM)),
cache: Mutex::new(SwashCache::new()),
};
log::debug!("created state in {:?}", instant.elapsed());

View file

@ -348,7 +348,7 @@ where
pub struct State {
is_dragging: bool,
cache: Mutex<SwashCache<'static>>,
cache: Mutex<SwashCache>,
}
impl State {
@ -356,7 +356,7 @@ impl State {
pub fn new() -> State {
State {
is_dragging: false,
cache: Mutex::new(SwashCache::new(&crate::FONT_SYSTEM)),
cache: Mutex::new(SwashCache::new()),
}
}
}

View file

@ -79,7 +79,7 @@ fn main() {
}
}
let mut swash_cache = SwashCache::new(&font_system);
let mut swash_cache = SwashCache::new();
let mut ctrl_pressed = false;
let mut mouse_x = -1;

View file

@ -59,7 +59,7 @@ fn main() {
let mut editor = Editor::new(buffer);
let mut swash_cache = SwashCache::new(&font_system);
let mut swash_cache = SwashCache::new();
let text = if let Some(arg) = env::args().nth(1) {
fs::read_to_string(&arg).expect("failed to open file")

View file

@ -144,7 +144,7 @@ fn main() {
.push(BufferLine::new(line_text, attrs_list));
}
let mut swash_cache = SwashCache::new(&font_system);
let mut swash_cache = SwashCache::new();
//TODO: make window not async?
let mut mouse_x = -1;

View file

@ -9,7 +9,7 @@ fn main() {
let font_system = FontSystem::new();
// A SwashCache stores rasterized glyphs, create one per application
let mut swash_cache = SwashCache::new(&font_system);
let mut swash_cache = SwashCache::new();
// Text metrics indicate the font size and line height of a buffer
let metrics = Metrics::new(14.0, 20.0);