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

Added possibility to sort widgets. #141

Merged
merged 1 commit into from
Aug 18, 2020
Merged

Added possibility to sort widgets. #141

merged 1 commit into from
Aug 18, 2020

Conversation

1aam2am1
Copy link
Contributor

Added possibility to sort Container::m_widgets by std::sort and user lambda compare function to further enable moving widgets.

In example now can I sort layers of widgets and change what should be first displayed in one command and not by calling moveWidgetForward or moveWidgetBackward

@texus
Copy link
Owner

texus commented Aug 17, 2020

What use case do you have for this?
Layers of widgets could be created by putting them into Groups, then you just have to move the group forward or backwards.

@1aam2am1
Copy link
Contributor Author

Yes but I can have many groups of widgets say 5. Now to create sixst and place it in say 3 place I need place it and move widget 3 times.
But I don't know in what place I need to place my new group with example z-order 128. I need to place it then check all widgets (get name from them) and remember with z-order was will be and what to move up or down.(sort them) Or copy vector of widgets clear widgets then sort my vector and add it to gui one more time.
In this way I can change order and sort my container based on different things.

@texus
Copy link
Owner

texus commented Aug 18, 2020

I'm still not really convinced that a sort function is really the best way to handle this.

Based on the first part that you said, about creating a sixth group and moving it to place 3, I would suggest adding a function that moves a widget to an absolute position in the list (as opposed to requiting you to call a function multiple times that only moves it one spot each time). This function was considered but ultimately not added because I couldn't figure out whether the index that you pass to such function should be the index before or after the widget is removed from the list.

The index in the list is currently the z-order. I do understand that some people might want to use a custom z-order and let the container automatically order the widgets based on this custom number. I believe such an implementation would be superior to the sorting, because new widgets could be inserted in the right place instead of having to run a sort on all widgets again.

The sort function does provide full control over the order and thus provides a lot of flexibility, which the Container class currently lacks, so I will merge this. But the sort function might be removed again in the future if I ever implement a better way to specify a z-order (not very likely to happen soon, and now that the sort function exists it would have an even lower priority).

@texus texus merged commit 0c1e1c7 into texus:0.8 Aug 18, 2020
texus pushed a commit that referenced this pull request Aug 21, 2020
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