-
Notifications
You must be signed in to change notification settings - Fork 367
Warn when layout width/height is given but size_hint will override it #2834
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
63be4b4
Initial plan
Copilot 570df7a
Add size_hint warnings for GUI layouts when fixed width/height confli…
Copilot 8d06749
Address review feedback: use Ellipsis sentinel, add type hints, use c…
Copilot 306c9b3
Inline Ellipsis sentinel and move warning to UILayout method
Copilot 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| """Tests that layouts warn when explicit width/height conflicts with active size_hint.""" | ||
| import warnings | ||
|
|
||
| import pytest | ||
|
|
||
| from arcade.gui import UIBoxLayout | ||
| from arcade.gui.widgets.layout import UIAnchorLayout, UIGridLayout | ||
|
|
||
|
|
||
| def test_anchor_layout_warns_when_width_given_with_default_size_hint(window): | ||
| """UIAnchorLayout should warn when width is given but size_hint_x is active.""" | ||
| with pytest.warns(UserWarning, match="size_hint_x"): | ||
| UIAnchorLayout(width=500) | ||
|
|
||
|
|
||
| def test_anchor_layout_warns_when_height_given_with_default_size_hint(window): | ||
| """UIAnchorLayout should warn when height is given but size_hint_y is active.""" | ||
| with pytest.warns(UserWarning, match="size_hint_y"): | ||
| UIAnchorLayout(height=500) | ||
|
|
||
|
|
||
| def test_anchor_layout_no_warning_when_size_hint_none(window): | ||
| """UIAnchorLayout should not warn when size_hint=None is explicitly set.""" | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| UIAnchorLayout(width=500, height=500, size_hint=None) | ||
|
|
||
|
|
||
| def test_anchor_layout_no_warning_when_no_explicit_size(window): | ||
| """UIAnchorLayout should not warn when width/height are not explicitly given.""" | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| UIAnchorLayout(size_hint=(1, 1)) | ||
|
|
||
|
|
||
| def test_anchor_layout_no_warning_when_size_hint_x_none(window): | ||
| """UIAnchorLayout should not warn for width when size_hint_x is None.""" | ||
| # No width warning expected (only height warning) | ||
| with pytest.warns(UserWarning, match="size_hint_y"): | ||
| UIAnchorLayout(width=500, height=500, size_hint=(None, 1)) | ||
|
|
||
|
|
||
| def test_anchor_layout_no_warning_when_size_hint_y_none(window): | ||
| """UIAnchorLayout should not warn for height when size_hint_y is None.""" | ||
| # No height warning expected (only width warning) | ||
| with pytest.warns(UserWarning, match="size_hint_x"): | ||
| UIAnchorLayout(width=500, height=500, size_hint=(1, None)) | ||
|
|
||
|
|
||
| def test_box_layout_warns_when_width_given_with_default_size_hint(window): | ||
| """UIBoxLayout should warn when width is given but size_hint_x is active.""" | ||
| with pytest.warns(UserWarning, match="size_hint_x"): | ||
| UIBoxLayout(width=200) | ||
|
|
||
|
|
||
| def test_box_layout_warns_when_height_given_with_default_size_hint(window): | ||
| """UIBoxLayout should warn when height is given but size_hint_y is active.""" | ||
| with pytest.warns(UserWarning, match="size_hint_y"): | ||
| UIBoxLayout(height=200) | ||
|
|
||
|
|
||
| def test_box_layout_no_warning_when_size_hint_none(window): | ||
| """UIBoxLayout should not warn when size_hint=None is explicitly set.""" | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| UIBoxLayout(width=200, height=200, size_hint=None) | ||
|
|
||
|
|
||
| def test_box_layout_no_warning_when_no_explicit_size(window): | ||
| """UIBoxLayout should not warn when width/height are not explicitly given.""" | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| UIBoxLayout(size_hint=(0, 0)) | ||
|
|
||
|
|
||
| def test_grid_layout_warns_when_width_given_with_default_size_hint(window): | ||
| """UIGridLayout should warn when width is given but size_hint_x is active.""" | ||
| with pytest.warns(UserWarning, match="size_hint_x"): | ||
| UIGridLayout(width=200) | ||
|
|
||
|
|
||
| def test_grid_layout_warns_when_height_given_with_default_size_hint(window): | ||
| """UIGridLayout should warn when height is given but size_hint_y is active.""" | ||
| with pytest.warns(UserWarning, match="size_hint_y"): | ||
| UIGridLayout(height=200) | ||
|
|
||
|
|
||
| def test_grid_layout_no_warning_when_size_hint_none(window): | ||
| """UIGridLayout should not warn when size_hint=None is explicitly set.""" | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| UIGridLayout(width=200, height=200, size_hint=None) | ||
|
|
||
|
|
||
| def test_grid_layout_no_warning_when_no_explicit_size(window): | ||
| """UIGridLayout should not warn when width/height are not explicitly given.""" | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| UIGridLayout(size_hint=(0, 0)) | ||
|
|
||
|
|
||
| def test_warning_message_includes_class_name(window): | ||
| """Warning should include the layout class name for clear identification.""" | ||
| with pytest.warns(UserWarning, match="UIBoxLayout"): | ||
| UIBoxLayout(width=200) | ||
|
|
||
| with pytest.warns(UserWarning, match="UIAnchorLayout"): | ||
| UIAnchorLayout(width=200) | ||
|
|
||
| with pytest.warns(UserWarning, match="UIGridLayout"): | ||
| UIGridLayout(width=200) |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.