some nice dynamic stuff

This commit is contained in:
2024-12-12 17:14:48 +01:00
parent 250528950a
commit b4c4e32aba
7 changed files with 129 additions and 135 deletions
+26 -4
View File
@@ -1,5 +1,7 @@
use std::io::{stdout, Write};
use crossterm::terminal::disable_raw_mode;
pub struct Frame {
used: Vec<u16>,
width: u16,
@@ -21,9 +23,21 @@ impl Frame {
pub fn render(&mut self, focused: bool, element: &crate::Element) {
let style = element.get_style().get(focused);
if style.visible {
let y = style.y.as_position_y(&self.used, self.height);
let y = style.y.as_position(
&{
let mut y_ = 0;
for n in self.used.iter().rev() {
if *n == 0 {
break;
}
y_ += 1;
}
y_
},
self.height,
);
if let Some(y_) = self.used.get(y as usize) {
let x = style.x.as_position_x(y_, self.width);
let x = style.x.as_position(y_, self.width);
let mut writer = crate::Writer::new(
focused,
style.clone(),
@@ -31,9 +45,17 @@ impl Frame {
(self.width, self.height),
);
element.render(&mut writer);
let (width, height) = writer.get_size();
let (width, height) = writer.get_size_root();
if style.outline {
clear();
show_cursor();
disable_raw_mode().unwrap();
panic!("the 'outline' option isn't available right now. please set 'outline' to 'false'")
}
for i in y..y + height {
*self.used.get_mut(i as usize).unwrap() += x + width;
if let Some(o) = self.used.get_mut(i as usize) {
*o += x + width;
}
}
}
}