Use one swash cache for all text boxes
This commit is contained in:
parent
91e3d3e05a
commit
efe9302139
2 changed files with 5 additions and 6 deletions
|
|
@ -12,7 +12,7 @@ use cosmic::{
|
||||||
widget::{self, button, icon, nav_bar, segmented_button, view_switcher},
|
widget::{self, button, icon, nav_bar, segmented_button, view_switcher},
|
||||||
ApplicationExt, Element,
|
ApplicationExt, Element,
|
||||||
};
|
};
|
||||||
use cosmic_text::{FontSystem, SyntaxSystem, ViMode};
|
use cosmic_text::{FontSystem, SwashCache, SyntaxSystem, ViMode};
|
||||||
use std::{
|
use std::{
|
||||||
env, fs,
|
env, fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
|
@ -39,6 +39,7 @@ mod text_box;
|
||||||
//TODO: re-use iced FONT_SYSTEM
|
//TODO: re-use iced FONT_SYSTEM
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref FONT_SYSTEM: Mutex<FontSystem> = Mutex::new(FontSystem::new());
|
static ref FONT_SYSTEM: Mutex<FontSystem> = Mutex::new(FontSystem::new());
|
||||||
|
static ref SWASH_CACHE: Mutex<SwashCache> = Mutex::new(SwashCache::new());
|
||||||
static ref SYNTAX_SYSTEM: SyntaxSystem = SyntaxSystem::new();
|
static ref SYNTAX_SYSTEM: SyntaxSystem = SyntaxSystem::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ use cosmic::{
|
||||||
},
|
},
|
||||||
theme::{Theme, ThemeType},
|
theme::{Theme, ThemeType},
|
||||||
};
|
};
|
||||||
use cosmic_text::{Action, Edit, SwashCache};
|
use cosmic_text::{Action, Edit};
|
||||||
use std::{cmp, sync::Mutex, time::Instant};
|
use std::{cmp, sync::Mutex, time::Instant};
|
||||||
|
|
||||||
use crate::FONT_SYSTEM;
|
use crate::{FONT_SYSTEM, SWASH_CACHE};
|
||||||
|
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
background_color: Option<Color>,
|
background_color: Option<Color>,
|
||||||
|
|
@ -281,7 +281,7 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
editor.draw(
|
editor.draw(
|
||||||
&mut state.cache.lock().unwrap(),
|
&mut SWASH_CACHE.lock().unwrap(),
|
||||||
text_color,
|
text_color,
|
||||||
|x, y, w, h, color| {
|
|x, y, w, h, color| {
|
||||||
draw_rect(buffer, image_w, image_h, x, y, w as i32, h as i32, color.0);
|
draw_rect(buffer, image_w, image_h, x, y, w as i32, h as i32, color.0);
|
||||||
|
|
@ -446,7 +446,6 @@ where
|
||||||
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
is_dragging: bool,
|
is_dragging: bool,
|
||||||
cache: Mutex<SwashCache>,
|
|
||||||
handle: Mutex<image::Handle>,
|
handle: Mutex<image::Handle>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -455,7 +454,6 @@ impl State {
|
||||||
pub fn new() -> State {
|
pub fn new() -> State {
|
||||||
State {
|
State {
|
||||||
is_dragging: false,
|
is_dragging: false,
|
||||||
cache: Mutex::new(SwashCache::new()),
|
|
||||||
//TODO: make option!
|
//TODO: make option!
|
||||||
handle: Mutex::new(image::Handle::from_pixels(1, 1, vec![0, 0, 0, 0])),
|
handle: Mutex::new(image::Handle::from_pixels(1, 1, vec![0, 0, 0, 0])),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue