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

Dynamic sized strips, tables, and date picker #963

Merged
merged 87 commits into from
Mar 31, 2022

Conversation

elwerene
Copy link
Contributor

@elwerene elwerene commented Dec 17, 2021

A (dynamic) grid and table layout widget which allows a mixed use of size constraints:

  • Absolute sizing
  • Relative sizing: relative to available size in dimension
  • Remainder: The remaining space is distributed evenly to all cells using Remainder Sizing
  • Relative/Remainder with minimum size

Also contains a date picker button which is based on the dynamic grid.

This is early in development and has definitely lots of bugs and rough edges.

I didn't want to wait longer as I love the results so far and I wanted to show it and open it up for discussion!

TODO

I added many TODO comments in the code which I want as a minimum to get this released, like:

  • Positioning of date picker popup
  • Colors on date picker popup
  • Internationalization/locale of date picker button/popup
  • Padding in table/grid should be worked over/switched to a more egui like approach
  • Is having two extra crates really needed? I developed it in extra grades but would not mind having it integrated into the main crate. I would prefer some integration into egui repository over maintaining external crates.

Screenshots:

@elwerene elwerene marked this pull request as draft December 17, 2021 17:51
@elwerene elwerene changed the title WIP: Dynamic grid Dynamic grid Dec 17, 2021
@elwerene elwerene changed the title Dynamic grid Dynamic grid and date picker Dec 17, 2021
@emilk
Copy link
Owner

emilk commented Dec 21, 2021

This looks amazing 😍

@emilk
Copy link
Owner

emilk commented Dec 27, 2021

There's a lot to review here 😅 The table/grid code could really do with some documentation too, explaining the high level concepts.

Adding two new crates creates a lot of extra work to maintain. However, I have been considering creating a new crate egui_extras for stuff like this - useful widgets built on top of egui. I think both the table and datepicker could fit in there. We could later consider moving the table into egui proper once it has been battle tested and polished.

@elwerene elwerene mentioned this pull request Jan 7, 2022
@kevin406972552
Copy link

Looking forward to it. When will it be available?

@elwerene
Copy link
Contributor Author

elwerene commented Jan 9, 2022

@emilk I reworked most of the grid and table code to be more readable and with less boilerplate. Also I merged both crates into a new crate egui_extras. So maybe you could do another take in reviewing it if you find some time :)

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Very impressive! I think the new dynamic grid could be very useful. I have left a lot of questions though, and have a few more:

What happens if the contents of a cell overflows the width we allocated for it? Everything else in egui expands the parent when this happens (parent window gets wider, etc), and I would like for this to happen here as well, if possible. It is very difficult to know beforehand how much space you need for a widget, so to have the parent layout expand as needed is quite important. This is why egui::Grid keeps a memory of the sizes from previous frames. Of course, this adds a lot of complexity.

We also have a name-clash: egui::Grid and egui_extras::Grid. Can we come up with a another name?

Some other things:

  • Add egui_extras to .github/workflows/rust.yml
  • Add egui_extras to sh/check.sh
  • Please add some labels to explain the grid-demo (just a bunch of rectangles doesn't say much)
  • Add source code links from the grid and table demos

egui_demo_lib/src/apps/demo/table_demo.rs Outdated Show resolved Hide resolved
egui_extras/Cargo.toml Outdated Show resolved Hide resolved
egui_extras/Cargo.toml Outdated Show resolved Hide resolved
egui_extras/src/datepicker/button.rs Outdated Show resolved Hide resolved
egui_extras/src/table.rs Outdated Show resolved Hide resolved
egui_extras/src/table.rs Show resolved Hide resolved
egui_extras/src/table.rs Outdated Show resolved Hide resolved
egui_extras/src/table.rs Outdated Show resolved Hide resolved
egui_extras/src/table.rs Outdated Show resolved Hide resolved
@songlinshu
Copy link

Looking forward to it. When will it be available?

@emilk
Copy link
Owner

emilk commented Mar 31, 2022

I'm pushing new commits to this branch, but they are not showing up in this PR, yet they are showing up in https://github.com/emilk/egui/commits/dynamic-grid

I think GitHub is having another bad day…

@elwerene
Copy link
Contributor Author

elwerene commented Mar 31, 2022

I can see your typo fix

@emilk
Copy link
Owner

emilk commented Mar 31, 2022

But can you see the nine other commits at https://github.com/emilk/egui/commits/dynamic-grid ?

Screen Shot 2022-03-31 at 15 12 35

Do you get them if you git pull?

@emilk
Copy link
Owner

emilk commented Mar 31, 2022

In the meantime: there is a bug where a vertical Strip doesn't get the width of its child elements. This means it is possible to make the table demo window far more narrow than it should be:

Screen Shot 2022-03-31 at 15 14 53

@elwerene
Copy link
Contributor Author

But can you see the nine other commits at https://github.com/emilk/egui/commits/dynamic-grid ?

Screen Shot 2022-03-31 at 15 12 35

Do you get them if you pull?

You are very active! ❤️
I got them by merging your dynamic-grid into mine 🤷

@emilk
Copy link
Owner

emilk commented Mar 31, 2022

Weird that only the first commit got to the shared branch…

@emilk
Copy link
Owner

emilk commented Mar 31, 2022

Do you know what is causing the width-resize bug? Seems like it should be a fairly easy fix (I hope)

@elwerene
Copy link
Contributor Author

Do you know what is causing the width-resize bug? Seems like it should be a fairly easy fix (I hope)

I was just inspecting it, I'm calling ui.allocate_rect for each cell to make them clickable and on the whole Strip/TableHeader/TableBody so the scroll view knows about them. Did something change in that logic?

@emilk
Copy link
Owner

emilk commented Mar 31, 2022

Nothing changed, and also the problem exists in 2ec346e (before any of my commits).

@elwerene
Copy link
Contributor Author

I introduced the error in ae71f91

time to find the bug!

@elwerene
Copy link
Contributor Author

Oh I guess it was me moving the table inside of the grid 🤦

@elwerene
Copy link
Contributor Author

This is a shortcoming of the current implementation. The strip only has one fixed dimension, the other dimension takes whatever there's left. We could add a minimum size here. This could also be added later as an option to the builder. What do you say, @emilk?

@emilk emilk changed the title Dynamic grid and date picker Dynamic sized strips, tables, and date picker Mar 31, 2022
Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Awesome work!

@emilk emilk merged commit 1d32670 into emilk:master Mar 31, 2022
This was referenced Mar 31, 2022
@JulianRuiseco
Copy link

Nice!!

@emilk
Copy link
Owner

emilk commented Dec 5, 2022

@elwerene chrono needs a version bump, but it has a lot of deprecated functions. Would you like to help out?

@elwerene
Copy link
Contributor Author

elwerene commented Dec 5, 2022

@emilk Sure, I'll have a look some time this week :)

@elwerene elwerene mentioned this pull request Dec 6, 2022
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.

None yet

8 participants