Outline
This commit is contained in:
@@ -25,6 +25,8 @@ pub trait App {
|
|||||||
|
|
||||||
self.render(get_screen().allocate(&self.layout().await))
|
self.render(get_screen().allocate(&self.layout().await))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
crossterm::execute!(std::io::stdout()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ impl Allocation {
|
|||||||
widget.render(&mut scope);
|
widget.render(&mut scope);
|
||||||
scope.draw();
|
scope.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn draw_frame<W: Widget>(&self, index: usize, widget: W) {
|
||||||
|
let mut scope = RenderScope::new(self.frame_alloc[index]);
|
||||||
|
widget.render(&mut scope);
|
||||||
|
scope.draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderScope {
|
impl RenderScope {
|
||||||
@@ -89,5 +95,5 @@ impl RenderScope {
|
|||||||
|
|
||||||
pub fn print_at(x: u16, y: u16, text: &str) {
|
pub fn print_at(x: u16, y: u16, text: &str) {
|
||||||
crossterm::execute!(stdout(), crossterm::cursor::MoveTo(x, y)).unwrap();
|
crossterm::execute!(stdout(), crossterm::cursor::MoveTo(x, y)).unwrap();
|
||||||
println!("{text}");
|
print!("{text}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
pub mod outline;
|
||||||
|
|
||||||
use crate::render::RenderScope;
|
use crate::render::RenderScope;
|
||||||
|
|
||||||
pub trait Widget {
|
pub trait Widget {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
use crate::widget::Widget;
|
||||||
|
|
||||||
|
pub struct Outline;
|
||||||
|
|
||||||
|
impl Widget for Outline {
|
||||||
|
fn render(&self, scope: &mut crate::render::RenderScope) {
|
||||||
|
scope.draw_text(0, "-".repeat(scope.rect.width as usize));
|
||||||
|
|
||||||
|
scope.draw_text((0, 1), "|\n".repeat(scope.rect.height as usize - 2));
|
||||||
|
scope.draw_text(
|
||||||
|
(scope.rect.width, 1),
|
||||||
|
"|\n".repeat(scope.rect.height as usize - 2),
|
||||||
|
);
|
||||||
|
|
||||||
|
scope.draw_text(
|
||||||
|
(0, scope.rect.height),
|
||||||
|
"-".repeat(scope.rect.width as usize),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-4
@@ -1,10 +1,7 @@
|
|||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
use pulse_ui::{
|
use pulse_ui::{
|
||||||
App,
|
App, layout::{LayoutItem, layout}, state::State, unit::Size, widget::outline::Outline,
|
||||||
layout::{LayoutItem, layout},
|
|
||||||
state::State,
|
|
||||||
unit::Size,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct PulseTradeApp {
|
pub struct PulseTradeApp {
|
||||||
@@ -27,6 +24,7 @@ impl App for PulseTradeApp {
|
|||||||
|
|
||||||
async fn render(&mut self, layout: pulse_ui::layout::Allocation) {
|
async fn render(&mut self, layout: pulse_ui::layout::Allocation) {
|
||||||
layout.draw(1, "Yo");
|
layout.draw(1, "Yo");
|
||||||
|
layout.draw_frame(0, Outline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user