Skip to content

Commit

Permalink
Datatable extend background (#1946)
Browse files Browse the repository at this point in the history
* Extending DataTable widget horizontally

* Fading background of extended DataTable rows

* Updating DataTable snapshots

* Update CHANGELOG.md

---------

Co-authored-by: Will McGugan <[email protected]>
  • Loading branch information
darrenburns and willmcgugan authored Mar 6, 2023
1 parent 98cc1a7 commit fd0e0d9
Show file tree
Hide file tree
Showing 3 changed files with 408 additions and 378 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.14.0] - Unreleased

### Changes
### Changed

- Breaking change: There is now only `post_message` to post events, which is non-async, `post_message_no_wait` was dropped. https://github.com/Textualize/textual/pull/1940
- Breaking change: The Timer class now has just one method to stop it, `Timer.stop` which is non sync https://github.com/Textualize/textual/pull/1940
- Breaking change: Messages don't require a `sender` in their constructor https://github.com/Textualize/textual/pull/1940
- Many messages have grown a `control` property which returns the control they relate to. https://github.com/Textualize/textual/pull/1940
- Dropped `time` attribute from Messages https://github.com/Textualize/textual/pull/1940
- Updated styling to make it clear DataTable grows horizontally https://github.com/Textualize/textual/pull/1946
- Changed the `Checkbox` character due to issues with Windows Terminal and Windows 10 https://github.com/Textualize/textual/issues/1934
- Changed the `RadioButton` character due to issues with Windows Terminal and Windows 10 and 11 https://github.com/Textualize/textual/issues/1934

Expand Down
23 changes: 23 additions & 0 deletions src/textual/widgets/_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .._two_way_dict import TwoWayDict
from .._types import SegmentLines
from ..binding import Binding, BindingType
from ..color import Color
from ..coordinate import Coordinate
from ..geometry import Region, Size, Spacing, clamp
from ..message import Message
Expand Down Expand Up @@ -880,6 +881,9 @@ async def on_styles_updated(self) -> None:
self._clear_caches()
self.refresh()

def on_resize(self, event: events.Resize) -> None:
self._update_count += 1

def watch_show_cursor(self, show_cursor: bool) -> None:
self._clear_caches()
if show_cursor and self.cursor_type != "none":
Expand Down Expand Up @@ -1682,6 +1686,25 @@ def _should_highlight(
)[line_no]
scrollable_row.append(cell_lines)

# Extending the styling out horizontally to fill the container
widget_width = self.size.width
table_width = (
sum(
column.render_width
for column in self.ordered_columns[self.fixed_columns :]
)
+ self._row_label_column_width
)
remaining_space = max(0, widget_width - table_width)
background_color = self.background_colors[1]
faded_color = Color.from_rich_color(row_style.bgcolor).blend(
background_color, factor=0.25
)
faded_style = Style.from_color(
color=row_style.color, bgcolor=faded_color.rich_color
)
scrollable_row.append([Segment(" " * remaining_space, faded_style)])

row_pair = (fixed_row, scrollable_row)
self._row_render_cache[cache_key] = row_pair
return row_pair
Expand Down
Loading

0 comments on commit fd0e0d9

Please sign in to comment.