khonsulabs / cushy

An experimental cross-platform graphical user interface (GUI) crate for Rust.
Apache License 2.0
491 stars 25 forks source link

Semantics of exact size vs lower bounded size? #197

Closed bluenote10 closed 1 month ago

bluenote10 commented 1 month ago

Another small example where I'm unsure if this is intended behavior or a minor bug. It is about the usage of an exact size like .width(Px::new(100)) vs a lower bounded size like .width(Px::new(100)..). Consider the following example:

use cushy::animation::ZeroToOne;
use cushy::figures::units::Px;
use cushy::figures::Zero;
use cushy::value::Dynamic;
use cushy::widget::MakeWidget;
use cushy::widgets::progress::Progressable;
use cushy::Run;

fn content() -> impl MakeWidget {
    let progress = Dynamic::new(ZeroToOne::ZERO);
    progress
        .clone()
        .progress_bar()
        .width(Px::new(100)..) // using just `Px::new(100)` works
        .contain()
        .centered()
        .expand()
}

pub fn main() -> cushy::Result<()> {
    content().run()
}

Using an exact size, the widget renders as:

image

Using a lower bounded size, the widget renders as:

image

For some reason, the progress bar got shrunken down to less then the 100 pixels in this case. Intuitively I would have expected that the range syntax would express 100 pixel or more, so I'm a bit surprised that it can shrink now. Interestingly, it still has a width of 100 to the outside (barely visible by the container size) -- only the inner widget seems to have lost its minimum width constraint?

ecton commented 1 month ago

Thank you for reporting this! This looks like it only affected the Slider widget, which is what the progress bar uses under the hood.