Add Background widget
This commit is contained in:
parent
1000de5bcf
commit
fd1b337cd1
4 changed files with 70 additions and 17 deletions
34
showbits-common/src/widgets/background.rs
Normal file
34
showbits-common/src/widgets/background.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use crate::{BoxedWidget, Vec2, Widget};
|
||||
|
||||
pub struct Background<C> {
|
||||
inner: BoxedWidget<C>,
|
||||
color: C,
|
||||
}
|
||||
|
||||
impl<C> Background<C> {
|
||||
pub fn new(inner: BoxedWidget<C>, color: C) -> Self {
|
||||
Self { inner, color }
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: Copy> Widget<C> for Background<C> {
|
||||
fn size(&self, max_width: Option<i32>, max_height: Option<i32>) -> crate::Vec2 {
|
||||
self.inner.size(max_width, max_height)
|
||||
}
|
||||
|
||||
fn resize(&mut self, area: crate::Rect) {
|
||||
self.inner.resize(area);
|
||||
}
|
||||
|
||||
fn update(&mut self, _area: crate::Rect) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn draw(self, view: &mut crate::View<'_, C>) {
|
||||
for y in 0..view.size().y {
|
||||
for x in 0..view.size().x {
|
||||
view.set(Vec2::new(x, y), self.color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue