Redot-Engine / redot-proposals

Redot Improvement Proposals
MIT License
33 stars 8 forks source link

Add a Reverse Sort property to BoxContainer #27

Open Kazox61 opened 1 month ago

Kazox61 commented 1 month ago

Describe the project you are working on

A card game where you need to select and scroll throw many card slots

Describe the problem or limitation you are having in your project

I want a way that my card slots can overlap each other when activated and that the upper card slot in the scene tree takes the input event.

https://github.com/user-attachments/assets/ed2441da-a876-41a7-a9df-a756e990562b

Describe the feature / enhancement and how it helps to overcome the problem or limitation

A way to fix this would be having a boolean that sorts the items in reverse, same as in css flex-direction row-reverse. This way you can have the upper item in the screen to be lower in the scene tree, so the input events will trigger in the different order.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Having a boolean named sort_reverse available in the editor

void BoxContainer::_resort() {
    ...

    for (int i = 0; i < get_child_count(); i++) {
        int index = i;
        if (sort_reverse) {
             index = get_child_count() - 1 - i;
        }
        Control *c = as_sortable_control(index);
    }
}

If this enhancement will not be used often, can it be worked around with a few lines of script?

This can not be worked around, the only way i achieved it was writing the same logic for the BoxContainer in GDScript and adding the logic of the reverse sorting

Is there a reason why this should be core and not an add-on in the asset library?

This should be directly integrated in the BoxContainer Node

jovantanyk commented 1 month ago

Seems like a good change to me, I'm curious why this isn't a thing yet