Add Layer widget
This commit is contained in:
parent
a620fcf907
commit
4fa4c9a897
2 changed files with 34 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ pub mod background;
|
|||
pub mod border;
|
||||
pub mod empty;
|
||||
pub mod join;
|
||||
pub mod layer;
|
||||
pub mod list;
|
||||
pub mod padding;
|
||||
pub mod rules;
|
||||
|
|
|
|||
33
src/ui/widgets/layer.rs
Normal file
33
src/ui/widgets/layer.rs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue