-
-
Notifications
You must be signed in to change notification settings - Fork 798
Column data styles for Table and Tree widgets
#4258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
corranwebster
wants to merge
18
commits into
beeware:main
Choose a base branch
from
corranwebster:column-data-styles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
85c9f69
Add text and background color support; cocoa implementation.
corranwebster d31f06e
Merge branch 'main' into column-data-styles
corranwebster e94763b
Add color support for Qt backend.
corranwebster 44d6354
Add support for colors in Android.
corranwebster ac4cbda
Update changelog.
corranwebster 516eab3
Skip tree tests on backends where it is not implemented.
corranwebster 345a687
Android tables support colors.
corranwebster dca8ed1
Add support for text_align on columns in Cocoa, Qt and Android
corranwebster afea442
Fix Qt table and tree probes.
corranwebster a2f5419
Add data-driven font support for columns on Cocoa, Qt and Android.
corranwebster 7391694
Change font() method to take default font, rather than widget.
corranwebster 20bac9d
Add fast path if no font styling used.
corranwebster 36f47cd
Revert "Add fast path if no font styling used."
corranwebster bf0e8da
Don't cover case where font is None.
corranwebster feeb174
Don't store implementation on Model in Qt; handle changes to font in Qt.
corranwebster b6b5c55
Fix Android font logic.
corranwebster 2bdcbed
Don't mess with font size - its a macOS Qt issue.
corranwebster 146c02f
Add documentation about the new column methods.
corranwebster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| The `Table` and `Tree` widgets on Cocoa and Qt, and the `Table` widget on Android, can now specify colors, fonts and text alignment to use for individual cells based on the data contained in the cell by writing an appropriate `Column` subclass. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,10 @@ | |
| NSTableView, | ||
| NSTableViewAnimation, | ||
| NSTableViewColumnAutoresizingStyle, | ||
| NSTextAlignment, | ||
| ) | ||
|
|
||
| from ..colors import native_color | ||
| from .base import Widget | ||
| from .internal.cells import TogaIconView | ||
|
|
||
|
|
@@ -43,6 +45,10 @@ def tableView_viewForTableColumn_row_(self, table, column, row: int): | |
|
|
||
| icon = column.toga_column.icon(data_row) | ||
| text = column.toga_column.text(data_row, self.interface.missing_value) | ||
| text_align = column.toga_column.text_align(data_row) | ||
| color = column.toga_column.color(data_row) | ||
| background_color = column.toga_column.background_color(data_row) | ||
| font = column.toga_column.font(data_row, self.interface.style.font) | ||
|
|
||
| # creates a NSTableCellView from interface-builder template (does not exist) | ||
| # or reuses an existing view which is currently not needed for painting | ||
|
|
@@ -60,6 +66,26 @@ def tableView_viewForTableColumn_row_(self, table, column, row: int): | |
| else: | ||
| tcv.setImage(None) | ||
|
|
||
| if text_align is not None: | ||
| tcv.textField.alignment = NSTextAlignment(text_align) | ||
| else: | ||
| tcv.textField.alignment = self.alignment | ||
|
|
||
| if color is not None: | ||
| tcv.textField.textColor = native_color(color) | ||
| else: | ||
| tcv.textField.textColor = None | ||
| if background_color is not None: | ||
| tcv.drawsBackground = True | ||
| tcv.backgroundColor = native_color(background_color) | ||
| else: | ||
| tcv.textField.drawsBackground = False | ||
|
|
||
| # font is only None if something is very wrong (eg. can't find system font) | ||
| # so can't test | ||
| if font is not None: # pragma: no branch | ||
| tcv.textField.font = font._impl.native | ||
|
Comment on lines
+69
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This piece of code gets thrown around a lot. Is it possible to have a |
||
|
|
||
| return tcv | ||
|
|
||
| @objc_method | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nit for this to read more smoothly: