Add basic HRule and VRule widgets

This commit is contained in:
Joscha 2022-07-20 21:04:06 +02:00
parent 78906ffd96
commit 32f1ad5aae
2 changed files with 37 additions and 0 deletions

View file

@ -1,6 +1,7 @@
pub mod background;
pub mod empty;
pub mod list;
pub mod rules;
pub mod text;
use async_trait::async_trait;

36
src/ui/widgets/rules.rs Normal file
View file

@ -0,0 +1,36 @@
use async_trait::async_trait;
use toss::frame::{Frame, Pos, Size};
use super::Widget;
pub struct HRule;
#[async_trait]
impl Widget for HRule {
fn size(&self, _frame: &mut Frame, _max_width: Option<u16>, _max_height: Option<u16>) -> Size {
Size::new(0, 1)
}
async fn render(self: Box<Self>, frame: &mut Frame) {
let size = frame.size();
for x in 0..size.width as i32 {
frame.write(Pos::new(x, 0), "");
}
}
}
pub struct VRule;
#[async_trait]
impl Widget for VRule {
fn size(&self, _frame: &mut Frame, _max_width: Option<u16>, _max_height: Option<u16>) -> Size {
Size::new(1, 0)
}
async fn render(self: Box<Self>, frame: &mut Frame) {
let size = frame.size();
for y in 0..size.height as i32 {
frame.write(Pos::new(0, y), "");
}
}
}