switch between sequences; layout unfucking

This commit is contained in:
🪞👃🪞 2024-06-21 12:57:46 +03:00
parent c18aa2cbbd
commit 185c6b5b34
7 changed files with 253 additions and 201 deletions

View file

@ -1,5 +1,53 @@
use crate::prelude::*;
pub fn draw_box (buffer: &mut Buffer, area: Rect) -> Rect {
if area.width < 1 || area.height < 1 {
return area
}
let border = Style::default().gray().dim();
let top = format!("{}", "".repeat((area.width - 2).into()));
let bottom = format!("{}", "".repeat((area.width - 2).into()));
buffer.set_string(area.x, area.y, top, border);
for y in (area.y + 1)..(area.y + area.height - 1) {
buffer.set_string(area.x, y, format!(""), border);
buffer.set_string(area.x + area.width - 1, y, format!(""), border);
}
buffer.set_string(area.x, area.y + area.height - 1, bottom, border);
area
}
pub fn draw_box_styled (buffer: &mut Buffer, area: Rect, style: Option<Style>) -> Rect {
if area.width < 1 || area.height < 1 {
return area
}
let style = style.unwrap_or(Style::default());
let top = format!("{}", "".repeat((area.width - 2).into()));
let bottom = format!("{}", "".repeat((area.width - 2).into()));
buffer.set_string(area.x, area.y, top, style);
for y in (area.y + 1)..(area.y + area.height - 1) {
buffer.set_string(area.x, y, format!(""), style);
buffer.set_string(area.x + area.width - 1, y, format!(""), style);
}
buffer.set_string(area.x, area.y + area.height - 1, bottom, style);
area
}
pub fn draw_box_styled_dotted (buffer: &mut Buffer, area: Rect, style: Option<Style>) -> Rect {
if area.width < 1 || area.height < 1 {
return area
}
let style = style.unwrap_or(Style::default());
let top = format!("{}", "".repeat((area.width - 2).into()));
let bottom = format!("{}", "".repeat((area.width - 2).into()));
buffer.set_string(area.x, area.y, top, style);
for y in (area.y + 1)..(area.y + area.height - 1) {
buffer.set_string(area.x, y, format!(""), style);
buffer.set_string(area.x + area.width - 1, y, format!(""), style);
}
buffer.set_string(area.x, area.y + area.height - 1, bottom, style);
area
}
pub struct Column(pub Vec<Box<dyn Device>>);
impl Column {
@ -18,24 +66,25 @@ impl Row {
impl Device for Column {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
Ok(render_column(&self.0, buf, area)?.0)
Ok(draw_column(&self.0, buf, area, 0)?.0)
}
}
impl Device for Row {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
Ok(render_row(&self.0, buf, area)?.0)
Ok(draw_row(&self.0, buf, area, 0)?.0)
}
}
pub fn render_column (items: &[Box<dyn Device>], buf: &mut Buffer, area: Rect)
pub fn draw_column (items: &[Box<dyn Device>], buf: &mut Buffer, area: Rect, space: i16)
-> Usually<(Rect, Vec<Rect>)>
{
let mut w = 0u16;
let mut h = 0u16;
let mut rects = vec![];
for (i, device) in items.iter().enumerate() {
let rect = Rect { x: area.x, y: area.y + h, width: area.width, height: area.height - h };
let y = ((area.y + h) as i16).saturating_add(space) as u16;
let rect = Rect { x: area.x, y, width: area.width, height: area.height - h };
let result = device.render(buf, rect)?;
rects.push(result);
w = w.max(result.width);
@ -44,14 +93,15 @@ pub fn render_column (items: &[Box<dyn Device>], buf: &mut Buffer, area: Rect)
Ok((Rect { x: area.x, y: area.y, width: w, height: h }, rects))
}
pub fn render_row (items: &[Box<dyn Device>], buf: &mut Buffer, area: Rect)
pub fn draw_row (items: &[Box<dyn Device>], buf: &mut Buffer, area: Rect, space: i16)
-> Usually<(Rect, Vec<Rect>)>
{
let mut w = 0u16;
let mut h = 0u16;
let mut rects = vec![];
for (i, device) in items.iter().enumerate() {
let rect = Rect { x: area.x + w, y: area.y, width: area.width - w, height: area.height };
let x = ((area.x + w) as i16).saturating_add(space) as u16;
let rect = Rect { x, y: area.y, width: area.width - w, height: area.height };
let result = device.render(buf, rect)?;
rects.push(result);
w = w + result.width;