Configurable font support

Use fontconfig to load fonts. Fonts can be added to the `fonts` map in
the config, and referenced from individual widgets' configurations for
customizability.

Fonts default to values "mono" and "sans" if nothing is set.
This commit is contained in:
Hilmar Gústafsson
2020-06-14 17:01:42 +02:00
committed by Kenny Levinsen
parent 1a62696662
commit 48985c470a
26 changed files with 396 additions and 14128 deletions
+11 -8
View File
@@ -1,18 +1,21 @@
use crate::color::Color;
use crate::draw::{Font, ROBOTO_REGULAR};
use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, WaitContext, Widget};
use crate::draw::Font;
use crate::{
fonts::FontRef,
widget::{DrawContext, DrawReport, KeyState, ModifiersState, WaitContext, Widget},
};
use chrono::{Duration, NaiveDateTime, Timelike};
pub struct Clock {
pub struct Clock<'a> {
cur_time: NaiveDateTime,
clock_cache: Font,
clock_cache: Font<'a>,
size: f32,
}
impl Clock {
pub fn new(time: NaiveDateTime, size: f32) -> Box<Clock> {
let mut clock_cache = Font::new(&ROBOTO_REGULAR, size);
impl<'a> Clock<'a> {
pub fn new(time: NaiveDateTime, font: FontRef, size: f32) -> Box<Clock> {
let mut clock_cache = Font::new(font, size);
clock_cache.add_str_to_cache("0123456789:");
Box::new(Clock {
@@ -23,7 +26,7 @@ impl Clock {
}
}
impl Widget for Clock {
impl<'a> Widget for Clock<'a> {
fn wait(&mut self, ctx: &mut WaitContext) {
let target = (self.cur_time + Duration::seconds(60))
.with_second(0)