Re: NSStackView basics
Re: NSStackView basics
Prompted by this I took a look at NSStackView.
Documentation is limited to header comments and some WWDC session coverage.
However, the class will be very useful for composing dynamic layouts.
It behaves pretty much like its WPF equivalent StackPanel.
One notable difference is that StackPanel removes child controls from the stack when the child is hidden.
This makes it possible control the stack content by manipulating the child’s visibility binding.
The subclass below does the same for NSStackView.
The subclass observes -hidden for each subview and lays the stack out accordingly.
https://github.com/mugginsoft/TSStackView
WPF also features a simple DockPanel control.
To my mind it should be possible to compose an equivalent using a vertical NSStackView with a horizontal NSStackView loaded into the middle gravity.
Jonathan
On 12 Nov 2013, at 17:28, Tom Harrington <email@hidden> wrote:
> Thanks Ken. I suspected it was something like that but didn't know what to
> do about it. It also hadn't occurred to me that making the text field
> centered didn't necessarily imply anything about the size of the containing
> view. With no constraints on the sizes of contained view, it seems that
> NSStackView scaled one view down to zero size while scaling the other one
> up to fill the itself. Neither choice violates any constraints, though it
> wasn't what I expected.
>
> Adding a fixed height constraint to the subviews makes both visible.
> Likewise, adding other height constraints like setting the equivalent of
> @"V:|-[subview2]-" makes both visible (with different sizes). Looking at
> the demo project, I see now that there are constraints with similar effect,
> which is why it works.
>
>
>
> On Mon, Nov 11, 2013 at 6:29 PM, Ken Ferry <email@hidden> wrote:
>
>>
>> Hi Tom,
>>
>> I think the problem here is that if you have view A containing textField,
>> and textField is centered in A, there's no constraint expressing anything
>> about A's height. A can go to zero height and still have the textField
>> centered within it.
>>
>> If you added something giving a height (or fastened the edges of A to the
>> textField), that'd probably do it.
>>
>> -ken
>>
>> On Fri, Nov 8, 2013 at 5:02 PM, Tom Harrington <email@hidden>wrote:
>>
>>> I'm trying to use NSStackView in what should be the most basic way
>>> possible. I create the stack view and add two subviews. But only one of
>>> them is ever visible.
>>>
>>> I'm creating the stack view in code (in my app delegate, for purposes of a
>>> test project):
>>>
>>> NSStackView *stackView = [NSStackView stackViewWithViews:@
>>> [self.subview1,
>>> self.subview2]];
>>>
>>> stackView.orientation = NSUserInterfaceLayoutOrientationVertical;
>>>
>>> stackView.alignment = NSLayoutAttributeCenterX;
>>>
>>> stackView.spacing = 0;
>>>
>>> [self.window.contentView addSubview:stackView];
>>>
>>> [self.window.contentView addConstraints:[NSLayoutConstraint
>>> constraintsWithVisualFormat:@"H:|-(50)-[stackView]-(50)-|"
>>>
>>>
>>> options:0
>>>
>>>
>>> metrics:nil
>>>
>>>
>>> views:NSDictionaryOfVariableBindings(stackView)]];
>>>
>>> [self.window.contentView addConstraints:[NSLayoutConstraint
>>> constraintsWithVisualFormat:@"V:|-(50)-[stackView]-(50)-|"
>>>
>>>
>>> options:0
>>>
>>>
>>> metrics:nil
>>>
>>>
>>> views:NSDictionaryOfVariableBindings(stackView)]];
>>>
>>> The two subviews subview1 and subview2 are just plain NSViews, each with
>>> an
>>> NSTextField label subview constrained to be in the center.
>>>
>>> At run time, only one subview is visible-- the last one in the array. It's
>>> resized to fill the entire stack view. If I resize the window, the stack
>>> view and the one visible subview also resize, but no window size ever gets
>>> both subviews showing.
>>>
>>> Obviously I'm missing something basic about stack views, but I don't know
>>> what. I've been looking at Apple's InfoBarStackView demo app but haven't
>>> worked out which detail it has that I don't (Apple's demo:
>>>
>>> https://developer.apple.com/library/mac/samplecode/InfoBarStackView/Introduction/Intro.html
>>> )
>>>
>>> --
>>> Tom Harrington
>>> email@hidden
>>> AIM: atomicbird1
>>> _______________________________________________
>>>
>>> Cocoa-dev mailing list (email@hidden)
>>>
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>> This email sent to email@hidden
>>
>>
>>
>
>
> --
> Tom Harrington
> email@hidden
> AIM: atomicbird1
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden