From 4fa4c9a897b2cc15871f4bbd4b3c2c24289f6531 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 21 Jul 2022 15:42:06 +0200 Subject: [PATCH] Add Layer widget --- src/ui/widgets.rs | 1 + src/ui/widgets/layer.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/ui/widgets/layer.rs diff --git a/src/ui/widgets.rs b/src/ui/widgets.rs index a95ba5d..ceaebd4 100644 --- a/src/ui/widgets.rs +++ b/src/ui/widgets.rs @@ -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; diff --git a/src/ui/widgets/layer.rs b/src/ui/widgets/layer.rs new file mode 100644 index 0000000..7c5e659 --- /dev/null +++ b/src/ui/widgets/layer.rs @@ -0,0 +1,33 @@ +use async_trait::async_trait; +use toss::frame::{Frame, Size}; + +use super::{BoxedWidget, Widget}; + +pub struct Layer { + layers: Vec, +} + +impl Layer { + pub fn new(layers: Vec) -> Self { + Self { layers } + } +} + +#[async_trait] +impl Widget for Layer { + fn size(&self, frame: &mut Frame, max_width: Option, max_height: Option) -> 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, frame: &mut Frame) { + for layer in self.layers { + layer.render(frame).await; + } + } +}