Cache font matches, use usize for line index, use font system for swash

This commit is contained in:
Jeremy Soller 2022-10-26 12:23:03 -06:00
parent 94576fb682
commit 119a570ee9
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
8 changed files with 105 additions and 120 deletions

View file

@ -64,7 +64,7 @@ pub struct Window {
theme: Theme,
path_opt: Option<PathBuf>,
buffer: Mutex<TextBuffer<'static>>,
cache: Mutex<SwashCache>,
cache: Mutex<SwashCache<'static>>,
bold: bool,
italic: bool,
monospaced: bool,
@ -117,11 +117,13 @@ impl Application for Window {
FONT_SIZES[font_size_i],
);
let cache = SwashCache::new(&FONT_SYSTEM);
let mut window = Window {
theme: Theme::Dark,
path_opt: None,
buffer: Mutex::new(buffer),
cache: Mutex::new(SwashCache::new()),
cache: Mutex::new(cache),
bold: false,
italic: false,
monospaced: true,
@ -178,7 +180,7 @@ impl Application for Window {
} else {
cosmic_text::Weight::NORMAL
});
buffer.set_attrs(&FONT_SYSTEM, attrs);
buffer.set_attrs(attrs);
},
Message::Italic(italic) => {
self.italic = italic;
@ -189,7 +191,7 @@ impl Application for Window {
} else {
cosmic_text::Style::Normal
});
buffer.set_attrs(&FONT_SYSTEM, attrs);
buffer.set_attrs(attrs);
},
Message::Monospaced(monospaced) => {
self.monospaced = monospaced;
@ -202,7 +204,7 @@ impl Application for Window {
cosmic_text::Family::SansSerif
})
.monospaced(monospaced);
buffer.set_attrs(&FONT_SYSTEM, attrs);
buffer.set_attrs(attrs);
},
Message::MetricsChanged(metrics) => {
let mut buffer = self.buffer.lock().unwrap();

View file

@ -63,16 +63,16 @@ impl StyleSheet for Theme {
pub struct TextBox<'a> {
buffer: &'a Mutex<TextBuffer<'static>>,
cache: &'a Mutex<SwashCache>,
cache: &'a Mutex<SwashCache<'static>>,
}
impl<'a> TextBox<'a> {
pub fn new(buffer: &'a Mutex<TextBuffer<'static>>, cache: &'a Mutex<SwashCache>) -> Self {
pub fn new(buffer: &'a Mutex<TextBuffer<'static>>, cache: &'a Mutex<SwashCache<'static>>) -> Self {
Self { buffer, cache }
}
}
pub fn text_box<'a>(buffer: &'a Mutex<TextBuffer<'static>>, cache: &'a Mutex<SwashCache>) -> TextBox<'a> {
pub fn text_box<'a>(buffer: &'a Mutex<TextBuffer<'static>>, cache: &'a Mutex<SwashCache<'static>>) -> TextBox<'a> {
TextBox::new(buffer, cache)
}