Use pre-seeded font caches to avoid mut

This commit is contained in:
Kenny Levinsen
2019-08-06 16:39:17 +02:00
parent c5d7faceba
commit 37fcb7390b
8 changed files with 126 additions and 78 deletions
+5 -4
View File
@@ -3,7 +3,6 @@ use crate::color::Color;
use crate::draw::{draw_bar, draw_box, Font, ROBOTO_REGULAR};
use crate::module::{Input, ModuleImpl};
use std::cell::RefCell;
use std::fs::OpenOptions;
use std::io::{Error, ErrorKind};
use std::io::{Read, Write};
@@ -15,7 +14,7 @@ pub struct Backlight {
device_path: PathBuf,
cur_brightness: u64,
max_brightness: u64,
font: RefCell<Font>,
font: Font,
dirty: bool,
}
@@ -87,10 +86,12 @@ impl Backlight {
device_path: first_device.path(),
cur_brightness: 0,
max_brightness: 0,
font: RefCell::new(Font::new(&ROBOTO_REGULAR, 24.0)),
font: Font::new(&ROBOTO_REGULAR, 24.0),
dirty: true,
};
dev.font.add_str_to_cache("backlight");
dev.update()?;
Ok(dev)
@@ -106,7 +107,7 @@ impl ModuleImpl for Backlight {
) -> Result<Vec<(i32, i32, i32, i32)>, Error> {
buf.memset(bg);
let c = Color::new(1.0, 1.0, 1.0, 1.0);
self.font.borrow_mut().draw_text(
self.font.draw_text(
&mut buf.subdimensions((0, 0, 128, 24))?,
bg,
&c,