Skip to main content

carch_core/ui/widgets/
mod.rs

1pub mod category_list;
2pub mod header;
3pub mod script_list;
4pub mod status_bar;
5
6use ratatui::Frame;
7use ratatui::layout::Rect;
8use ratatui::style::{Color, Style};
9use ratatui::widgets::ListState;
10
11const ROUNDED_LEFT: &str = "\u{e0b6}";
12const ROUNDED_RIGHT: &str = "\u{e0b4}";
13
14pub fn paint_rounded_highlight(f: &mut Frame, area: Rect, state: &ListState, highlight_bg: Color) {
15    let Some(selected) = state.selected() else {
16        return;
17    };
18
19    if area.width < 4 || area.height < 3 {
20        return;
21    }
22
23    let offset = state.offset();
24    if selected < offset {
25        return;
26    }
27    let row_offset = (selected - offset) as u16;
28    let inner_height = area.height.saturating_sub(2);
29    if row_offset >= inner_height {
30        return;
31    }
32
33    let y = area.y + 1 + row_offset;
34    let left_x = area.x + 1;
35    let right_x = area.x + area.width - 2;
36
37    let buf = f.buffer_mut();
38    let cap_style = Style::default().fg(highlight_bg).bg(Color::Reset);
39
40    if let Some(cell) = buf.cell_mut((left_x, y)) {
41        cell.set_symbol(ROUNDED_LEFT).set_style(cap_style);
42    }
43    if let Some(cell) = buf.cell_mut((right_x, y)) {
44        cell.set_symbol(ROUNDED_RIGHT).set_style(cap_style);
45    }
46}