Display stuff

This commit is contained in:
2026-07-14 22:53:27 +02:00
parent b8162ebe3c
commit 7be4040267
4 changed files with 31 additions and 12 deletions
-6
View File
@@ -8,7 +8,6 @@ use crate::{
pub enum Instr { pub enum Instr {
DrawText(Point, String), DrawText(Point, String),
DrawOutline(Rect),
} }
pub struct RenderScope { pub struct RenderScope {
@@ -21,10 +20,6 @@ impl RenderScope {
self.draw_instructions self.draw_instructions
.push(Instr::DrawText(at.into(), text.to_string())); .push(Instr::DrawText(at.into(), text.to_string()));
} }
pub fn draw_outline<P: Into<Point>>(&mut self, rect: Rect) {
self.draw_instructions.push(Instr::DrawOutline(rect));
}
} }
impl RenderScope { impl RenderScope {
@@ -87,7 +82,6 @@ impl RenderScope {
); );
} }
} }
Instr::DrawOutline(rect) => {}
} }
} }
} }
+6
View File
@@ -40,6 +40,12 @@ impl<T> State<T> {
} }
} }
impl<T: std::fmt::Display> State<T> {
pub async fn display(&self) -> String {
self.lock().await.to_string()
}
}
impl<'a, T> std::ops::Deref for StateGuard<'a, T> { impl<'a, T> std::ops::Deref for StateGuard<'a, T> {
type Target = T; type Target = T;
+20 -1
View File
@@ -6,8 +6,27 @@ pub trait Widget {
fn render(&self, scope: &mut RenderScope); fn render(&self, scope: &mut RenderScope);
} }
impl Widget for &str { macro_rules! display_widget {
($t:ty) => {
impl Widget for $t {
fn render(&self, scope: &mut RenderScope) { fn render(&self, scope: &mut RenderScope) {
scope.draw_text(0, self); 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);
+2 -2
View File
@@ -1,7 +1,7 @@
use std::any::Any; use std::any::Any;
use pulse_ui::{ use pulse_ui::{
App, get_screen, App,
layout::{LayoutItem, layout}, layout::{LayoutItem, layout},
state::{Refresh, State}, state::{Refresh, State},
unit::Size, unit::Size,
@@ -37,7 +37,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, 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(1, Outline);
layout.draw_frame(2, Outline); layout.draw_frame(2, Outline);
} }