linebender / druid

A data-first Rust-native UI design toolkit.
https://linebender.org/druid/
Apache License 2.0
9.5k stars 566 forks source link

Add debug warnings for layout gotchas #685

Open futurepaul opened 4 years ago

futurepaul commented 4 years ago

There are some layouts that are expressible in our system, but nonsensical, that we want to watch out for. When we can we'd like to log a warning, and if possible fix the API to make nonsensical layouts harder or impossible to layout. But warnings are a good first step.

Here are a few:

  1. A "minimum" constraint of infinity makes no sense.
  2. A child returning infinity as its size makes no sense (infinity should only be passed down to children, never bubbled back up). I believe this can currently happen with a flexible widget inside an align widget, for instance.
  3. As far as I know, passing an infinite width to an align widget that's trying to center horizontally makes no sense, and same for height / vertical. However, an align widget could center something in one axis and still be fine with max infinity in the other — centering in a vertical scroll comes to mind.
  4. If you try to "expand" a SizedBox inside of infinity that should be bad.

When possible, warnings can be added to the BoxConstraints method debug_check. constrain might also be a good spot. Not sure if that will work for all of these.

If you know of any other gotchas please add them!

PoignardAzur commented 3 years ago

Are there still gotchas that aren't addressed?