Rename Layer parts

This commit is contained in:
Joscha 2023-02-18 02:49:52 +01:00
parent 95a01d5fc8
commit f25ce49e77
2 changed files with 18 additions and 18 deletions

View file

@ -49,12 +49,12 @@ pub trait WidgetExt: Sized {
Float::new(self)
}
fn below<W>(self, top: W) -> Layer<Self, W> {
Layer::new(self, top)
fn below<W>(self, above: W) -> Layer<Self, W> {
Layer::new(self, above)
}
fn above<W>(self, bottom: W) -> Layer<W, Self> {
Layer::new(bottom, self)
fn above<W>(self, below: W) -> Layer<W, Self> {
Layer::new(below, self)
}
fn padding(self) -> Padding<Self> {

View file

@ -3,17 +3,17 @@ use async_trait::async_trait;
use crate::{AsyncWidget, Frame, Size, Widget};
pub struct Layer<I1, I2> {
bottom: I1,
top: I2,
below: I1,
above: I2,
}
impl<I1, I2> Layer<I1, I2> {
pub fn new(bottom: I1, top: I2) -> Self {
Self { bottom, top }
pub fn new(below: I1, above: I2) -> Self {
Self { below, above }
}
fn size(bottom: Size, top: Size) -> Size {
Size::new(bottom.width.max(top.width), bottom.height.max(top.height))
fn size(below: Size, above: Size) -> Size {
Size::new(below.width.max(above.width), below.height.max(above.height))
}
}
@ -28,14 +28,14 @@ where
max_width: Option<u16>,
max_height: Option<u16>,
) -> Result<Size, E> {
let bottom = self.bottom.size(frame, max_width, max_height)?;
let top = self.top.size(frame, max_width, max_height)?;
let bottom = self.below.size(frame, max_width, max_height)?;
let top = self.above.size(frame, max_width, max_height)?;
Ok(Self::size(bottom, top))
}
fn draw(self, frame: &mut Frame) -> Result<(), E> {
self.bottom.draw(frame)?;
self.top.draw(frame)?;
self.below.draw(frame)?;
self.above.draw(frame)?;
Ok(())
}
}
@ -52,14 +52,14 @@ where
max_width: Option<u16>,
max_height: Option<u16>,
) -> Result<Size, E> {
let bottom = self.bottom.size(frame, max_width, max_height).await?;
let top = self.top.size(frame, max_width, max_height).await?;
let bottom = self.below.size(frame, max_width, max_height).await?;
let top = self.above.size(frame, max_width, max_height).await?;
Ok(Self::size(bottom, top))
}
async fn draw(self, frame: &mut Frame) -> Result<(), E> {
self.bottom.draw(frame).await?;
self.top.draw(frame).await?;
self.below.draw(frame).await?;
self.above.draw(frame).await?;
Ok(())
}
}