refactor(ui): use pre-computed layout in GridWidget

Refactor GridWidget and other UI components to use the pre-computed layout from
App instead of re-creating it on every render. This improves performance and
ensures consistency.

- Update GridWidget to take a reference to GridLayout
- Update GridWidget::new and render to use the provided layout
- Update App::cmd_context and other call sites to pass the layout
- Update tests to provide the layout to GridWidget

Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q5_K_XL)
This commit is contained in:
Edward Langley
2026-04-06 23:18:40 -07:00
parent 812760233b
commit e0171c758f

View File

@ -22,6 +22,7 @@ const GROUP_COLLAPSED: &str = "▶";
pub struct GridWidget<'a> {
pub model: &'a Model,
pub layout: &'a GridLayout,
pub mode: &'a AppMode,
pub search_query: &'a str,
pub buffers: &'a std::collections::HashMap<String, String>,
@ -31,6 +32,7 @@ pub struct GridWidget<'a> {
impl<'a> GridWidget<'a> {
pub fn new(
model: &'a Model,
layout: &'a GridLayout,
mode: &'a AppMode,
search_query: &'a str,
buffers: &'a std::collections::HashMap<String, String>,
@ -38,6 +40,7 @@ impl<'a> GridWidget<'a> {
) -> Self {
Self {
model,
layout,
mode,
search_query,
buffers,
@ -47,9 +50,7 @@ impl<'a> GridWidget<'a> {
fn render_grid(&self, area: Rect, buf: &mut Buffer) {
let view = self.model.active_view();
let frozen = self.drill_state.map(|s| s.records.clone());
let layout = GridLayout::with_frozen_records(self.model, view, frozen);
let layout = self.layout;
let (sel_row, sel_col) = view.selected;
let row_offset = view.row_offset;
let col_offset = view.col_offset;
@ -664,7 +665,8 @@ mod tests {
let area = Rect::new(0, 0, width, height);
let mut buf = Buffer::empty(area);
let bufs = std::collections::HashMap::new();
GridWidget::new(model, &AppMode::Normal, "", &bufs, None).render(area, &mut buf);
let layout = GridLayout::new(model, model.active_view());
GridWidget::new(model, &layout, &AppMode::Normal, "", &bufs, None).render(area, &mut buf);
buf
}