Re: Custom NSButton image effects for pressed/disabled
Re: Custom NSButton image effects for pressed/disabled
- Subject: Re: Custom NSButton image effects for pressed/disabled
- From: Alastair Houghton <email@hidden>
- Date: Thu, 13 Dec 2018 08:37:21 +0000
On 12 Dec 2018, at 01:03, Lars C. Hassing <email@hidden> wrote:
>
> If I assign an image to an NSButton it is displayed with nice pressed and
> disabled effects.
>
> In my custom NSButton, that should display image1+title+image2, I override
> drawRect:, but how do I obtain the EXACT SAME system effects for the two
> images?
Override -drawRect: to call the cell’s -drawWithFrame:inRect: *twice*, once
with the cell’s image set to image1 and the alignment set to left, and once
with the cell’s image set to image2 and the alignment set to right, making sure
to clip appropriately so it only draws the portions you want. Obviously your
custom button is going to have its own “image1” and “image2” properties, right,
so you don’t care that the “image” property is all over the place :-)
e.g. on the first call, draw this:
................
.+---+ .
.| 1 | Title .
.+---+ .
................
Then on the second call, add this part:
.......
+---+ .+---+.
| 1 | Title .| 2 |.
+---+ .+---+.
.......
Do note that if you take this approach, you’re relying on controls being
NSCell-based. At some point in the future, I think that’s likely to change, at
which point you might need to do something else.
It’s also conceivable that this might work better on current versions of the
macOS if you made a custom NSButtonCell subclass and did the clipping and two
calls in that. Why? Because various controls currently try to detect whether
they’re using a custom cell or not and use different rendering code if they are
not…
> I am looking for system functions to produce the SAME look and feel as Cocoa
> controls.
>
> Motif, Windows and Carbon all have system functions to draw control parts in
> various states
> to help developers achieve a consistent look and feel, why wouldn’t Cocoa be
> interested in supporting that?
Cocoa does in fact have this kind of functionality internally, but it’s
currently SPI rather than API. I’m not sure whether Apple intends to expose the
theme support at some time in the future.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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