Skip to content

Commit

Permalink
Rename render_width as get_render_width.
Browse files Browse the repository at this point in the history
Related review comment: #3443 (comment)
  • Loading branch information
rodrigogiraoserrao committed Oct 2, 2023
1 parent ab4da8e commit b84334c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
32 changes: 16 additions & 16 deletions src/textual/widgets/_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Column:
content_width: int = 0
auto_width: bool = False

def render_width(self, data_table: DataTable[Any]) -> int:
def get_render_width(self, data_table: DataTable[Any]) -> int:
"""Width, in cells, required to render the column with padding included.
Args:
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def watch_show_header(self, show: bool) -> None:

def watch_show_row_labels(self, show: bool) -> None:
width, height = self.virtual_size
column_width = self._label_column.render_width(self)
column_width = self._label_column.get_render_width(self)
width_change = column_width if show else -column_width
self.virtual_size = Size(width + width_change, height)
self._scroll_cursor_into_view()
Expand Down Expand Up @@ -1206,7 +1206,7 @@ def _highlight_cursor(self) -> None:
def _row_label_column_width(self) -> int:
"""The render width of the column containing row labels"""
return (
self._label_column.render_width(self)
self._label_column.get_render_width(self)
if self._should_render_row_labels
else 0
)
Expand Down Expand Up @@ -1304,7 +1304,7 @@ def _update_dimensions(self, new_rows: Iterable[RowKey]) -> None:
row_index,
column_index,
style,
column.render_width(self),
column.get_render_width(self),
cursor=should_highlight(
cursor_location, cell_location, cursor_type
),
Expand All @@ -1314,7 +1314,7 @@ def _update_dimensions(self, new_rows: Iterable[RowKey]) -> None:
)
cell_height = len(rendered_cell)
rendered_cells.append(
(rendered_cell, cell_height, column.render_width(self))
(rendered_cell, cell_height, column.get_render_width(self))
)
height = max(height, cell_height)

Expand All @@ -1332,7 +1332,7 @@ def _update_dimensions(self, new_rows: Iterable[RowKey]) -> None:
)

data_cells_width = sum(
column.render_width(self) for column in self.columns.values()
column.get_render_width(self) for column in self.columns.values()
)
total_width = data_cells_width + self._row_label_column_width
header_height = self.header_height if self.show_header else 0
Expand All @@ -1354,13 +1354,13 @@ def _get_cell_region(self, coordinate: Coordinate) -> Region:
# plus the width of the render width of the longest row label.
x = (
sum(
column.render_width(self)
column.get_render_width(self)
for column in self.ordered_columns[:column_index]
)
+ self._row_label_column_width
)
column_key = self._column_locations.get_key(column_index)
width = self.columns[column_key].render_width(self)
width = self.columns[column_key].get_render_width(self)
height = row.height
y = sum(ordered_row.height for ordered_row in self.ordered_rows[:row_index])
if self.show_header:
Expand All @@ -1377,7 +1377,7 @@ def _get_row_region(self, row_index: int) -> Region:
row_key = self._row_locations.get_key(row_index)
row = rows[row_key]
row_width = (
sum(column.render_width(self) for column in self.columns.values())
sum(column.get_render_width(self) for column in self.columns.values())
+ self._row_label_column_width
)
y = sum(ordered_row.height for ordered_row in self.ordered_rows[:row_index])
Expand All @@ -1394,13 +1394,13 @@ def _get_column_region(self, column_index: int) -> Region:
columns = self.columns
x = (
sum(
column.render_width(self)
column.get_render_width(self)
for column in self.ordered_columns[:column_index]
)
+ self._row_label_column_width
)
column_key = self._column_locations.get_key(column_index)
width = columns[column_key].render_width(self)
width = columns[column_key].get_render_width(self)
header_height = self.header_height if self.show_header else 0
height = self._total_row_height + header_height
full_column_region = Region(x, 0, width, height)
Expand Down Expand Up @@ -2083,7 +2083,7 @@ def _render_line_in_row(
row_index,
column_index,
fixed_style,
column.render_width(self),
column.get_render_width(self),
cursor=should_highlight(
cursor_location, cell_location, cursor_type
),
Expand All @@ -2100,7 +2100,7 @@ def _render_line_in_row(
row_index,
column_index,
row_style,
column.render_width(self),
column.get_render_width(self),
cursor=should_highlight(cursor_location, cell_location, cursor_type),
hover=should_highlight(hover_location, cell_location, cursor_type),
)[line_no]
Expand All @@ -2110,7 +2110,7 @@ def _render_line_in_row(
widget_width = self.size.width
table_width = (
sum(
column.render_width(self)
column.get_render_width(self)
for column in self.ordered_columns[self.fixed_columns :]
)
+ self._row_label_column_width
Expand Down Expand Up @@ -2194,7 +2194,7 @@ def _render_line(self, y: int, x1: int, x2: int, base_style: Style) -> Strip:
hover_location=self.hover_coordinate,
)
fixed_width = sum(
column.render_width(self)
column.get_render_width(self)
for column in self.ordered_columns[: self.fixed_columns]
)

Expand Down Expand Up @@ -2314,7 +2314,7 @@ def _get_fixed_offset(self) -> Spacing:
top += sum(row.height for row in self.ordered_rows[: self.fixed_rows])
left = (
sum(
column.render_width(self)
column.get_render_width(self)
for column in self.ordered_columns[: self.fixed_columns]
)
+ self._row_label_column_width
Expand Down
12 changes: 6 additions & 6 deletions tests/test_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ async def test_add_column_with_width():
assert table.get_cell(row, column) == "123"
assert table.columns[column].width == 10
assert (
table.columns[column].render_width(table)
table.columns[column].get_render_width(table)
== 10 + 2 * _DEFAULT_CELL_X_PADDING
)

Expand Down Expand Up @@ -694,7 +694,7 @@ async def test_update_cell_at_column_width(label, new_value, new_content_width):
await wait_for_idle()
assert first_column.content_width == new_content_width
assert (
first_column.render_width(table)
first_column.get_render_width(table)
== new_content_width + 2 * _DEFAULT_CELL_X_PADDING
)

Expand Down Expand Up @@ -1202,21 +1202,21 @@ async def test_add_row_expands_column_widths():
table.add_column("Second", width=10)
await pilot.pause()
assert (
table.ordered_columns[0].render_width(table)
table.ordered_columns[0].get_render_width(table)
== 5 + 2 * _DEFAULT_CELL_X_PADDING
)
assert (
table.ordered_columns[1].render_width(table)
table.ordered_columns[1].get_render_width(table)
== 10 + 2 * _DEFAULT_CELL_X_PADDING
)

table.add_row("a" * 20, "a" * 20)
await pilot.pause()
assert (
table.ordered_columns[0].render_width(table)
table.ordered_columns[0].get_render_width(table)
== 20 + 2 * _DEFAULT_CELL_X_PADDING
)
assert (
table.ordered_columns[1].render_width(table)
table.ordered_columns[1].get_render_width(table)
== 10 + 2 * _DEFAULT_CELL_X_PADDING
)

0 comments on commit b84334c

Please sign in to comment.