Use frame stack instead of explicit pos and size parameters
This commit is contained in:
parent
44470b973d
commit
9aed0a3cee
9 changed files with 22 additions and 15 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1246,7 +1246,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "toss"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/Garmelon/toss.git?rev=e4e1454e8064269350ff7f10b2dcbb388d26c57d#e4e1454e8064269350ff7f10b2dcbb388d26c57d"
|
||||
source = "git+https://github.com/Garmelon/toss.git?rev=14aedaf25212cd50924566821ad37645a4cacf28#14aedaf25212cd50924566821ad37645a4cacf28"
|
||||
dependencies = [
|
||||
"crossterm",
|
||||
"unicode-linebreak",
|
||||
|
|
|
|||
|
|
@ -30,4 +30,4 @@ features = ["rustls-tls-native-roots"]
|
|||
|
||||
[dependencies.toss]
|
||||
git = "https://github.com/Garmelon/toss.git"
|
||||
rev = "e4e1454e8064269350ff7f10b2dcbb388d26c57d"
|
||||
rev = "14aedaf25212cd50924566821ad37645a4cacf28"
|
||||
|
|
|
|||
|
|
@ -262,7 +262,9 @@ impl EuphRoom {
|
|||
|
||||
let mut list = self.nick_list.list();
|
||||
Self::render_rows(&mut list, joined);
|
||||
Box::new(list).render(frame, pos, size).await;
|
||||
frame.push(pos, size);
|
||||
Box::new(list).render(frame).await;
|
||||
frame.pop();
|
||||
}
|
||||
|
||||
fn render_hsplit(frame: &mut Frame, hsplit: i32) {
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ impl Rooms {
|
|||
let rooms = self.stabilize_rooms().await;
|
||||
let mut list = self.list.list().focus(true);
|
||||
self.render_rows(&mut list, rooms).await;
|
||||
Box::new(list).render(frame, Pos::ZERO, frame.size()).await;
|
||||
Box::new(list).render(frame).await;
|
||||
}
|
||||
|
||||
pub async fn handle_key_event(
|
||||
|
|
|
|||
|
|
@ -10,5 +10,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: Box<Self>, frame: &mut Frame, pos: Pos, size: Size);
|
||||
async fn render(self: Box<Self>, frame: &mut Frame);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,14 @@ impl Widget for Background {
|
|||
self.inner.size(frame, max_width, max_height)
|
||||
}
|
||||
|
||||
async fn render(self: Box<Self>, frame: &mut Frame, pos: Pos, size: Size) {
|
||||
async fn render(self: Box<Self>, frame: &mut Frame) {
|
||||
let size = frame.size();
|
||||
for dy in 0..size.height {
|
||||
for dx in 0..size.width {
|
||||
frame.write(pos + Pos::new(dx.into(), dy.into()), (" ", self.style));
|
||||
frame.write(Pos::new(dx.into(), dy.into()), (" ", self.style));
|
||||
}
|
||||
}
|
||||
|
||||
self.inner.render(frame, pos, size).await;
|
||||
self.inner.render(frame).await;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,5 +11,5 @@ impl Widget for Empty {
|
|||
Size::ZERO
|
||||
}
|
||||
|
||||
async fn render(self: Box<Self>, _frame: &mut Frame, _pos: Pos, _size: Size) {}
|
||||
async fn render(self: Box<Self>, _frame: &mut Frame) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -289,7 +289,9 @@ impl<Id: Clone + Eq + Send> Widget for List<Id> {
|
|||
Size::new(width, height as u16)
|
||||
}
|
||||
|
||||
async fn render(self: Box<Self>, frame: &mut Frame, pos: Pos, size: Size) {
|
||||
async fn render(self: Box<Self>, frame: &mut Frame) {
|
||||
let size = frame.size();
|
||||
|
||||
// Guard acquisition and dropping must be inside its own block or the
|
||||
// compiler complains that "future created by async block is not
|
||||
// `Send`", pointing to the function body.
|
||||
|
|
@ -310,9 +312,9 @@ impl<Id: Clone + Eq + Send> Widget for List<Id> {
|
|||
break;
|
||||
}
|
||||
|
||||
let pos = pos + Pos::new(0, dy);
|
||||
frame.push(Pos::new(0, dy), row_size);
|
||||
match row {
|
||||
Row::Unselectable { normal } => normal.render(frame, pos, row_size).await,
|
||||
Row::Unselectable { normal } => normal.render(frame).await,
|
||||
Row::Selectable {
|
||||
id,
|
||||
normal,
|
||||
|
|
@ -325,9 +327,10 @@ impl<Id: Clone + Eq + Send> Widget for List<Id> {
|
|||
false
|
||||
};
|
||||
let widget = if focusing { selected } else { normal };
|
||||
widget.render(frame, pos, row_size).await;
|
||||
widget.render(frame).await;
|
||||
}
|
||||
}
|
||||
frame.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,13 +47,14 @@ impl Widget for Text {
|
|||
Size::new(min_width as u16, min_height as u16)
|
||||
}
|
||||
|
||||
async fn render(self: Box<Self>, frame: &mut Frame, pos: Pos, size: Size) {
|
||||
async fn render(self: Box<Self>, frame: &mut Frame) {
|
||||
let size = frame.size();
|
||||
for (i, line) in self
|
||||
.wrapped(frame, Some(size.width))
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
frame.write(pos + Pos::new(0, i as i32), line);
|
||||
frame.write(Pos::new(0, i as i32), line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue