Skip to content
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

Implement new grid widget #190

Merged
merged 4 commits into from
Oct 12, 2023
Merged

Conversation

avsaase
Copy link
Contributor

@avsaase avsaase commented Oct 11, 2023

As discussed on Discord, this PR replaces the grid widget with a new one with more layout options. The updated example shows the layout options and their effect.

2023-10-11_20-49-59.mp4

I think this is an improvement over the previous implementation but it but the API is geared towards a fixed number of elements per row and thus it does not support a variable number of columns and dynamically wrapping around cells to the next row.

Some limitations:

  • This does not play nice with widgets that try to fill up all available space. For example, when you add a iced_widget::Row with .width(Length::Fill) to the grid, it will push the grid partially out of the window. I'm not sure how to fix this. I believe the previous version also didn't account for this.
  • There's no option to let the grid itself fill the remaining space by widening the columns like in iced_widget::Row. I wanted to add this but it requires a new layout algorithm to account for all the edge cases so for now I kept it simple.

Copy link
Collaborator

@genusistimelord genusistimelord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. just need to let clippy and fmt check it and once that passes ill merge it in.

@genusistimelord
Copy link
Collaborator

for the Width::Fill I think in order for it to work you need to send the Exact size of the box its trying to fill to the Element to get the Elements correct size and layout created.

@avsaase
Copy link
Contributor Author

avsaase commented Oct 11, 2023

for the Width::Fill I think in order for it to work you need to send the Exact size of the box its trying to fill to the Element to get the Elements correct size and layout created.

But how can I get the size of the box that a child widget wants to fill? I don't fully understand how the layout engine works when widgets try to take more space than the minimum size.

@avsaase
Copy link
Contributor Author

avsaase commented Oct 11, 2023

Sorry, last commit. I found a fix for the issue where the grid gets pushed around when a child has a Fill width.

@genusistimelord
Copy link
Collaborator

that would probably be a hector question on how is the best way to get the Current boxes size so inside each rows box you can then know what it can be and send that to the element so it cant grow bigger. As even I struggle with the Layout stuff.

@genusistimelord
Copy link
Collaborator

for the Width::Fill I think in order for it to work you need to send the Exact size of the box its trying to fill to the Element to get the Elements correct size and layout created.

But how can I get the size of the box that a child widget wants to fill? I don't fully understand how the layout engine works when widgets try to take more space than the minimum size.

you don't get the inner elements sizes you get the outer elements, So if you know the size of each Column in a row you send that to the element to tell the element they can not go past this size. generally we should be able to get this size. but that would be a Hector question on discord or his forum board. IF you want me to leave this PR open for a little bit let me know, otherwise I will merge this and whatever new changes can be PR'd later.

@avsaase
Copy link
Contributor Author

avsaase commented Oct 12, 2023

I think this can be merged. I need to learn more about the layout algorithm before making more changes.

@genusistimelord genusistimelord merged commit 7b765d9 into iced-rs:main Oct 12, 2023
2 checks passed
@avsaase avsaase deleted the feat/improved-grid branch October 12, 2023 11:51
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