implement Draw<Tui> for usize
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
facile pop culture reference 2026-08-13 07:43:42 +03:00
parent 3ee25879cd
commit 95ace83756

View file

@ -439,6 +439,28 @@ impl<T: Draw<Tui>> Draw<Tui> for ShowSizeOf<T> {
}
}
impl_draw!(|self: usize, to: Tui|{
let XYWH(x0, y0, w0, h0) = to.area();
let mut v = *self;
let w = (1 + if v > 0 { self.ilog10() } else { 0 }) as u16;
let h = 1u16;
Ok((w0 >= w && h0 >= h).then(||{
if let Tui::Draw(buffer, ..) = to {
let mut x = x0 + w - 1;
while x >= x0 {
if let Some(cell) = buffer.cell_mut(Position { x, y: y0 }) {
cell.set_char([
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
][(v % 10) as usize]);
}
x -= 1;
v = v / 10;
}
}
XYWH(x0, y0, w, h)
}))
});
impl_draw!(|self: String, to: Tui|{
self.as_str().draw(to)
});