Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required strength on edit variable #2

Open
hansihe opened this issue May 25, 2017 · 1 comment
Open

Required strength on edit variable #2

hansihe opened this issue May 25, 2017 · 1 comment

Comments

@hansihe
Copy link

hansihe commented May 25, 2017

I am using edit variables to add variables that represent the width and height of the UI viewport. I am thinking these should probably be of REQUIRED strength, but the solver doesn't seem to accept this strength on edit variables.

If the size of the viewport is not required, I think I might sometimes get strange results where the solver decides to change the viewport size. This isn't supposed to happen. Do you have any ideas what I might do here?

@christolliday
Copy link
Contributor

I had the same issue recently. According to this, (which is for a different implementation, but I assume has the same limitations), edit variables can't be used in checking satisfiability, they can only be a suggestion. This seems to hold for every cassowary implementation I've looked at, it's not clear why but it probably makes changing edit variables more efficient by avoiding the cost of checking satisfiability.

Anyway, you have two choices, you can remove and re-add width and height constraints every time the viewport changes, which is the approach suggested here.
Or, do what I'm doing which is just setting the window size strength to REQUIRED - 1.0. This way it will still take priority over every other variable, and only be broken if it conflicts with the REQUIRED constraints, so if you don't always have control over the window size, you won't have to have a satisfiable layout for every possible window size. If you don't do this, and it's possible for your window size to have a size of 0x0, you won't be able to set a REQUIRED size or minimum size for any UI element. Obviously there are trade offs to both, but this seems to work pretty well so far. Better to catch more UnsatisfiableConstraint errors while designing the layout, than have them be possible while resizing your window.

I suppose the best case would be to catch the UnsatisfiableConstraint errors while resizing and prevent the window from resizing, but it might not always be possible or easy depending on what your viewport is, if it's managed by a window manager for instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants