Re: NSButton in NSToolbarItem does not use "small size"
Re: NSButton in NSToolbarItem does not use "small size"
- Subject: Re: NSButton in NSToolbarItem does not use "small size"
- From: Keary Suska <email@hidden>
- Date: Sun, 24 Feb 2013 15:53:45 -0700
On Feb 24, 2013, at 1:11 PM, Michael Starke wrote:
> I'm trying to use a toolbar with NSButtons as the views for the toolbar items. I'm creating the views programmatically and ran into the following problem.
>
> I add a NSSearchField a NSPopupButton and some NSButtons to the bar by creating a NSToolbarItem and using setView: on them with the appropriate controls (search field, popup and normal buttons)
>
> If I add these and check "use small size" the NSButtons do not get scaled down. The search field and the popup button though both do scale up/down correctly. The funny thing is, if I add a NSButton with IB as a custom NSToolbarItem it get's scaled down.
>
> I read that NSToolbarItem uses "setControlSize" to scale the view. So I tried to observe the cell for the keyPath "controlSize" and get notified just for the NSSearchField and the NSPopupButton but the NSButton seems to not get the call.
>
> Do I have to take special care with the buttons? Or did something else break the scaling?
>
> The initializations for the button item is as follows:
>
> NSToolBarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
> NSButton *button = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 32, 32)];
> [button setButtonType:NSMomentaryPushInButton];
> [button setTitle:itemIdentifier];
> [[button cell] setControlSize:NSSmallControlSize];
> [[button cell] setBezelStyle:NSTexturedRoundedBezelStyle];
> [button sizeToFit];
> [item setView:button];
> [button release];
I suspect the issue is that NSButton does not have built-in semantics for control size. In fact, none of the cells in question are documented to respond to -setControlSize is the way you are seeing, but apparently some do. If you consider that a button of any control size can actually be of any size, how would the cell know how to resize itself, other than to just change its font? And if it has an image, how would that work?
Because you can't guarantee KVO compliance for any API object that doesn't explicitly state so the only way to reliably know what is happening is to use your own NSButtonCell subclass (better than a symbolic breakpoint). You might actually find that you will need to handle resizing yourself anyway so your work won't go to waste.
If setControlSize is really not being called on the cell, then it is probably being handled like any regular view, and then you will probably need to specify the min/max sizes.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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