Box widgets

This way, widgets containing other widgets can be heterogenous. Wenever
a widget is expeted, *any* widget will work.
This commit is contained in:
Joscha 2022-07-12 21:09:38 +02:00
parent dea0384162
commit 8eda1ad97d
5 changed files with 5 additions and 5 deletions

View file

@ -255,7 +255,7 @@ impl EuphRoom {
let mut list = self.nick_list.list();
Self::render_rows(&mut list, joined);
list.render(frame, pos, size).await;
Box::new(list).render(frame, pos, size).await;
}
fn render_hsplit(frame: &mut Frame, hsplit: i32) {

View file

@ -146,7 +146,7 @@ impl Rooms {
let rooms = self.stabilize_rooms().await;
let mut list = self.list.list().focus(true);
self.render_rows(&mut list, rooms).await;
list.render(frame, Pos::ZERO, frame.size()).await;
Box::new(list).render(frame, Pos::ZERO, frame.size()).await;
}
pub async fn handle_key_event(

View file

@ -8,5 +8,5 @@ use toss::frame::{Frame, Pos, Size};
pub trait Widget {
fn size(&self, frame: &mut Frame, max_width: Option<u16>, max_height: Option<u16>) -> Size;
async fn render(self, frame: &mut Frame, pos: Pos, size: Size);
async fn render(self: Box<Self>, frame: &mut Frame, pos: Pos, size: Size);
}

View file

@ -308,7 +308,7 @@ impl<Id: Clone + Eq + Send> Widget for List<Id> {
Size::new(width as u16, height as u16)
}
async fn render(self, frame: &mut Frame, pos: Pos, size: Size) {
async fn render(self: Box<Self>, frame: &mut Frame, pos: Pos, size: Size) {
let mut guard = self.state.lock();
guard.stabilize(&self.rows, size.height.into());
for (i, row) in self.rows.into_iter().enumerate() {

View file

@ -47,7 +47,7 @@ impl Widget for Text {
Size::new(min_width as u16, min_height as u16)
}
async fn render(self, frame: &mut Frame, pos: Pos, size: Size) {
async fn render(self: Box<Self>, frame: &mut Frame, pos: Pos, size: Size) {
for (i, line) in self
.wrapped(frame, Some(size.width))
.into_iter()