Produce FontMatches inside of Buffer

This commit is contained in:
Jeremy Soller 2022-10-25 16:13:07 -06:00
parent 085231c153
commit 59a4f8a4c1
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
5 changed files with 20 additions and 24 deletions

View file

@ -23,7 +23,6 @@ use cosmic::{
},
};
use cosmic_text::{
FontMatches,
FontSystem,
SwashCache,
TextBuffer,
@ -40,7 +39,7 @@ use self::text_box::text_box;
mod text_box;
lazy_static::lazy_static! {
static ref FONT_SYSTEM: FontSystem = FontSystem::new();
static ref FONT_SYSTEM: FontSystem<'static> = FontSystem::new();
}
static FONT_SIZES: &'static [TextMetrics] = &[
@ -102,11 +101,10 @@ impl Application for Window {
fn new(_flags: ()) -> (Self, Command<Self::Message>) {
let attrs = cosmic_text::Attrs::new().monospaced(cfg!(feature = "mono"));
let font_matches = FONT_SYSTEM.matches_attrs(attrs).unwrap();
let font_size_i = 1; // Body
let buffer = TextBuffer::new(
font_matches,
&FONT_SYSTEM,
attrs,
FONT_SIZES[font_size_i],
);

View file

@ -30,9 +30,6 @@ fn main() {
)
.unwrap();
let attrs = cosmic_text::Attrs::new().monospaced(cfg!(feature = "mono"));
let font_matches = font_system.matches_attrs(attrs).unwrap();
let bg_color = Color::rgb(0x34, 0x34, 0x34);
let font_color = Color::rgb(0xFF, 0xFF, 0xFF);
let font_sizes = [
@ -59,8 +56,10 @@ fn main() {
let mut swash_cache = SwashCache::new();
let line_x = 8 * display_scale;
let attrs = cosmic_text::Attrs::new().monospaced(cfg!(feature = "mono"));
let mut buffer = TextBuffer::new(
font_matches,
&font_system,
attrs,
font_sizes[font_size_i]
);
buffer.set_size(

View file

@ -45,9 +45,6 @@ fn main() {
)
.unwrap();
let attrs = cosmic_text::Attrs::new().monospaced(cfg!(feature = "mono"));
let font_matches = font_system.matches_attrs(attrs).unwrap();
let font_sizes = [
TextMetrics::new(10, 14).scale(display_scale), // Caption
TextMetrics::new(14, 20).scale(display_scale), // Body
@ -58,8 +55,10 @@ fn main() {
];
let font_size_default = 1; // Body
let attrs = cosmic_text::Attrs::new().monospaced(cfg!(feature = "mono"));
let mut buffer = TextBuffer::new(
font_matches,
&font_system,
attrs,
font_sizes[font_size_default]
);
buffer.set_size(