slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.72k stars 615 forks source link

Layouts don't account for elements' `min-...`/`max-...` in non-flow-direction #6289

Open Enyium opened 2 months ago

Enyium commented 2 months ago

Consider this SlintPad demo:

import { Button, VerticalBox, HorizontalBox } from "std-widgets.slint";

export component Demo {
    width: 400px; // Comment out for more strange behavior.

    HorizontalBox {
        // Larger than `max-...`.
        VerticalBox {
            width: 200px;
            alignment: start;

            Rectangle {
                max-width: 50px;
                height: 50px;

                background: @linear-gradient(90deg, red 0%, lime 100%);
            }
            Button {
                max-width: 50px;
                height: 50px;
            }

            HorizontalBox {
                height: 200px;
                alignment: start;

                Rectangle {
                    max-height: 50px;
                    width: 50px;

                    background: @linear-gradient(180deg, red 0%, lime 100%);
                }
                Button {
                    max-height: 50px;
                    width: 50px;
                }
            }
        }

        // Smaller than `min-...`.
        VerticalBox {
            width: 50px;
            alignment: start;

            Rectangle {
                min-width: 200px;
                height: 50px;

                background: @linear-gradient(90deg, red 0%, lime 100%);
            }
            Button {
                min-width: 200px;
                height: 50px;
            }

            HorizontalBox {
                height: 50px;
                alignment: start;

                Rectangle {
                    min-height: 200px;
                    width: 50px;

                    background: @linear-gradient(180deg, red 0%, lime 100%);
                }
                Button {
                    min-height: 200px;
                    width: 50px;
                }
            }
        }
    }
}

stretched-too-much

The question is, of course: What should be the behavior in these cases? Since centering is the default in components on the root level, and overlaps may always happen when improperly defining your Slint code, you could argue that this should also be the case here: Always center. If one doesn't want that, they should wrap it in a layout.

ogoffart commented 2 months ago

The layout's constrain shouldn't allow to be bigger than the max size. But when it is, we should indeed perhaps respect the element's max-size (since we also respect the element's width)