Add Either3 widget
This commit is contained in:
parent
15e30dfdb2
commit
828bba464a
2 changed files with 85 additions and 9 deletions
|
|
@ -20,15 +20,15 @@ where
|
|||
max_height: Option<u16>,
|
||||
) -> Result<Size, E> {
|
||||
match self {
|
||||
Self::First(l) => l.size(frame, max_width, max_height),
|
||||
Self::Second(r) => r.size(frame, max_width, max_height),
|
||||
Self::First(w) => w.size(frame, max_width, max_height),
|
||||
Self::Second(w) => w.size(frame, max_width, max_height),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(self, frame: &mut Frame) -> Result<(), E> {
|
||||
match self {
|
||||
Self::First(l) => l.draw(frame),
|
||||
Self::Second(r) => r.draw(frame),
|
||||
Self::First(w) => w.draw(frame),
|
||||
Self::Second(w) => w.draw(frame),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,15 +46,79 @@ where
|
|||
max_height: Option<u16>,
|
||||
) -> Result<Size, E> {
|
||||
match self {
|
||||
Self::First(l) => l.size(frame, max_width, max_height).await,
|
||||
Self::Second(r) => r.size(frame, max_width, max_height).await,
|
||||
Self::First(w) => w.size(frame, max_width, max_height).await,
|
||||
Self::Second(w) => w.size(frame, max_width, max_height).await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn draw(self, frame: &mut Frame) -> Result<(), E> {
|
||||
match self {
|
||||
Self::First(l) => l.draw(frame).await,
|
||||
Self::Second(r) => r.draw(frame).await,
|
||||
Self::First(w) => w.draw(frame).await,
|
||||
Self::Second(w) => w.draw(frame).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Either3<I1, I2, I3> {
|
||||
First(I1),
|
||||
Second(I2),
|
||||
Third(I3),
|
||||
}
|
||||
|
||||
impl<E, I1, I2, I3> Widget<E> for Either3<I1, I2, I3>
|
||||
where
|
||||
I1: Widget<E>,
|
||||
I2: Widget<E>,
|
||||
I3: Widget<E>,
|
||||
{
|
||||
fn size(
|
||||
&self,
|
||||
frame: &mut Frame,
|
||||
max_width: Option<u16>,
|
||||
max_height: Option<u16>,
|
||||
) -> Result<Size, E> {
|
||||
match self {
|
||||
Self::First(w) => w.size(frame, max_width, max_height),
|
||||
Self::Second(w) => w.size(frame, max_width, max_height),
|
||||
Self::Third(w) => w.size(frame, max_width, max_height),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(self, frame: &mut Frame) -> Result<(), E> {
|
||||
match self {
|
||||
Self::First(w) => w.draw(frame),
|
||||
Self::Second(w) => w.draw(frame),
|
||||
Self::Third(w) => w.draw(frame),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<E, I1, I2, I3> AsyncWidget<E> for Either3<I1, I2, I3>
|
||||
where
|
||||
I1: AsyncWidget<E> + Send + Sync,
|
||||
I2: AsyncWidget<E> + Send + Sync,
|
||||
I3: AsyncWidget<E> + Send + Sync,
|
||||
{
|
||||
async fn size(
|
||||
&self,
|
||||
frame: &mut Frame,
|
||||
max_width: Option<u16>,
|
||||
max_height: Option<u16>,
|
||||
) -> Result<Size, E> {
|
||||
match self {
|
||||
Self::First(w) => w.size(frame, max_width, max_height).await,
|
||||
Self::Second(w) => w.size(frame, max_width, max_height).await,
|
||||
Self::Third(w) => w.size(frame, max_width, max_height).await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn draw(self, frame: &mut Frame) -> Result<(), E> {
|
||||
match self {
|
||||
Self::First(w) => w.draw(frame).await,
|
||||
Self::Second(w) => w.draw(frame).await,
|
||||
Self::Third(w) => w.draw(frame).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue