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::{Datelike, NaiveDateTime};
pub struct Date {
pub struct Date<'a> {
cur_time: NaiveDateTime,
date_cache: Font,
date_cache: Font<'a>,
size: f32,
}
impl Date {
pub fn new(time: NaiveDateTime, size: f32) -> Box<Date> {
let mut date_cache = Font::new(&ROBOTO_REGULAR, size);
impl<'a> Date<'a> {
pub fn new(time: NaiveDateTime, font: FontRef, size: f32) -> Box<Date> {
let mut date_cache = Font::new(font, size);
date_cache
.add_str_to_cache("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,/ ");
@@ -24,7 +27,7 @@ impl Date {
}
}
impl Widget for Date {
impl<'a> Widget for Date<'a> {
fn wait(&mut self, _: &mut WaitContext) {}
fn enter(&mut self) {}
fn leave(&mut self) {}