Repository: zng-ui/zng (language: rust)

Issue:
Window `auto_size` with `min_size` cause incorrect layout for first frame
<!--
Please, make sure:

- The issue happens in the latest crate release or newer (master branch).
- The issue happens after `cargo update`.
-->

I tried this code:

```rust
Window! {
    clear_color = colors::BLACK;
    auto_size = window::AutoSize::CONTENT;
    min_size = (300, 100);
    padding = 10;
    child = Text!("Short message.");
    child_bottom = Stack! {
        direction = StackDirection::start_to_end();
        layout::align = Align::BOTTOM_END;
        spacing = 5;
        children = ui_vec![
            Button! {
                child = Text!("Restart App");
            },
        ]
    }, 10;
}
```

Following these steps:

1 - Run.
2 - Resize to see button jump to BOTTOM_END.

I saw this happen:

First frame on open positions the button for the auto_size if it did not have a larger min_size.

I expected this to happen:

Layout for the actual window size (min_size) on init.


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 59f2e6da1..204633061 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@
 * Add `APP.about`.
 * Fix `AnsiText!` not resetting style.
 * `Markdown!` widget now uses `AnsiText!` for ```console code block.
+* Fix `auto_size` not using the min/max_size constraints.
 
 # 0.3.4
 
diff --git a/crates/zng-ext-window/src/control.rs b/crates/zng-ext-window/src/control.rs
index 4862e736e..a2ab2abcc 100644
--- a/crates/zng-ext-window/src/control.rs
+++ b/crates/zng-ext-window/src/control.rs
@@ -30,8 +30,8 @@ use zng_ext_image::{ImageRenderArgs, ImageSource, ImageVar, Img, IMAGES};
 use zng_layout::{
     context::{LayoutMetrics, LayoutPassId, DIRECTION_VAR, LAYOUT},
     unit::{
-        Dip, DipRect, DipSize, DipToPx, Factor, FactorUnits, Layout1d, Layout2d, Length, Ppi, Px, PxPoint, PxRect, PxSize, PxToDip,
-        PxVector, TimeUnits,
+        Dip, DipRect, DipSize, DipToPx, Factor, FactorUnits, Layout1d, Layout2d, Length, Ppi, Px, PxConstraints, PxPoint, PxRect, PxSize,
+        PxToDip, PxVector, TimeUnits,
     },
 };
 use zng_var::{AnyVar, ReadOnlyArcVar, Var, VarHandle, VarHandles};
@@ -1979,37 +1979,27 @@ impl ContentCtrl {
 
         let auto_size = self.vars.auto_size().get();
 
-        let mut viewport_size = size;
-        if !skip_auto_size {
-            if auto_size.contains(AutoSize::CONTENT_WIDTH) {
-                viewport_size.width = max_size.width;
-            }
-            if auto_size.contains(AutoSize::CONTENT_HEIGHT) {
-                viewport_size.height = max_size.height;
-            }
-        }
-
         self.layout_pass = self.layout_pass.next();
 
         WIDGET.with_context(&mut self.root_ctx, WidgetUpdateMode::Bubble, || {
-            let metrics = LayoutMetrics::new(scale_factor, viewport_size, root_font_size)
+            let metrics = LayoutMetrics::new(scale_factor, size, root_font_size)
                 .with_screen_ppi(screen_ppi)
                 .with_direction(DIRECTION_VAR.get());
             LAYOUT.with_root_context(self.layout_pass, metrics, || {
                 let mut root_cons = LAYOUT.constraints();
                 if !skip_auto_size {
                     if auto_size.contains(AutoSize::CONTENT_WIDTH) {
-                        root_cons = root_cons.with_unbounded_x();
+                        root_cons.x = PxConstraints::new_range(min_size.width, max_size.width);
                     }
                     if auto_size.contains(AutoSize::CONTENT_HEIGHT) {
-                        root_cons = root_cons.with_unbounded_y();
+                        root_cons.y = PxConstraints::new_range(min_size.height, max_size.height);
                     }
                 }
                 let desired_size = LAYOUT.with_constraints(root_cons, || {
                     WidgetLayout::with_root_widget(layout_widgets, |wl| self.root.layout(wl))
                 });
 
-                let mut final_size = viewport_size;
+                let mut final_size = size;
                 if !skip_auto_size {
                     if auto_size.contains(AutoSize::CONTENT_WIDTH) {
                         final_size.width = desired_size.width.max(min_size.width).min(max_size.width);


Test patch: