Add Layer widget

This commit is contained in:
Joscha 2022-07-21 15:42:06 +02:00
parent a620fcf907
commit 4fa4c9a897
2 changed files with 34 additions and 0 deletions

View file

@ -2,6 +2,7 @@ pub mod background;
pub mod border; pub mod border;
pub mod empty; pub mod empty;
pub mod join; pub mod join;
pub mod layer;
pub mod list; pub mod list;
pub mod padding; pub mod padding;
pub mod rules; pub mod rules;

33
src/ui/widgets/layer.rs Normal file
View file

@ -0,0 +1,33 @@
use async_trait::async_trait;
use toss::frame::{Frame, Size};
use super::{BoxedWidget, Widget};
pub struct Layer {
layers: Vec<BoxedWidget>,
}
impl Layer {
pub fn new(layers: Vec<BoxedWidget>) -> Self {
Self { layers }
}
}
#[async_trait]
impl Widget for Layer {
fn size(&self, frame: &mut Frame, max_width: Option<u16>, max_height: Option<u16>) -> Size {
let mut max_size = Size::ZERO;
for layer in &self.layers {
let size = layer.size(frame, max_width, max_height);
max_size.width = max_size.width.max(size.width);
max_size.height = max_size.height.max(size.height);
}
max_size
}
async fn render(self: Box<Self>, frame: &mut Frame) {
for layer in self.layers {
layer.render(frame).await;
}
}
}