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.56k stars 604 forks source link

The Button doesn't respects the `horizontal-stretch` property #3037

Closed ricvelozo closed 9 months ago

ricvelozo commented 1 year ago

The Button doesn't respects the horizontal-stretch property when there is a bigger sibling, like that Label:

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

export global App {
    pure callback quit();
}

export component Counter inherits Window {
    title: "Contador";
    out property <int> count: 5;
    states [
        counting when count > 1: { label.text: "Encerra em \{count} cliques."; }
        ending when count == 1: { label.text: "Encerra no próximo clique!"; }
    ]

    HorizontalBox {
        alignment: center; // Same as `stretch` in this case
        VerticalBox {
            alignment: center;
            label := Text { font-size: 18px; }
            Button {
                horizontal-stretch: 0; // Shouldn't stretch, but does
                text: "Fechar";
                primary: true;
                clicked => {
                    root.count -= 1;
                    if (root.count == 0) {
                        App.quit();
                    }
                }
            }
        }
    }
}

Using Fedora 38, GNOME 44/X11. The Cargo.toml:

[dependencies.slint]
version = "1.1"
default-features = false
features = ["compat-1-0", "std", "backend-winit", "renderer-winit-femtovg"]

[build-dependencies]
slint-build = "1.1"
ogoffart commented 1 year ago

Thanks for filling an issue. Maybe the documentation should be improved. Or possibly more flag should be added to the layouts.

The layout always stretch the widgets in the orthogonal direction.

So to do what you try to achieve, you need to add another HorizontalLayout: example

ogoffart commented 9 months ago

Duplicate of https://github.com/slint-ui/slint/issues/2587