-
-
Notifications
You must be signed in to change notification settings - Fork 689
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
Add "horizontal" and "vertical" aliases for align_items and justify_content #3113
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 ``align_items`` and ``justify_content`` properties now have the aliases ``horizontal_align_items``, ``vertical_align_items``, ``horizontal_align_content`` and ``vertical_align_content`` that explicitly describe layout behavior in the named direction. |
This file contains 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 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 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,48 @@ | ||
from toga.style.pack import Pack | ||
|
||
|
||
def with_init(**kwargs): | ||
return Pack(**kwargs) | ||
|
||
|
||
def with_update(**kwargs): | ||
style = Pack() | ||
style.update(**kwargs) | ||
return style | ||
|
||
|
||
def with_setattr(**kwargs): | ||
style = Pack() | ||
for name, value in kwargs.items(): | ||
setattr(style, name, value) | ||
return style | ||
|
||
|
||
def with_setitem(**kwargs): | ||
style = Pack() | ||
for name, value in kwargs.items(): | ||
style[name] = value | ||
return style | ||
|
||
|
||
def with_setitem_hyphen(**kwargs): | ||
style = Pack() | ||
for name, value in kwargs.items(): | ||
style[name.replace("_", "-")] = value | ||
return style | ||
|
||
|
||
def getitem(obj, name): | ||
return obj[name] | ||
|
||
|
||
def getitem_hyphen(obj, name): | ||
return obj[name.replace("_", "-")] | ||
|
||
|
||
def delitem(obj, name): | ||
del obj[name] | ||
|
||
|
||
def delitem_hyphen(obj, name): | ||
del obj[name.replace("_", "-")] |
This file contains 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,108 @@ | ||
import pytest | ||
from pytest import raises | ||
|
||
from toga.style.pack import CENTER, COLUMN, END, ROW | ||
|
||
from . import ( | ||
delitem, | ||
delitem_hyphen, | ||
getitem, | ||
getitem_hyphen, | ||
with_init, | ||
with_setattr, | ||
with_setitem, | ||
with_setitem_hyphen, | ||
with_update, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"css_name, row_alias, column_alias, default", | ||
[ | ||
( | ||
"align_items", | ||
"vertical_align_items", | ||
"horizontal_align_items", | ||
None, | ||
), | ||
( | ||
"justify_content", | ||
"horizontal_align_content", | ||
"vertical_align_content", | ||
"start", | ||
), | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"style_with", | ||
(with_init, with_update, with_setattr, with_setitem, with_setitem_hyphen), | ||
) | ||
@pytest.mark.parametrize("get_fn", (getattr, getitem, getitem_hyphen)) | ||
@pytest.mark.parametrize("del_fn", (delattr, delitem, delitem_hyphen)) | ||
def test_align(css_name, row_alias, column_alias, default, style_with, get_fn, del_fn): | ||
"""The `vertical_align` and `horizontal_align` aliases work correctly.""" | ||
# Row alias | ||
style = style_with(**{row_alias: CENTER}) | ||
freakboy3742 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert get_fn(style, css_name) == CENTER | ||
|
||
del_fn(style, row_alias) | ||
assert get_fn(style, css_name) == default | ||
|
||
style = style_with(**{css_name: CENTER}) | ||
freakboy3742 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert get_fn(style, row_alias) == CENTER | ||
|
||
del_fn(style, css_name) | ||
assert get_fn(style, row_alias) == default | ||
|
||
# Column alias | ||
style = style_with(**{"direction": COLUMN, column_alias: CENTER}) | ||
assert get_fn(style, css_name) == CENTER | ||
|
||
del_fn(style, column_alias) | ||
assert get_fn(style, css_name) == default | ||
|
||
style = style_with(**{"direction": COLUMN, css_name: CENTER}) | ||
assert get_fn(style, column_alias) == CENTER | ||
|
||
del_fn(style, css_name) | ||
assert get_fn(style, column_alias) == default | ||
|
||
# Column alias is not accepted in a row, and vice versa. | ||
def assert_invalid_alias(alias, direction): | ||
style = style_with(direction=direction) | ||
raises_kwargs = dict( | ||
expected_exception=AttributeError, | ||
match=f"'{alias}' is not supported on a {direction}", | ||
) | ||
|
||
with raises(**raises_kwargs): | ||
get_fn(style, alias) | ||
with raises(**raises_kwargs): | ||
setattr(style, alias, END) | ||
with raises(**raises_kwargs): | ||
del_fn(style, alias) | ||
with raises(**raises_kwargs): | ||
style.update(**{"direction": direction, alias: END}) | ||
with raises(**raises_kwargs): | ||
style.update(**{alias: END, "direction": direction}) | ||
|
||
assert_invalid_alias(column_alias, ROW) | ||
assert_invalid_alias(row_alias, COLUMN) | ||
|
||
# Consistent values of direction and alias can be updated together, regardless of | ||
# argument order. | ||
style = style_with(direction=COLUMN) | ||
style.update(**{"direction": ROW, row_alias: CENTER}) | ||
assert get_fn(style, row_alias) == CENTER | ||
assert get_fn(style, css_name) == CENTER | ||
style.update(**{column_alias: END, "direction": COLUMN}) | ||
assert get_fn(style, column_alias) == END | ||
assert get_fn(style, css_name) == END | ||
|
||
style = style_with(direction=ROW) | ||
style.update(**{"direction": COLUMN, column_alias: CENTER}) | ||
assert get_fn(style, column_alias) == CENTER | ||
assert get_fn(style, css_name) == CENTER | ||
style.update(**{row_alias: END, "direction": ROW}) | ||
assert get_fn(style, row_alias) == END | ||
assert get_fn(style, css_name) == END |
This file contains 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.
It looks like MicroPython doesn't support the
__init_subclass__
method used by BaseStyle, so this will have to be revisited once we start actually running Travertino on MicroPython rather than simply importing it.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.
Ugh -_-
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.
Actually turns out it's super simple, I can just replace the subclass_init with a pair of properties.