Configurable background

This commit is contained in:
Kenny Levinsen
2019-09-07 00:24:58 +02:00
parent d419946959
commit d10883169f
5 changed files with 22 additions and 7 deletions
+7 -1
View File
@@ -39,5 +39,11 @@
}
},
"outputMode": "active",
"scale": 1
"scale": 1,
"background": {
"red": 0,
"green": 0,
"blue": 0,
"opacity": 0.9
}
}
+5 -4
View File
@@ -203,6 +203,7 @@ pub struct App {
event_queue: EventQueue,
cmd_queue: Arc<Mutex<VecDeque<Cmd>>>,
widget: Option<Box<dyn Widget + Send>>,
bg: Color,
inner: Arc<Mutex<AppInner>>,
last_damage: Option<Vec<(i32, i32, i32, i32)>>,
last_dim: (u32, u32),
@@ -256,14 +257,13 @@ impl App {
force = true;
}
let bg = Color::new(0.0, 0.0, 0.0, 0.9);
if force {
buf.memset(&bg);
buf.memset(&self.bg);
}
let report = widget.draw(
&mut DrawContext {
buf: &mut buf,
bg: &bg,
bg: &self.bg,
time: &time,
force,
},
@@ -337,7 +337,7 @@ impl App {
self.redraw(true)
}
pub fn new(tx: Sender<Cmd>, output_mode: OutputMode, scale: u32) -> App {
pub fn new(tx: Sender<Cmd>, output_mode: OutputMode, bg: Color, scale: u32) -> App {
let inner = Arc::new(Mutex::new(AppInner::new(tx.clone(), output_mode, scale)));
//
@@ -543,6 +543,7 @@ impl App {
cmd_queue: cmd_queue,
pools: pools,
widget: None,
bg: bg,
inner: inner,
last_damage: None,
last_dim: (0, 0),
+3 -1
View File
@@ -1,4 +1,6 @@
#[derive(Debug, Clone, Copy)]
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct Color {
red: f32,
green: f32,
+3
View File
@@ -1,6 +1,7 @@
use crate::cmd::Cmd;
use crate::widget;
use crate::widgets;
use crate::color::Color;
use serde::{Deserialize, Serialize};
use std::default::Default;
use std::sync::mpsc::Sender;
@@ -149,6 +150,7 @@ pub struct Config {
pub widget: Widget,
pub output_mode: OutputMode,
pub scale: u32,
pub background: Color,
}
impl Default for Config {
@@ -204,6 +206,7 @@ impl Default for Config {
},
output_mode: Default::default(),
scale: 1,
background: Color::new(0.0, 0.0, 0.0, 0.9),
}
}
}
+4 -1
View File
@@ -107,6 +107,9 @@ fn main() {
config::OutputMode::Active => OutputMode::Active,
};
let background = config.background;
let (tx_draw, rx_draw) = channel();
let tx_draw_mod = tx_draw.clone();
let (mod_tx, mod_rx) = channel();
@@ -118,7 +121,7 @@ fn main() {
}
});
let mut app = App::new(tx_draw, output_mode, scale);
let mut app = App::new(tx_draw, output_mode, background, scale);
let widget = mod_rx.recv().unwrap();
app.set_widget(widget).unwrap();