christolliday / limn

Experimental cross platform GUI library
Other
404 stars 19 forks source link

Examples initially display with incorrect size #45

Closed tones111 closed 6 years ago

tones111 commented 6 years ago

When running an example application (ex: button) on linux X11 the window is initially drawn with an incorrect size before resizing to the desired dimension. The problem bisects to 563eb538.

The previous implementation was building the WindowBuilder with "with_dimensions" where the new implementation only uses "with_min_dimensions". Adding with_dimensions to the window_buildier created in the example appears to resolve the issue.

Is this something that should be tracked down and fixed within glutin or should the examples specify both dimensions?

Interestingly the window dimensions aren't consistent without specifying the min_dimensions. Some executions shrink down to the size of the button, other times it doesn't shrink the width.

christolliday commented 6 years ago

There are two problems here:

  1. Window resizing as the app starts. This is because I added the feature of auto-sizing the window based on the contents you specify, but the implementation is a little hacky right now. If you set a layout to just contain an image, it should measure the image and automatically set the window size based on that. Unfortunately, some aspects of layout measuring (images and text) currently require a gl context (at least without extra code and overhead), which is normally initialized at the same time as the window, so the current hacky solution is to initialize the window, initialize and measure the layout and then resize the window. The fix I want to make is to create a gl context first, set up the layout then create the window using that context and layout size. I could probably make it work without requiring a gl context, but I think that will add more complexity than it's worth.

    I could just require the user to measure the image and set the window size manually, but you'd be measuring it twice, plus if that's necessary, what's the point in having auto-layout :wink:

  2. Window size not staying consistent across executions. This is caused by having an under constrained layout, so for the button example, currently there is no constraint for what the root or window size should be, only padding around the button, and min_dimensions (for the window, not connected to the layout). So there are multiple correct solutions and the solver will just pick one that works. In this situation you just need to add more constraints, set a default root layout size (or set a window size and remove the auto-sizing feature). The reason for cassowary giving non-deterministic results for under constrained layouts is that HashMap ordering is non-deterministic by default, and adding that requirement would make the solver slower (as far as I know).

For 2. I'll fix this in the examples by adding more constraints, and/or setting "with_dimensions" 1. might take a little while to get to although maybe in the short time I'll remove the auto-sizing feature entirely and always require a window size to be set..

If anyone wants to take a stab at fixing 1. let me know!

christolliday commented 6 years ago

fixed by #61 #62