You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/core/embed/rust/src/ui/component/pad.rs

64 lines
1.2 KiB

use crate::ui::{
display::{self, Color},
geometry::Rect,
shape,
shape::Renderer,
};
pub struct Pad {
pub area: Rect,
pub color: Color,
clear: bool,
}
impl Pad {
pub fn with_background(color: Color) -> Self {
Self {
color,
area: Rect::zero(),
clear: false,
}
}
pub fn with_clear(self) -> Self {
Self {
clear: true,
..self
}
}
pub fn place(&mut self, area: Rect) {
self.area = area;
}
pub fn clear(&mut self) {
self.clear = true;
}
pub fn cancel_clear(&mut self) {
self.clear = false;
}
pub fn will_paint(&self) -> Option<(Rect, Color)> {
if self.clear {
Some((self.area, self.color))
} else {
None
}
}
pub fn paint(&mut self) {
if self.clear {
self.clear = false;
display::rect_fill(self.area, self.color);
}
}
pub fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
shape::Bar::new(self.area)
.with_bg(self.color)
.render(target);
}
}