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