• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Pressable Button
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pressable Button


  • Subject: Re: Pressable Button
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Wed, 17 Dec 2008 13:44:47 +0700


On 17 Dec 2008, at 00:56, Stéphane Sudre wrote:


On Dec 16, 2008, at 4:02 PM, Gerriet M. Denkmann wrote:

I am trying to build a pressable button: an on-off button (subclass of NSButton), which, if pressed for more than 0.3 seconds, displays a context menu.

My idea was:
Start a non-repeating timer in mouseDown: and schedule it with NSEventTrackingRunLoopMode.


In mouseUp: invalidate the timer.

And in timerFired: display the context menu.

But: mouseUp: is never called. So: where should I invalidate the timer?

And: if I send: [ NSMenu popUpContextMenu: menu withEvent: mouseDownEvent forView: self ]
the button gets all messed up: no more drawRect: on mouse up, no action sent.


Obviously I am doing it all wrong.

I have a button like this.

I use performSelector:withObject:afterDelay: in the mouseDown:, cancel the delayed perform in mouseDragged: if the mouse cursor is outside the button frame, put back the delayed perform if the mouse cursor comes back in the button frame.

On mouseUp: I cancel the delayed perform if needed.

I tried your solution, but when I press the button for several seconds still no menu comes up.
When I finally release the button in disgust, then suddenly the menu is shown and I feel cheated for having wasted my time in pressing so long.


I did not like this behaviour very much. Did I do something wrong?


Then I followed Peters advice:
Consider using a single-segment NSSegmentedControl. It has this behavior built-in.

But again, I am not completely satisfied: I want the NSOnState shown as done in an NSButton with buttonType = NSOnOffButton and bezelStyle = NSTexturedSquareBezelStyle.


Specifially: the NSOnState should look indented with a black background.
And there should be almost no space wasted left and right of the image or titel.
NSButton with a 20 x 20 image has a size of 24 x 24.
NSSegmentedControl with a 22 x 22 image reports a size of 44 x 24, but the hight looks more like 22.
(When I supply it with an 24 x 24 image, part of the images get drawn outside the button).


Also: a segmented control with an image has a lower height than one with text. Which also reports a height of 24, but looks definitely higher.

I tried messing around with [ [segmentedControl cell] setCellAttribute:to] but this did not seem to do anything at all.

I could live with the hightlight in blue or with the wasted space width-wise, but having different heights for image and text controls looks extremely silly.

But maybe I am doing something silly?


Kind regards,

Gerriet.





_______________________________________________

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


References: 
 >Pressable Button (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Pressable Button (From: Stéphane Sudre <email@hidden>)

  • Prev by Date: Re: nib loading / displaying question.
  • Next by Date: Re: Sublclassing NSThread
  • Previous by thread: Re: Pressable Button
  • Next by thread: Re: Pressable Button
  • Index(es):
    • Date
    • Thread