From 34b2158e00935f91cd929016c238c3ab4522c678 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Sun, 20 Jul 2025 15:50:09 -0700 Subject: [PATCH] Sketch in how the state should interact for resizable columns in the keymap editior --- crates/settings_ui/src/keybindings.rs | 9 ++++-- crates/settings_ui/src/ui_components/table.rs | 31 +++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/crates/settings_ui/src/keybindings.rs b/crates/settings_ui/src/keybindings.rs index 3f14f385912df3dc1f84d88d1c46fa738e430ed7..b28a9a487067757b42e09babb31380d1efa14098 100644 --- a/crates/settings_ui/src/keybindings.rs +++ b/crates/settings_ui/src/keybindings.rs @@ -36,7 +36,7 @@ use workspace::{ use crate::{ keybindings::persistence::KEYBINDING_EDITORS, - ui_components::table::{Table, TableInteractionState}, + ui_components::table::{ColumnWidths, Table, TableInteractionState}, }; const NO_ACTION_ARGUMENTS_TEXT: SharedString = SharedString::new_static(""); @@ -284,6 +284,7 @@ struct KeymapEditor { context_menu: Option<(Entity, Point, Subscription)>, previous_edit: Option, humanized_action_names: HumanizedActionNameCache, + current_widths: Entity>, show_hover_menus: bool, /// In order for the JSON LSP to run in the actions arguments editor, we /// require a backing file In order to avoid issues (primarily log spam) @@ -400,6 +401,7 @@ impl KeymapEditor { show_hover_menus: true, action_args_temp_dir: None, action_args_temp_dir_worktree: None, + current_widths: cx.new(|cx| ColumnWidths::new(cx)), }; this.on_keymap_changed(window, cx); @@ -1434,7 +1436,10 @@ impl Render for KeymapEditor { DefiniteLength::Fraction(0.08), ]) .header(["", "Action", "Arguments", "Keystrokes", "Context", "Source"]) - .resizable_columns([false, true, true, true, true, true]) + .resizable_columns( + [false, true, true, true, true, true], + self.current_widths.clone(), + ) .uniform_list( "keymap-editor-table", row_count, diff --git a/crates/settings_ui/src/ui_components/table.rs b/crates/settings_ui/src/ui_components/table.rs index ceabb038a63e801a98d33d1a0c7fdd36627f018c..7ebbacc7a265f2e0de1cd70d6aa2ca8ac23f8581 100644 --- a/crates/settings_ui/src/ui_components/table.rs +++ b/crates/settings_ui/src/ui_components/table.rs @@ -433,6 +433,18 @@ impl TableInteractionState { } } +pub struct ColumnWidths { + widths: [Pixels; COLS], +} + +impl ColumnWidths { + pub fn new(_: &mut App) -> Self { + Self { + widths: [px(0.0); COLS], + } + } +} + /// A table component #[derive(RegisterComponent, IntoElement)] pub struct Table { @@ -441,7 +453,8 @@ pub struct Table { headers: Option<[AnyElement; COLS]>, rows: TableContents, interaction_state: Option>, - column_widths: Option<[Length; COLS]>, + initial_widths: Option<[Length; COLS]>, + current_widths: Option>>, resizable_columns: Option<[bool; COLS]>, map_row: Option), &mut Window, &mut App) -> AnyElement>>, empty_table_callback: Option AnyElement>>, @@ -456,7 +469,8 @@ impl Table { headers: None, rows: TableContents::Vec(Vec::new()), interaction_state: None, - column_widths: None, + initial_widths: None, + current_widths: None, map_row: None, empty_table_callback: None, resizable_columns: None, @@ -521,12 +535,17 @@ impl Table { } pub fn column_widths(mut self, widths: [impl Into; COLS]) -> Self { - self.column_widths = Some(widths.map(Into::into)); + self.initial_widths = Some(widths.map(Into::into)); self } - pub fn resizable_columns(mut self, resizable: [impl Into; COLS]) -> Self { + pub fn resizable_columns( + mut self, + resizable: [impl Into; COLS], + current_widths: Entity>, + ) -> Self { self.resizable_columns = Some(resizable.map(Into::into)); + self.current_widths = Some(current_widths); self } @@ -648,7 +667,7 @@ impl TableRenderContext { Self { striped: table.striped, total_row_count: table.rows.len(), - column_widths: table.column_widths, + column_widths: table.initial_widths, map_row: table.map_row.clone(), } } @@ -735,7 +754,7 @@ impl RenderOnce for Table { ), }) .when_some( - self.column_widths + self.initial_widths .as_ref() .zip(interaction_state.as_ref()) .zip(self.resizable_columns.as_ref()),