Skip to content

Added size hinting implementation in UIGridLayout#1478

Merged
eruvanos merged 4 commits intopythonarcade:gui/grid_layoutfrom
Ibrahim2750mi:grid_layout
Jan 29, 2023
Merged

Added size hinting implementation in UIGridLayout#1478
eruvanos merged 4 commits intopythonarcade:gui/grid_layoutfrom
Ibrahim2750mi:grid_layout

Conversation

@Ibrahim2750mi
Copy link
Copy Markdown
Contributor

@eruvanos
Copy link
Copy Markdown
Member

Actually, the implementation is not what I expected, but I will check, if I was missing some tests. I thought more into the direction, that the do_layout follows the behaviour from: https://github.com/pythonarcade/arcade/blob/development/doc/programming_guide/gui/concept.rst#uiwidget

UIWidget:

  • size_hint: tuple of two floats, defines how much of the parents space it would like to occupy (range: 0.0-1.0). For maximal vertical and horizontal expansion, define size_hint of 1 for the axis.
  • size_hint_min - tuple of two ints, defines minimal size of the widget. If set, changing the size of a widget to a lower values will use this size instead.
  • size_hint_max - tuple of two ints, defines maximum size of the widget. If set, changing the size of a widget to a higher values will use this size instead.

size_hint, size_hint_min, and size_hint_max are values that are additional information of a widget, but do not effect the widget on its own. :class:UILayout may use these information to place or resize a widget.

UILayout are widgets, which reserve the option to move or resize children. They might respect special properties of a widget like size_hint, size_hint_min, or size_hint_max.

The UILayouts only resize a child widget (x or y axis) if size_hint provides a value for the axis which is not None for the dimension.

@Ibrahim2750mi
Copy link
Copy Markdown
Contributor Author

The UILayouts only resize a child widget (x or y axis) if size_hint provides a value for the axis which is not None for the dimension.

Ah, I will add a check if the widget's size hints are not None before resizing them. Other than that I think it is following the arcade gui concept right?

@Ibrahim2750mi
Copy link
Copy Markdown
Contributor Author

  1. UIGridLayout should cover the content by default and not take more space.
    Which results in the default of size_hint=(0,0) and the requirement, that size_hint_min is always set to the minimal size it requires to cover all children.
  2. If a user wants to use UIGridLayout to place something evenly on the screen, it could be stretched to the full parent size by setting size_hint=(1,1).
    Which should result in more space than required within each cell (ignoring the edge case where the parent is not big enough)
  3. If a user wants to define the size of the UIGridLayout, setting the size_hint=None should fix the UIGridLayout to the current size. (This is respected in other UILayouts). So the resize function or setting the rect directly can be used to set the size.
    (Ignoring again the edge case, that the size might not be big enough for the children) This is basically a special case of 2.
    Maybe constructor args (width, height) would not be a bad idea? Not sure.
    How to deal with children size hints.
    size_hint = None means the same like size_hint=(None, None) which states that the widget should not be resized in any dimension.
    This always applies only to the axis: size_hint=(1, None) would mean, grow the child to maximal available width, but do not touch the height at all.
    If the size_hint for an axis is 0, it should be shrunk to 0 or to the given size_hint_min value for the axis. The other way around with size_hint_max as the maximal growth value.
    The UIGridLayout size_hint_min[0] should be the sum of:
  • (child.size_hint_min[0] or 0) if child has size_hint[0] or
  • child.width
    Same applies to size_hint_min[1] referring the child's height.
    Combining this with the cases from above:
    Children are allowed to take grow within the bounds of their cell. E.g:
  • size_hint[0]==0.5 -> half of the available cell width
  • size_hint[0]==1 -> full available cell width

New changes in the code for size hinting is according to this text.

@eruvanos
Copy link
Copy Markdown
Member

Great work, thank you!

@eruvanos eruvanos merged commit 04f624d into pythonarcade:gui/grid_layout Jan 29, 2023
eruvanos pushed a commit that referenced this pull request Jan 29, 2023
* added resizing in UIGridLayout
* resizing child widgets iff they have non None size hints
* Implemented actual size hinting in UIGridLayout
* Edited tests for size hinting
eruvanos added a commit that referenced this pull request Jan 30, 2023
* UI: add tests for UIGridLayout to change size of children
* UI: improve layout documentation
* UI: Added size hinting implementation in UIGridLayout (#1478)

Co-authored-by: Mohammad Ibrahim <74553450+Ibrahim2750mi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants