FROM : Michael Becker
DATE : Tue Oct 12 18:07:07 2004
Hi!
I want to draw a matrix of buttons in a custom view that need to
re-organise whenever the view's size changes. I've taken the advice to
use NSButtonCells instead of NSButtons. However, these NSButtonCells
don't do anything. They're displayed, I connected their targets and
actions but they don't respond to mouse clicks in whatsoever way.
I tried the same thing with NSButtons, by adding them as subviews to my
custom view and on each drawRect: I checked the view's size and
re-organised the subviews' frame rects. The target/action/highlighting
worked wonderfully. But using NSButtons produced a strange behavior of
the buttons as they would "lag behind" on a resize (I blame that on the
subview-principle, somehow...)
Code snippet #1: Adding another button...
NSButtonCell *button = [[ NSButtonCell alloc] init];
[ button setButtonType:NSMomentaryLightButton];
[ button setBordered:YES];
[ button setBezelStyle:NSRegularSquareBezelStyle];
[ button setTarget:_pvButtonTarget];
[ button setAction:_pvButtonAction];
[ buttons addObject:button];
[ button release];
Code snippet #2: part of the drawRect method:
for (i=0; i<[ buttons count]; i++) {
[[ buttons objectAtIndex:i]
drawWithFrame:NSMakeRect(x,y,BUTTON_WIDTH,BUTTON_HEIGHT) inView:self];
x += BUTTON_CELL_WIDTH;
if (x+BUTTON_CELL_WIDTH >= mySize.width) {
x = 0;
y += BUTTON_CELL_HEIGHT;
}
}
So what do I have to do to get the NSButtonCells to work?
Cheers,
Michael
DATE : Tue Oct 12 18:07:07 2004
Hi!
I want to draw a matrix of buttons in a custom view that need to
re-organise whenever the view's size changes. I've taken the advice to
use NSButtonCells instead of NSButtons. However, these NSButtonCells
don't do anything. They're displayed, I connected their targets and
actions but they don't respond to mouse clicks in whatsoever way.
I tried the same thing with NSButtons, by adding them as subviews to my
custom view and on each drawRect: I checked the view's size and
re-organised the subviews' frame rects. The target/action/highlighting
worked wonderfully. But using NSButtons produced a strange behavior of
the buttons as they would "lag behind" on a resize (I blame that on the
subview-principle, somehow...)
Code snippet #1: Adding another button...
NSButtonCell *button = [[ NSButtonCell alloc] init];
[ button setButtonType:NSMomentaryLightButton];
[ button setBordered:YES];
[ button setBezelStyle:NSRegularSquareBezelStyle];
[ button setTarget:_pvButtonTarget];
[ button setAction:_pvButtonAction];
[ buttons addObject:button];
[ button release];
Code snippet #2: part of the drawRect method:
for (i=0; i<[ buttons count]; i++) {
[[ buttons objectAtIndex:i]
drawWithFrame:NSMakeRect(x,y,BUTTON_WIDTH,BUTTON_HEIGHT) inView:self];
x += BUTTON_CELL_WIDTH;
if (x+BUTTON_CELL_WIDTH >= mySize.width) {
x = 0;
y += BUTTON_CELL_HEIGHT;
}
}
So what do I have to do to get the NSButtonCells to work?
Cheers,
Michael
| Related mails | Author | Date |
|---|---|---|
| Michael Becker | Oct 12, 18:07 | |
| stephane sudre | Oct 12, 18:13 |






Cocoa mail archive

