refactor: separate Render from Handle

This commit is contained in:
🪞👃🪞 2024-06-22 10:15:14 +03:00
parent d9b3bd150e
commit 72ead536be
12 changed files with 255 additions and 212 deletions

View file

@ -35,29 +35,25 @@ pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
-> Usually<Rect>
{
let Rect { x, y, .. } = area;
let selected = Some(if state.focused {
Style::default().green().not_dim()
} else {
Style::default().green().dim()
});
Ok(match state.view {
ChainView::Hidden => Rect { x, y, width: 0, height: 0 },
ChainView::Compact => {
let area = Rect { x, y, width: (state.name.len() + 4) as u16, height: 3 };
buf.set_string(area.x + 2, area.y + 1, &state.name, Style::default());
draw_box_styled(buf, area, Some(Style::default().dim()))
draw_box_styled(buf, area, selected)
},
ChainView::Row => {
let (area, areas) = draw_row(&state.items, buf, area, 0)?;
draw_box_styled(buf, area, Some(Style::default().dim()))
let (area, areas) = Row::draw(buf, area, &state.items, 0)?;
draw_box_styled(buf, area, selected)
},
ChainView::Column => {
let (area, areas) = draw_column(&state.items, buf, area, 0)?;
//draw_box_styled(buf, area, Some(if state.focused {
//Style::default().dim()
//} else {
//Style::default().not_dim()
//}));
draw_box_styled(buf, areas[state.focus], Some(if state.focused {
Style::default().green().not_dim()
} else {
Style::default().green().dim()
}));
let (area, areas) = Column::draw(buf, area, &state.items, 0)?;
draw_box_styled(buf, areas[state.focus], selected);
area
},
})