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

Form window is not sized properly #3

Open
marcoconti83 opened this issue Mar 1, 2018 · 0 comments
Open

Form window is not sized properly #3

marcoconti83 opened this issue Mar 1, 2018 · 0 comments

Comments

@marcoconti83
Copy link
Owner

marcoconti83 commented Mar 1, 2018

Problem

The goal is to programmatically display a form (a bunch of controls) inside a window, and automatically resize the window to a "sensible" size that is never larger than the screen.

However when opening a form window (FormWindow), the window has a size that does not match the size of the controls in the form and needs to be manually resized by the user.

Expected behaviour

The desired behaviour of the window (FormWindow) is that the window expands to a size that is large enough to include the form controls (minimum size necessary to display all controls), unless that would make the window larger than the screen. In this case, the window should be limited by the screen size, and the form controls will be clipped (inside a scroll view).

How to reproduce

  1. check out the fix/form-window-resizing branch
  2. run carthage bootstrap --platform osx
  3. open XCode and run the EasyDialogExample schema
  4. The app will open an show a window with a button for "Large" or "Small" form. Try both.

Details

The window in FormWindow is composed of three sections:

The three sections are constrained to be on top of each other, in that order, filling the entire window. The relevant part for the purpose of this issue is the stack.

The stack is a NSStackView inside a NSScrollView. The NSStackView holds the form controls. The desired behavior is that the scroll view will grow to adjust to the minimum size necessary to accommodate the stack with no clipping, unless this will make the whole window larger than the screen, i.e. the top (or bottom) of the window is far off the screen and it can not be reached with the mouse.

If this were to happen, the NSScrollView should instead clip the stack view, so that the window is as large as the screen but it does not grow beyond it, and the user can scroll to visit the entire stack.

Attempted solution

Set the scroll size min and max

scroll.height <= stack.height
scroll.height >= 300

Why it doesn't work: the scroll size is always the minimum one. I need to manually resize the window after it's displayed.

Set the scroll size to be the stack size

scroll.height == stack.height

Why it doesn't work: the window is always as large as needed to display the form. This works as long as the stack plus the rest of the window is smaller than the screen. However it will make the window larger than the screen.

Modify the scroll view intrinsicContentSize

I subclassed NSStackView to return an intrinsic content size which is equal to the size of the documentView. However, the intrinsic size property is accessed before performing the layout, so the intrinsic content size of the subview at that moment is (-1,-1).

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

No branches or pull requests

1 participant