rustimal 0.8.0

A minimal, GPU-rendered terminal for Windows that runs Git Bash, with animated split panes and a glass look
//! The session picker's card.

use super::*;

pub(super) fn draw_picker(ctx: &mut Ctx, picker: &mut Picker, pane: &Rect, out: &mut Vec<Quad>) {
    let s = ctx.scale;
    let pal = ctx.palette;
    let speed = ctx.config.animation_speed;
    let d = |secs: f32| if speed <= 0.0 { 0.0 } else { secs / speed };
    let now = ctx.now;
    let (cw, ch) = (ctx.glyphs.cell_w, ctx.glyphs.cell_h);

    // Fade in with a small rise; fade straight out on close.
    let target_op = if picker.closing { 0.0 } else { 1.0 };
    picker.opacity_anim.set(target_op, d(if picker.closing { 0.12 } else { 0.16 }), now);
    picker.opacity = picker.opacity_anim.get(now);
    let sel = picker.selected as f32;
    picker.highlight_anim.set(sel, d(0.12), now);
    picker.highlight = picker.highlight_anim.get(now);
    let op = picker.opacity;
    let rise = if picker.closing { 0.0 } else { (1.0 - op) * 6.0 * s };

    // Layout.
    let pad = (18.0 * s).round();
    let row_h = (ch * 1.8).round();
    let search_h = (ch * 1.9).round();
    let rows = picker.rows();
    let fixed = pad * 2.0 + ch + 12.0 * s + search_h + 10.0 * s + 10.0 * s + ch;
    let room = ((pane.h - 48.0 * s - fixed) / row_h).floor().max(1.0) as usize;
    let visible = rows.min(room).min(9);
    let w = (pane.w - 40.0 * s).min(700.0 * s).max(cw * 24.0).min(pane.w);
    let h = fixed + visible as f32 * row_h;
    let x = (pane.x + (pane.w - w) * 0.5).round();
    let y = (pane.y + (pane.h - h) * 0.42 + rise).round();
    let card = Rect::new(x, y, w, h);
    picker.card = card;

    // Keep the selection in view, scrolling smoothly.
    let cur = picker.scroll_anim.target();
    let scroll_t = if sel < cur {
        sel
    } else if sel >= cur + visible as f32 {
        sel - visible as f32 + 1.0
    } else {
        cur
    };
    picker.scroll_anim.set(scroll_t, d(0.14), now);
    picker.scroll = picker.scroll_anim.get(now);
    picker.animating =
        picker.opacity_anim.active(now) || picker.highlight_anim.active(now) || picker.scroll_anim.active(now);

    // Backdrop over the pane, then the card.
    let radius = ctx.config.radius * s;
    out.push(rounded(pane.inset(1.0 * s), with_alpha(pal.background, 0.62 * op), radius, 0.0, [0.0; 4], NO_CLIP));
    let see_through = ctx.alpha < 1.0;
    out.push(shadow(card, 14.0 * s, 22.0 * s, 8.0 * s, 0.55 * op, see_through));
    let card_bg = mix(pal.surface, pal.foreground, 0.035);
    if ctx.glass {
        let tint = with_alpha(card_bg, (ctx.alpha + 0.12).min(1.0) * op);
        out.push(glass(card, tint, with_alpha(WHITE, 0.6 * op), 0.55 * op, 14.0 * s, s));
    } else {
        let border = mix(pal.border, pal.foreground, 0.06);
        out.push(rounded(card, with_alpha(card_bg, op), 14.0 * s, s.max(1.0), with_alpha(border, op), NO_CLIP));
    }

    let muted = with_alpha(mix(pal.foreground, card_bg, 0.55), op);
    let fg = with_alpha(pal.foreground, op);
    let inner_w = w - 2.0 * pad;

    // Header: "✻ claude  project" and a session count.
    let mut hx = x + pad;
    let hy = y + pad;
    hx += text(ctx, out, hx, hy, "✻ claude", with_alpha(CLAUDE, op), STYLE_BOLD, inner_w, NO_CLIP);
    hx += cw * 2.0;
    let count = match picker.sessions.len() {
        0 => "no sessions yet".to_string(),
        1 => "1 session".to_string(),
        n => format!("{n} sessions"),
    };
    let count_w = count.chars().count() as f32 * cw;
    text(ctx, out, x + w - pad - count_w, hy, &count, muted, 0, count_w + 1.0, NO_CLIP);
    let project = picker.project.clone();
    text(ctx, out, hx, hy, &project, fg, 0, (x + w - pad - count_w - cw * 2.0 - hx).max(0.0), NO_CLIP);

    // Search field.
    let sy = hy + ch + 12.0 * s;
    let field = Rect::new(x + pad, sy, inner_w, search_h);
    out.push(rounded(
        field,
        with_alpha(pal.surface, ctx.alpha * op),
        9.0 * s,
        s.max(1.0),
        with_alpha(pal.border, op),
        NO_CLIP,
    ));
    let ty = (sy + (search_h - ch) * 0.5).round();
    let tx = field.x + cw;
    text(ctx, out, tx, ty, "›", with_alpha(CLAUDE, op), STYLE_BOLD, cw * 2.0, NO_CLIP);
    let qx = tx + cw * 2.0;
    let placeholder = with_alpha(mix(pal.foreground, pal.surface, 0.7), op);
    let qw = if picker.query.is_empty() {
        text(ctx, out, qx, ty, "search sessions", placeholder, 0, field.w - cw * 4.0, NO_CLIP);
        0.0
    } else {
        let q = picker.query.clone();
        text(ctx, out, qx, ty, &q, fg, 0, field.w - cw * 5.0, NO_CLIP)
    };
    if !picker.closing {
        let cx = if picker.query.is_empty() { qx - 3.0 * s } else { qx + qw + 1.0 };
        let caret = Rect::new(cx, ty + ch * 0.12, (1.5 * s).round().max(1.0), ch * 0.76);
        out.push(quad(caret, with_alpha(CLAUDE, op * ctx.cursor_alpha.max(0.25)), NO_CLIP, MODE_SOLID));
    }

    // List.
    let ly = sy + search_h + 10.0 * s;
    let list = Rect::new(x + pad * 0.5, ly, w - pad, visible as f32 * row_h);
    picker.list = list;
    picker.row_h = row_h;
    let clip = [list.x, list.y, list.right(), list.bottom()];

    let hl_y = ly + (picker.highlight - picker.scroll) * row_h;
    out.push(rounded(
        Rect::new(list.x, hl_y, list.w, row_h),
        with_alpha(CLAUDE, 0.12 * op),
        8.0 * s,
        0.0,
        [0.0; 4],
        clip,
    ));
    let bar = Rect::new(list.x + 4.0 * s, hl_y + row_h * 0.28, 3.0 * s, row_h * 0.44);
    out.push(rounded(bar, with_alpha(CLAUDE, op), 1.5 * s, 0.0, [0.0; 4], clip));

    let first = picker.scroll.floor().max(0.0) as usize;
    let text_x = list.x + 16.0 * s;
    let right = list.right() - 14.0 * s;
    for row in first..(first + visible + 1).min(rows) {
        let ry = ly + (row as f32 - picker.scroll) * row_h;
        let ty = (ry + (row_h - ch) * 0.5).round();
        let selected = row == picker.selected;
        if row == 0 {
            let c = if selected { with_alpha(CLAUDE, op) } else { with_alpha(mix(CLAUDE, card_bg, 0.25), op) };
            text(ctx, out, text_x, ty, "+  New session", c, STYLE_BOLD, right - text_x, clip);
            let hint = "fresh start";
            let hw = hint.chars().count() as f32 * cw;
            text(ctx, out, right - hw, ty, hint, muted, 0, hw + 1.0, clip);
            continue;
        }
        let session = &picker.sessions[picker.filtered[row - 1]];
        let meta = if session.branch.is_empty() {
            claude::relative_time(session.modified)
        } else {
            format!("{} · {}", claude::relative_time(session.modified), session.branch)
        };
        let title = session.title.clone();
        let mw = meta.chars().count() as f32 * cw;
        text(ctx, out, right - mw, ty, &meta, muted, 0, mw + 1.0, clip);
        let tc = if selected { fg } else { with_alpha(mix(pal.foreground, card_bg, 0.22), op) };
        text(ctx, out, text_x, ty, &title, tc, 0, (right - mw - cw * 3.0 - text_x).max(0.0), clip);
    }

    // Footer hints.
    let fy = list.bottom() + 10.0 * s;
    let hint = "↑↓ select   enter open   type to filter   esc cancel";
    let hw = (hint.chars().count() as f32 * cw).min(inner_w);
    let hc = with_alpha(mix(pal.foreground, card_bg, 0.68), op);
    text(ctx, out, x + (w - hw) * 0.5, fy, hint, hc, 0, inner_w, NO_CLIP);
}