use crate::core::geometry::{Point, Rect};
use crate::core::event::Event;
use crate::core::draw::DrawBuffer;
use crate::core::palette::colors;
use crate::terminal::Terminal;
use super::view::{View, write_line_to_terminal};
pub struct Indicator {
bounds: Rect,
location: Point, modified: bool, }
impl Indicator {
pub fn new(bounds: Rect) -> Self {
Self {
bounds,
location: Point::new(1, 1),
modified: false,
}
}
pub fn set_value(&mut self, location: Point, modified: bool) {
self.location = location;
self.modified = modified;
}
}
impl View for Indicator {
fn bounds(&self) -> Rect {
self.bounds
}
fn set_bounds(&mut self, bounds: Rect) {
self.bounds = bounds;
}
fn draw(&mut self, terminal: &mut Terminal) {
let width = self.bounds.width() as usize;
let mut buf = DrawBuffer::new(width);
let text = if self.modified {
format!(" {}:{} * ", self.location.y, self.location.x)
} else {
format!(" {}:{} ", self.location.y, self.location.x)
};
let text_len = text.len().min(width);
let start_pos = width.saturating_sub(text_len);
buf.move_char(0, ' ', colors::DIALOG_FRAME, width);
buf.move_str(start_pos, &text, colors::DIALOG_FRAME);
write_line_to_terminal(terminal, self.bounds.a.x, self.bounds.a.y, &buf);
}
fn handle_event(&mut self, _event: &mut Event) {
}
}