clean up ui, more upgrades

This commit is contained in:
Vinzenz Schroeter 2025-07-06 22:03:11 +02:00
commit 2a4f92c9b3

View file

@ -1,4 +1,4 @@
use servicepoint::GridMut;
use servicepoint::{Bitmap, WindowMut};
#[derive(Debug, Clone, Copy)]
pub struct Bar {
pub progress: f64,
@ -9,33 +9,38 @@ impl Bar {
Self { progress: 0.0 }
}
pub fn draw<P: GridMut<bool>>(&self, bitmap: &mut P) {
pub fn draw(&self, mut bitmap: WindowMut<bool, Bitmap>) {
bitmap.fill(false);
let margin = 1;
let bar_height = bitmap.height() - 2 * margin;
let bar_width = bitmap.width() - 2 * margin;
let border_thickness = 1;
let padding = 1;
let mut bitmap = bitmap
.window_mut(
padding,
padding,
bitmap.width() - 2 * padding,
bitmap.height() - 2 * padding,
)
.unwrap();
// border top + bottom
let last_row = bitmap.height() - margin - border_thickness;
for x in margin..bar_width {
bitmap.set(x, margin, true);
let last_row = bitmap.height() - 1;
for x in 0..bitmap.width() {
bitmap.set(x, 0, true);
bitmap.set(x, last_row, true);
}
// border left + right
let last_col = bitmap.width() - margin - border_thickness;
for y in 1..=bar_height {
bitmap.set(1, y, true);
let last_col = bitmap.width() - 1;
for y in 0..bitmap.height() {
bitmap.set(0, y, true);
bitmap.set(last_col, y, true);
}
// progress fill
let fill_to = ((bar_width - 2) as f64 * self.progress) as usize;
for y in 2..bar_height {
for x in 2..=fill_to {
bitmap.set(x, y, (x + y) % 2 == 0);
let fill_to = (bitmap.width() as f64 * self.progress) as usize;
for y in 1..bitmap.height() - 1 {
for x in 1..bitmap.width() - 1 {
bitmap.set(x, y, x < fill_to && (x + y) % 2 == 0);
}
}
}