Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions crates/csv_preview/src/csv_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::{

use crate::table_data_engine::TableDataEngine;
use ui::{
AbsoluteLength, DefiniteLength, RedistributableColumnsState, SharedString,
TableInteractionState, TableResizeBehavior, prelude::*,
AbsoluteLength, ResizableColumnsState, SharedString, TableInteractionState,
TableResizeBehavior, prelude::*,
};
use workspace::{Item, SplitDirection, Workspace};

Expand Down Expand Up @@ -56,27 +56,25 @@ pub fn init(cx: &mut App) {

impl CsvPreviewView {
pub(crate) fn sync_column_widths(&self, cx: &mut Context<Self>) {
// plus 1 for the rows column
// plus 1 for the row identifier column
let cols = self.engine.contents.headers.cols() + 1;
let remaining_col_number = cols.saturating_sub(1);
let fraction = if remaining_col_number > 0 {
1. / remaining_col_number as f32
} else {
1.
};
let mut widths = vec![DefiniteLength::Fraction(fraction); cols];
let line_number_width = self.calculate_row_identifier_column_width();
widths[0] = DefiniteLength::Absolute(AbsoluteLength::Pixels(line_number_width.into()));

let mut widths: Vec<AbsoluteLength> = vec![AbsoluteLength::Pixels(px(150.)); cols];
widths[0] = AbsoluteLength::Pixels(px(line_number_width));

let mut resize_behaviors = vec![TableResizeBehavior::Resizable; cols];
resize_behaviors[0] = TableResizeBehavior::None;

self.column_widths.widths.update(cx, |state, _cx| {
if state.cols() != cols
|| state.initial_widths().as_slice() != widths.as_slice()
|| state.resize_behavior().as_slice() != resize_behaviors.as_slice()
{
*state = RedistributableColumnsState::new(cols, widths, resize_behaviors);
if state.cols() != cols {
*state = ResizableColumnsState::new(cols, widths, resize_behaviors);
} else {
state.set_column_configuration(
0,
AbsoluteLength::Pixels(px(line_number_width)),
TableResizeBehavior::None,
);
}
});
}
Expand Down Expand Up @@ -207,7 +205,7 @@ impl CsvPreviewView {

// Update list state with filtered row count
let visible_rows = self.engine.d2d_mapping().visible_row_count();
self.list_state = gpui::ListState::new(visible_rows, ListAlignment::Top, px(1.));
self.list_state = gpui::ListState::new(visible_rows, ListAlignment::Top, px(100.));
}

pub fn resolve_active_item_as_csv_editor(
Expand Down Expand Up @@ -313,16 +311,16 @@ impl PerformanceMetrics {

/// Holds state of column widths for a table component in CSV preview.
pub(crate) struct ColumnWidths {
pub widths: Entity<RedistributableColumnsState>,
pub widths: Entity<ResizableColumnsState>,
}

impl ColumnWidths {
pub(crate) fn new(cx: &mut Context<CsvPreviewView>, cols: usize) -> Self {
Self {
widths: cx.new(|_cx| {
RedistributableColumnsState::new(
ResizableColumnsState::new(
cols,
vec![ui::DefiniteLength::Fraction(1.0 / cols as f32); cols],
vec![AbsoluteLength::Pixels(px(150.)); cols],
vec![ui::TableResizeBehavior::Resizable; cols],
)
}),
Expand Down
12 changes: 5 additions & 7 deletions crates/csv_preview/src/renderer/render_table.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::types::TableCell;
use gpui::{AnyElement, Entity};
use std::ops::Range;
use ui::{
ColumnWidthConfig, RedistributableColumnsState, Table, UncheckedTableRow, div, prelude::*,
};
use ui::{ColumnWidthConfig, ResizableColumnsState, Table, UncheckedTableRow, div, prelude::*};

use crate::{
CsvPreviewView,
Expand All @@ -13,10 +11,10 @@ use crate::{

impl CsvPreviewView {
/// Creates a new table.
/// Column number is derived from the `RedistributableColumnsState` entity.
/// Column number is derived from the `ResizableColumnsState` entity.
pub(crate) fn create_table(
&self,
current_widths: &Entity<RedistributableColumnsState>,
current_widths: &Entity<ResizableColumnsState>,
cx: &mut Context<Self>,
) -> AnyElement {
self.create_table_inner(self.engine.contents.rows.len(), current_widths, cx)
Expand All @@ -25,7 +23,7 @@ impl CsvPreviewView {
fn create_table_inner(
&self,
row_count: usize,
current_widths: &Entity<RedistributableColumnsState>,
current_widths: &Entity<ResizableColumnsState>,
cx: &mut Context<Self>,
) -> AnyElement {
let cols = current_widths.read(cx).cols();
Expand Down Expand Up @@ -54,7 +52,7 @@ impl CsvPreviewView {
Table::new(cols)
.interactable(&self.table_interaction_state)
.striped()
.width_config(ColumnWidthConfig::redistributable(current_widths.clone()))
.width_config(ColumnWidthConfig::Resizable(current_widths.clone()))
.header(headers)
.disable_base_style()
.map(|table| {
Expand Down
8 changes: 4 additions & 4 deletions crates/csv_preview/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#[derive(Default, Clone, Copy)]
pub enum RowRenderMechanism {
/// Default behaviour
#[default]
VariableList,
/// More performance oriented, but all rows are same height
/// More correct for multiline content, but slower.
#[allow(dead_code)] // Will be used when settings ui is added
VariableList,
/// Default behaviour for now while resizable columns are being stabilized.
#[default]
UniformList,
}

Expand Down
3 changes: 2 additions & 1 deletion crates/git_graph/src/git_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2556,7 +2556,8 @@ impl Render for GitGraph {
this.child(self.render_loading_spinner(cx))
})
} else {
let header_resize_info = HeaderResizeInfo::from_state(&self.column_widths, cx);
let header_resize_info =
HeaderResizeInfo::from_redistributable(&self.column_widths, cx);
let header_context = TableRenderContext::for_column_widths(
Some(self.column_widths.read(cx).widths_to_render()),
true,
Expand Down
Loading
Loading