[SOLVED] Re: setFrame: not working in custom event loop
[SOLVED] Re: setFrame: not working in custom event loop
- Subject: [SOLVED] Re: setFrame: not working in custom event loop
- From: Mike Manzano <email@hidden>
- Date: Wed, 11 Mar 2009 12:10:53 -0700
That was exactly it. Thank you very much!
Mike
On Mar 11, 2009, at 11:48 AM, Andy Lee wrote:
I'm guessing the problem is that you are only calling setFrame: on
subview 0, thereby increasing the total width of the subviews. You
are assuming subview 1 will adjust by the same amount as you added/
subtracted from subview 0. But actually, adjustSubviews scales both
subviews down so their total width is what it was before. You can
see this by doing an NSLog *after* the call to adjustSubviews.
What you need to do is adjust the width of *both* subviews -- add
from one, subtract from the other -- maintaining constant total width.
--Andy
On Mar 11, 2009, at 2:17 PM, Mike Manzano wrote:
Well, I just rewrote it, and it's doing exactly the same thing. You
can see this from the debug output:
2009-03-11 11:15:50.092 SkootUI[13145:10b] Will Set To: {{0, 0},
{743, 604}}
2009-03-11 11:15:50.097 SkootUI[13145:10b] After: {{0, 0}, {743,
604}}
2009-03-11 11:15:50.179 SkootUI[13145:10b] Will Set To: {{0, 0},
{744, 604}}
2009-03-11 11:15:50.186 SkootUI[13145:10b] After: {{0, 0}, {744,
604}}
2009-03-11 11:15:51.221 SkootUI[13145:10b] *** Finally: {{0, 0},
{689, 604}}
Here's the new code:
- (void)mouseUp:(NSEvent *)theEvent
{
NSLog( @"*** Finally: %@" , NSStringFromRect( [[[splitView
subviews] objectAtIndex:0] frame] )) ;
}
- (void)mouseDragged:(NSEvent *)theEvent
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter] ;
[nc postNotificationName:NSSplitViewWillResizeSubviewsNotification
object:splitView];
NSRect firstFrame = [[[splitView subviews] objectAtIndex:0] frame];
firstFrame.size.width = (_isLeftResizer ?
MAX(0,roundf(([splitViewconvertPoint:[theEvent locationInWindow]
fromView:nil].x + _offset) - firstFrame.origin.x)) :
MAX(0,roundf([splitViewconvertPoint:[theEvent locationInWindow]
fromView:nil].x - [splitViewdividerThickness] - _offset)));
firstFrame.size.width = MIN(MAX(firstFrame.size.width,_min),_max);
NSLog( @"Will Set To: %@" , NSStringFromRect(firstFrame) ) ;
[[[splitView subviews] objectAtIndex:0] setFrame:firstFrame];
NSLog( @"\tAfter: %@" , NSStringFromRect( [[[splitView subviews]
objectAtIndex:0] frame] )) ;
[splitView adjustSubviews];
[nc postNotificationName:NSSplitViewDidResizeSubviewsNotification
object:splitView];
[[splitView window] flushWindowIfNeeded] ;
}
- (void)mouseDown:(NSEvent *)theEvent
{
// Get min and max sizes of the first sub view from the split view
delegate if there is one...
_min = 0.0 ;
_max = [splitView frame].size.width - [splitView dividerThickness];
if ([[splitView delegate]
respondsToSelector
:@selector(splitView:constrainMinCoordinate:ofSubviewAt:)])
_min = [[splitView delegate] splitView:splitView
constrainMinCoordinate:_min ofSubviewAt:0];
if ([[splitView delegate]
respondsToSelector
:@selector(splitView:constrainMaxCoordinate:ofSubviewAt:)])
_max = [[splitView delegate] splitView:splitView
constrainMaxCoordinate:_max ofSubviewAt:0];
_isLeftResizer = [self isDescendantOf:[[splitView subviews]
objectAtIndex:0]];
_offset = _isLeftResizer ?
[self frame].size.width - [self convertPoint:[theEvent
locationInWindow] fromView:nil].x :
[self convertPoint:[theEvent locationInWindow] fromView:nil].x ;
}
On Mar 11, 2009, at 10:52 AM, Mike Manzano wrote:
Nope that didn't do it. Same symptoms. Any other ideas before I
throw in the gauntlet and rewrite it?
On Mar 10, 2009, at 5:41 PM, Jesper Storm Bache wrote:
When you modify a window it registers itself as needing redrawing
in the current run loop.
If you are performing active tracking, you may have to do so
yourself.
Try calling [window flushWindowIfNeeded] on your window at the
end of your loop (inside the loop).
What is the reason for your explicit tracking?
You should be able to simply listen for mouseDragged, mouseDown,
and mouseUp on your split view (if this is a custom sub-class).
Jesper Storm Bache
On Mar 10, 2009, at 2:51 PM, Mike Manzano wrote:
Hi,
I am tracking the mouse pointer to dynamically resize a splitter
as a
separate drag handle is dragged. This is done in mouseDown: of the
drag handle with a custom event loop. The loop looks like this:
while (keepOn)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
theEvent = [[self window] nextEventMatchingMask:
NSAnyEventMask] ;// NSLeftMouseUpMask | NSLeftMouseDraggedMask];
switch ([theEvent type])
{
case NSLeftMouseUp:
keepOn = NO;
break;
case NSLeftMouseDragged:
[nc
postNotificationName:NSSplitViewWillResizeSubviewsNotification
object:splitView];
firstFrame = [[[splitView subviews] objectAtIndex:0] frame];
firstFrame.size.width = (isLeftResizer ?
MAX(0,roundf(([splitViewconvertPoint:[theEvent
locationInWindow] fromView:nil].x + offset) -
firstFrame.origin.x)) :
MAX(0,roundf([splitViewconvertPoint:[theEvent
locationInWindow] fromView:nil].x - [splitViewdividerThickness] -
offset)));
firstFrame.size.width =
MIN(MAX(firstFrame.size.width,min),max);
NSLog( @"SetFrame: %@" , NSStringFromRect(firstFrame) ) ;
[[[splitView subviews] objectAtIndex:0] setFrame:firstFrame];
NSLog( @"\tIs Now: %@" , NSStringFromRect([[[splitView
subviews]
objectAtIndex:0] frame]) ) ;
[splitView adjustSubviews];
[nc
postNotificationName:NSSplitViewDidResizeSubviewsNotification
object:splitView];
break;
default:
break;
}
[pool release] ;
}
NSLog( @"Finally: %@" , NSStringFromRect([[[splitView subviews]
objectAtIndex:0] frame]) ) ;
(you might recognize this is as the Scrivener custom split view
code
available on the web)
Anyway, the visual updates to the screen seem to start lagging the
further right I drag the handle. You can see the NSLog()s I have
in
the code; here is the output as I drag:
[...]
2009-03-10 14:37:42.428 SkootUI[8830:10b] SetFrame: {{0, 0},
{718, 604}}
2009-03-10 14:37:42.444 SkootUI[8830:10b] Is Now: {{0, 0},
{718, 604}}
2009-03-10 14:37:42.511 SkootUI[8830:10b] SetFrame: {{0, 0},
{721, 604}}
2009-03-10 14:37:42.539 SkootUI[8830:10b] Is Now: {{0, 0},
{721, 604}}
2009-03-10 14:37:42.596 SkootUI[8830:10b] SetFrame: {{0, 0},
{723, 604}}
2009-03-10 14:37:42.600 SkootUI[8830:10b] Is Now: {{0, 0},
{723, 604}}
2009-03-10 14:37:44.101 SkootUI[8830:10b] Finally: {{0, 0},
{684, 604}}
As you can see, as far as the view being resized is concerned,
it is
being set to what I set it to as I drag the handle; i.e., the
"SetFrame:" dimensions match the "Is Now:" dimensions. During this
time, however, I can see the view sizing visually lag. When the
drag
finishes and the "Finally" block prints out, querying the view
for its
frame displays what I believe to be the actual lagged dimensions.
Can anyone tell me what's going on?
Thanks,
Mike
_______________________________________________
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
_______________________________________________
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
_______________________________________________
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
_______________________________________________
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