mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-28 05:06:56 +02:00
This commit is contained in:
parent
3ee25879cd
commit
95ace83756
1 changed files with 22 additions and 0 deletions
22
src/term.rs
22
src/term.rs
|
|
@ -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)
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue