add borders around panels

This commit is contained in:
Vinzenz Schroeter 2025-07-06 17:55:50 +02:00
commit 12f48497ae

View file

@ -1,60 +1,15 @@
use crate::Currency;
use servicepoint::{CharGridMutExt, GridMut, WindowMut};
use std::time::Duration;
use servicepoint::GridMut;
#[derive(Debug, Clone, Copy)]
pub struct Bar {
name: &'static str,
progress: f64,
pub(crate) enabled: bool,
pub(crate) speed: f64,
pub(crate) productivity: f64,
pub progress: f64,
}
impl Bar {
pub(crate) fn new(productivity: f64, speed: f64, name: &'static str) -> Self {
Self {
name,
productivity,
speed,
enabled: false,
progress: 0f64,
}
pub fn new() -> Self {
Self { progress: 0.0 }
}
pub(crate) fn name(&self) -> &'static str {
self.name
}
pub(crate) fn progress(&mut self, delta: Duration) -> Currency {
if !self.enabled {
return 0.0;
}
let extra_progress = delta.mul_f64(self.speed).as_secs_f64();
let progress = self.progress + extra_progress;
let completions = progress.floor();
self.progress = progress - completions;
completions * self.productivity
}
pub fn draw<C: GridMut<char>, P: GridMut<bool>>(&self, chars: &mut C, bitmap: &mut P) {
if !self.enabled {
return;
}
let mut bitmap = WindowMut::new(bitmap, 0, 0, bitmap.width() / 2, bitmap.height()).unwrap();
let mut chars = WindowMut::new(
chars,
chars.width() / 2 + 1,
0,
chars.width() / 2 - 1,
chars.height(),
)
.unwrap();
chars.set_row_str(0, self.name).unwrap();
pub fn draw<P: GridMut<bool>>(&self, bitmap: &mut P) {
bitmap.fill(false);
let margin = 1;