Draw bar for backlight
This commit is contained in:
+11
-3
@@ -1,6 +1,6 @@
|
||||
use crate::buffer::Buffer;
|
||||
use crate::color::Color;
|
||||
use crate::draw::{draw_text, ROBOTO_REGULAR};
|
||||
use crate::draw::{draw_bar, draw_text, ROBOTO_REGULAR};
|
||||
use crate::module::{Input, ModuleImpl};
|
||||
|
||||
use chrono::{DateTime, Local};
|
||||
@@ -103,12 +103,20 @@ impl ModuleImpl for Backlight {
|
||||
buf.memset(bg);
|
||||
draw_text(
|
||||
ROBOTO_REGULAR,
|
||||
&mut buf.subdimensions((0, 0, 256, 24)),
|
||||
&mut buf.subdimensions((0, 0, 128, 24)),
|
||||
bg,
|
||||
&Color::new(1.0, 1.0, 1.0, 1.0),
|
||||
24.0,
|
||||
&format!("backlight: {:}%", self.brightness() as u8),
|
||||
"backlight",
|
||||
)?;
|
||||
draw_bar(
|
||||
&mut buf.subdimensions((128, 0, 384, 24)),
|
||||
bg,
|
||||
&Color::new(1.0, 1.0, 1.0, 1.0),
|
||||
384,
|
||||
24,
|
||||
self.brightness() / 100.0,
|
||||
);
|
||||
Ok(vec![buf.get_signed_bounds()])
|
||||
}
|
||||
|
||||
|
||||
+23
@@ -101,3 +101,26 @@ pub fn draw_text_fixed_width(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn draw_bar(
|
||||
buf: &mut Buffer,
|
||||
background_color: &Color,
|
||||
color: &Color,
|
||||
length: u32,
|
||||
height: u32,
|
||||
fill: f32,
|
||||
) -> Result<(), ::std::io::Error> {
|
||||
let mut buf = buf.subdimensions((0, 0, length, height));
|
||||
|
||||
let mut fill_pos = (((length as f32) * fill) as u32);
|
||||
if fill_pos > length {
|
||||
fill_pos = length;
|
||||
}
|
||||
for y in 0..height {
|
||||
for x in 0..fill_pos {
|
||||
buf.put((x, y), &background_color.blend(color, 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+1
-1
@@ -369,7 +369,7 @@ impl App {
|
||||
];
|
||||
|
||||
if let Ok(m) = Backlight::new() {
|
||||
modules.push(Module::new(Box::new(m), (720, 0, 256, 24)));
|
||||
modules.push(Module::new(Box::new(m), (720, 0, 512, 32)));
|
||||
}
|
||||
|
||||
App {
|
||||
|
||||
+13
-6
@@ -11,12 +11,19 @@ pub enum Input {
|
||||
}
|
||||
|
||||
impl Input {
|
||||
pub fn offset(&self, offset: (u32, u32)) -> Input{
|
||||
match self {
|
||||
Input::Click{pos, button} => Input::Click{pos: (pos.0 - offset.0, pos.1 - offset.1), button: *button},
|
||||
Input::Scroll{pos, x, y} => Input::Scroll{pos: (pos.0 - offset.0, pos.1 - offset.1), x: *x, y: *y},
|
||||
}
|
||||
}
|
||||
pub fn offset(&self, offset: (u32, u32)) -> Input {
|
||||
match self {
|
||||
Input::Click { pos, button } => Input::Click {
|
||||
pos: (pos.0 - offset.0, pos.1 - offset.1),
|
||||
button: *button,
|
||||
},
|
||||
Input::Scroll { pos, x, y } => Input::Scroll {
|
||||
pos: (pos.0 - offset.0, pos.1 - offset.1),
|
||||
x: *x,
|
||||
y: *y,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ModuleImpl {
|
||||
|
||||
Reference in New Issue
Block a user