diff --git a/pulse-ui/src/render.rs b/pulse-ui/src/render.rs index bde8aaf..b8ab8a1 100644 --- a/pulse-ui/src/render.rs +++ b/pulse-ui/src/render.rs @@ -8,7 +8,6 @@ use crate::{ pub enum Instr { DrawText(Point, String), - DrawOutline(Rect), } pub struct RenderScope { @@ -21,10 +20,6 @@ impl RenderScope { self.draw_instructions .push(Instr::DrawText(at.into(), text.to_string())); } - - pub fn draw_outline>(&mut self, rect: Rect) { - self.draw_instructions.push(Instr::DrawOutline(rect)); - } } impl RenderScope { @@ -87,7 +82,6 @@ impl RenderScope { ); } } - Instr::DrawOutline(rect) => {} } } } diff --git a/pulse-ui/src/state.rs b/pulse-ui/src/state.rs index 36020d1..7ff8e6b 100644 --- a/pulse-ui/src/state.rs +++ b/pulse-ui/src/state.rs @@ -40,6 +40,12 @@ impl State { } } +impl State { + pub async fn display(&self) -> String { + self.lock().await.to_string() + } +} + impl<'a, T> std::ops::Deref for StateGuard<'a, T> { type Target = T; diff --git a/pulse-ui/src/widget/mod.rs b/pulse-ui/src/widget/mod.rs index f11b45f..aa8e40b 100644 --- a/pulse-ui/src/widget/mod.rs +++ b/pulse-ui/src/widget/mod.rs @@ -6,8 +6,27 @@ pub trait Widget { fn render(&self, scope: &mut RenderScope); } -impl Widget for &str { - fn render(&self, scope: &mut RenderScope) { - scope.draw_text(0, self); - } +macro_rules! display_widget { + ($t:ty) => { + impl Widget for $t { + fn render(&self, scope: &mut RenderScope) { + scope.draw_text(0, self); + } + } + }; } + +display_widget!(&str); +display_widget!(String); +display_widget!(i8); +display_widget!(i16); +display_widget!(i32); +display_widget!(i64); +display_widget!(i128); +display_widget!(u8); +display_widget!(u16); +display_widget!(u32); +display_widget!(u64); +display_widget!(u128); +display_widget!(f32); +display_widget!(f64); diff --git a/src/main.rs b/src/main.rs index 44d26c7..0428109 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use std::any::Any; use pulse_ui::{ - App, get_screen, + App, layout::{LayoutItem, layout}, state::{Refresh, State}, unit::Size, @@ -37,7 +37,7 @@ impl App for PulseTradeApp { } async fn render(&mut self, layout: pulse_ui::layout::Allocation) { - layout.draw(1, format!("{:?}", *self.count.lock().await).as_str()); + layout.draw(1, format!("{}", self.count.display().await).as_str()); layout.draw_frame(1, Outline); layout.draw_frame(2, Outline); }