Re: Long delay of NSPopUpButton first click
Re: Long delay of NSPopUpButton first click
- Subject: Re: Long delay of NSPopUpButton first click
- From: "Glenn L. Austin" <email@hidden>
- Date: Tue, 02 Aug 2011 08:13:38 -0700
On Aug 2, 2011, at 6:42 AM, Rimas M. wrote:
> Hello list,
>
> I am trying to do quite simple thing - add a popup with all fonts, available
> on system. Each item of menu, should be displayed in corresponding font. As
> an example could be all iWork apps. When you dealing with text, you have a
> popup with fonts, and each font name is displayed with "preview" of that
> font.
>
> I have tried to do that in very usual way:
> - iterating over available fonts
> - creating a NSMenuItem for each font, setting it up
> - setting menuItem's attributedTitle with corresponding NSFontAttributeName
> - adding menuItem to the popup.
>
> This works as expected, but after app launch, when I click on that popup for
> the first time, delay until menu is shown is unacceptable. Usually it takes
> a few seconds. All following times I click on the popup, the menu is
> displayed immediately. Until relaunch of the app..
>
> Shark has not provided any useful information. So I am wondering - I have
> missed something, or should I use some "tricks" to avoid that delay?
Yes -- don't do that!!!
You are asking the system to not only iterate through all of the fonts and styles, but to also set each menu item's text to that font and style. The iteration part is fairly quick, setting the item text requires that the font be loaded and prepared for use just to draw that *one text item*. Preparing each font takes a small amount of time, but multiplied by the 100+ fonts on a system gives you a noticeable time delay.
Most applications that draw the font menu using the fonts actually pre-create the menu items as images of the menu item text, then only display the image in the menu.
(History: I've worked on both the AppleWorks and the Microsoft Office 2011 font menus in my career.)
--
Glenn L. Austin, Computer Wizard and Race Car Driver <><
<http://www.austin-soft.com>
Looking for more opportunities..._______________________________________________
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