mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 02:17:35 +03:00
repl: Pad the table rows with a fraction of the line height (#15042)
Compute the final height using the number of rows and the constant fraction. Ensures we don't accidentally overlap lines below table output. <img width="663" alt="image" src="https://github.com/user-attachments/assets/fe24b08d-2271-4dcc-88c7-8702ba4c68b0"> Release Notes: - N/A
This commit is contained in:
parent
4d65f7eea3
commit
5062bf0b4d
@ -117,6 +117,9 @@ fn cell_content(row: &Value, field: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Declare constant for the padding multiple on the line height
|
||||||
|
const TABLE_Y_PADDING_MULTIPLE: f32 = 0.5;
|
||||||
|
|
||||||
impl TableView {
|
impl TableView {
|
||||||
pub fn new(table: TabularDataResource, cx: &mut WindowContext) -> Self {
|
pub fn new(table: TabularDataResource, cx: &mut WindowContext) -> Self {
|
||||||
let mut widths = Vec::with_capacity(table.schema.fields.len());
|
let mut widths = Vec::with_capacity(table.schema.fields.len());
|
||||||
@ -170,8 +173,6 @@ impl TableView {
|
|||||||
None => return div().into_any_element(),
|
None => return div().into_any_element(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo!(): compute the width of each column by finding the widest cell in each column
|
|
||||||
|
|
||||||
let mut headings = serde_json::Map::new();
|
let mut headings = serde_json::Map::new();
|
||||||
for field in &self.table.schema.fields {
|
for field in &self.table.schema.fields {
|
||||||
headings.insert(field.name.clone(), Value::String(field.name.clone()));
|
headings.insert(field.name.clone(), Value::String(field.name.clone()));
|
||||||
@ -200,6 +201,8 @@ impl TableView {
|
|||||||
) -> AnyElement {
|
) -> AnyElement {
|
||||||
let theme = cx.theme();
|
let theme = cx.theme();
|
||||||
|
|
||||||
|
let line_height = cx.line_height();
|
||||||
|
|
||||||
let row_cells = schema
|
let row_cells = schema
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
@ -227,11 +230,11 @@ impl TableView {
|
|||||||
.w(*width + px(22.))
|
.w(*width + px(22.))
|
||||||
.child(value)
|
.child(value)
|
||||||
.px_2()
|
.px_2()
|
||||||
.py_1()
|
.py((TABLE_Y_PADDING_MULTIPLE / 2.0) * line_height)
|
||||||
.border_color(theme.colors().border);
|
.border_color(theme.colors().border);
|
||||||
|
|
||||||
if is_header {
|
if is_header {
|
||||||
cell = cell.border_2().bg(theme.colors().border_focused)
|
cell = cell.border_1().bg(theme.colors().border_focused)
|
||||||
} else {
|
} else {
|
||||||
cell = cell.border_1()
|
cell = cell.border_1()
|
||||||
}
|
}
|
||||||
@ -255,16 +258,15 @@ impl TableView {
|
|||||||
impl LineHeight for TableView {
|
impl LineHeight for TableView {
|
||||||
fn num_lines(&self, _cx: &mut WindowContext) -> u8 {
|
fn num_lines(&self, _cx: &mut WindowContext) -> u8 {
|
||||||
let num_rows = match &self.table.data {
|
let num_rows = match &self.table.data {
|
||||||
Some(data) => data.len(),
|
// Rows + header
|
||||||
// We don't support Path based data sources
|
Some(data) => data.len() + 1,
|
||||||
None => 0,
|
// We don't support Path based data sources, however we
|
||||||
|
// still render the header and padding
|
||||||
|
None => 1 + 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Given that each cell has both `py_1` and a border, we have to estimate
|
let num_lines = num_rows as f32 * (1.0 + TABLE_Y_PADDING_MULTIPLE) + 1.0;
|
||||||
// a reasonable size to add on, then round up.
|
num_lines.ceil() as u8
|
||||||
let row_heights = (num_rows as f32 * 1.2) + 1.0;
|
|
||||||
|
|
||||||
(row_heights as u8).saturating_add(2) // Header + spacing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user