Add text attributes
This commit is contained in:
parent
bc04887b35
commit
84f4381cdf
6 changed files with 83 additions and 88 deletions
|
|
@ -101,35 +101,8 @@ impl Application for Window {
|
||||||
type Theme = Theme;
|
type Theme = Theme;
|
||||||
|
|
||||||
fn new(_flags: ()) -> (Self, Command<Self::Message>) {
|
fn new(_flags: ()) -> (Self, Command<Self::Message>) {
|
||||||
let font_matches: FontMatches<'static> = FONT_SYSTEM.matches(|info| -> bool {
|
let attrs = cosmic_text::Attrs::new().monospaced(cfg!(feature = "mono"));
|
||||||
#[cfg(feature = "mono")]
|
let font_matches = FONT_SYSTEM.matches_attrs(attrs).unwrap();
|
||||||
let monospaced = true;
|
|
||||||
|
|
||||||
#[cfg(not(feature = "mono"))]
|
|
||||||
let monospaced = false;
|
|
||||||
|
|
||||||
let matched = {
|
|
||||||
info.style == fontdb::Style::Normal &&
|
|
||||||
info.weight == fontdb::Weight::NORMAL &&
|
|
||||||
info.stretch == fontdb::Stretch::Normal &&
|
|
||||||
(info.monospaced == monospaced || info.post_script_name.contains("Emoji"))
|
|
||||||
};
|
|
||||||
|
|
||||||
if matched {
|
|
||||||
log::debug!(
|
|
||||||
"{:?}: family '{}' postscript name '{}' style {:?} weight {:?} stretch {:?} monospaced {:?}",
|
|
||||||
info.id,
|
|
||||||
info.family,
|
|
||||||
info.post_script_name,
|
|
||||||
info.style,
|
|
||||||
info.weight,
|
|
||||||
info.stretch,
|
|
||||||
info.monospaced
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
matched
|
|
||||||
}).unwrap();
|
|
||||||
|
|
||||||
let font_size_i = 1; // Body
|
let font_size_i = 1; // Body
|
||||||
let buffer = TextBuffer::new(
|
let buffer = TextBuffer::new(
|
||||||
|
|
|
||||||
|
|
@ -30,35 +30,8 @@ fn main() {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let font_matches = font_system.matches(|info| -> bool {
|
let attrs = cosmic_text::Attrs::new().monospaced(cfg!(feature = "mono"));
|
||||||
#[cfg(feature = "mono")]
|
let font_matches = font_system.matches_attrs(attrs).unwrap();
|
||||||
let monospaced = true;
|
|
||||||
|
|
||||||
#[cfg(not(feature = "mono"))]
|
|
||||||
let monospaced = false;
|
|
||||||
|
|
||||||
let matched = {
|
|
||||||
info.style == fontdb::Style::Normal &&
|
|
||||||
info.weight == fontdb::Weight::NORMAL &&
|
|
||||||
info.stretch == fontdb::Stretch::Normal &&
|
|
||||||
(info.monospaced == monospaced || info.post_script_name.contains("Emoji"))
|
|
||||||
};
|
|
||||||
|
|
||||||
if matched {
|
|
||||||
log::debug!(
|
|
||||||
"{:?}: family '{}' postscript name '{}' style {:?} weight {:?} stretch {:?} monospaced {:?}",
|
|
||||||
info.id,
|
|
||||||
info.family,
|
|
||||||
info.post_script_name,
|
|
||||||
info.style,
|
|
||||||
info.weight,
|
|
||||||
info.stretch,
|
|
||||||
info.monospaced
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
matched
|
|
||||||
}).unwrap();
|
|
||||||
|
|
||||||
let bg_color = Color::rgb(0x34, 0x34, 0x34);
|
let bg_color = Color::rgb(0x34, 0x34, 0x34);
|
||||||
let font_color = Color::rgb(0xFF, 0xFF, 0xFF);
|
let font_color = Color::rgb(0xFF, 0xFF, 0xFF);
|
||||||
|
|
|
||||||
|
|
@ -45,35 +45,8 @@ fn main() {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let font_matches = font_system.matches(|info| -> bool {
|
let attrs = cosmic_text::Attrs::new().monospaced(cfg!(feature = "mono"));
|
||||||
#[cfg(feature = "mono")]
|
let font_matches = font_system.matches_attrs(attrs).unwrap();
|
||||||
let monospaced = true;
|
|
||||||
|
|
||||||
#[cfg(not(feature = "mono"))]
|
|
||||||
let monospaced = false;
|
|
||||||
|
|
||||||
let matched = {
|
|
||||||
info.style == fontdb::Style::Normal &&
|
|
||||||
info.weight == fontdb::Weight::NORMAL &&
|
|
||||||
info.stretch == fontdb::Stretch::Normal &&
|
|
||||||
(info.monospaced == monospaced || info.post_script_name.contains("Emoji"))
|
|
||||||
};
|
|
||||||
|
|
||||||
if matched {
|
|
||||||
log::debug!(
|
|
||||||
"{:?}: family '{}' postscript name '{}' style {:?} weight {:?} stretch {:?} monospaced {:?}",
|
|
||||||
info.id,
|
|
||||||
info.family,
|
|
||||||
info.post_script_name,
|
|
||||||
info.style,
|
|
||||||
info.weight,
|
|
||||||
info.stretch,
|
|
||||||
info.monospaced
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
matched
|
|
||||||
}).unwrap();
|
|
||||||
|
|
||||||
let font_sizes = [
|
let font_sizes = [
|
||||||
TextMetrics::new(10, 14).scale(display_scale), // Caption
|
TextMetrics::new(10, 14).scale(display_scale), // Caption
|
||||||
|
|
|
||||||
46
src/attrs.rs
Normal file
46
src/attrs.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
pub use fontdb::{Family, Stretch, Style, Weight};
|
||||||
|
|
||||||
|
pub struct Attrs<'a> {
|
||||||
|
pub family: Family<'a>,
|
||||||
|
pub monospaced: bool,
|
||||||
|
pub stretch: Stretch,
|
||||||
|
pub style: Style,
|
||||||
|
pub weight: Weight,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Attrs<'a> {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
family: Family::SansSerif,
|
||||||
|
monospaced: false,
|
||||||
|
stretch: Stretch::Normal,
|
||||||
|
style: Style::Normal,
|
||||||
|
weight: Weight::NORMAL,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn family(mut self, family: Family<'a>) -> Self {
|
||||||
|
self.family = family;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn monospaced(mut self, monospaced: bool) -> Self {
|
||||||
|
self.monospaced = monospaced;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stretch(mut self, stretch: Stretch) -> Self {
|
||||||
|
self.stretch = stretch;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn style(mut self, style: Style) -> Self {
|
||||||
|
self.style = style;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn weight(mut self, weight: Weight) -> Self {
|
||||||
|
self.weight = weight;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use super::{Font, FontMatches};
|
use crate::{Attrs, Font, FontMatches};
|
||||||
|
|
||||||
/// Access system fonts
|
/// Access system fonts
|
||||||
pub struct FontSystem {
|
pub struct FontSystem {
|
||||||
|
|
@ -81,6 +81,33 @@ impl FontSystem {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn matches_attrs(&self, attrs: Attrs) -> Option<FontMatches<'_>> {
|
||||||
|
self.matches(|info| {
|
||||||
|
let matched = {
|
||||||
|
info.style == attrs.style &&
|
||||||
|
info.weight == attrs.weight &&
|
||||||
|
info.stretch == attrs.stretch &&
|
||||||
|
//TODO: smarter way of including emoji
|
||||||
|
(info.monospaced == attrs.monospaced || info.post_script_name.contains("Emoji"))
|
||||||
|
};
|
||||||
|
|
||||||
|
if matched {
|
||||||
|
log::debug!(
|
||||||
|
"{:?}: family '{}' postscript name '{}' style {:?} weight {:?} stretch {:?} monospaced {:?}",
|
||||||
|
info.id,
|
||||||
|
info.family,
|
||||||
|
info.post_script_name,
|
||||||
|
info.style,
|
||||||
|
info.weight,
|
||||||
|
info.stretch,
|
||||||
|
info.monospaced
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
matched
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FontSystem {
|
impl Default for FontSystem {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
|
pub use self::attrs::*;
|
||||||
|
mod attrs;
|
||||||
|
|
||||||
pub use self::buffer::*;
|
pub use self::buffer::*;
|
||||||
mod buffer;
|
mod buffer;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue