Re: Window/View Size Constraining
Re: Window/View Size Constraining
- Subject: Re: Window/View Size Constraining
- From: Gordon Apple <email@hidden>
- Date: Sat, 20 Oct 2007 23:58:23 -0500
I totally rewrote the "windowWillResize" delegate method to correctly
compute size by contentRect rather than frameRect. It works correctly
except for the same remaining two issues.
> The following code is my attempt to constrain a displayView and window
> size such that the displayView maintains the proper aspect ratio when the
> window is resized. I have two issues:
>
> 1. The displayView size tracking lags by at
> least one time sample and I then have to gently nudge the window size to get
> it right, or at least within one pixel. I don't understand why the display
view lags, since I'm computing everything based on the proposed window size, not
current size. I could try to clean it up in "windowDidResize", but could end up
in an infinite loop trying to do that.
>
> 2. This is a variable size window that is intended to show a miniature
> display of what is in the main window (elsewhere), with a fixed height
controlView below.. I made an abortive
> attempt to scale the coordinates of displayView. Apparently, I don't
> understand the "scaleUnitSquareToSize" call and the docs don't help much. Any
> suggestions?
- (float)aspectRatio
{
NSSize fullSize = [self mainDisplaySize]; // From original (large)
window.
return fullSize.width / fullSize.height;
}
- (float)newDisplayHeightFromWidth:(float)width
{
// Computes height to maintain correct aspect ratio.
return width / [self aspectRatio];
}
- (float)contentHeightFromWidth:(float)width
{
float displayViewHeight = [self newDisplayHeightFromWidth:width];
float controlViewHeight = controlView == nil ? 0 : [controlView
frame].size.height;
return displayViewHeight + controlViewHeight;
}
// Window delegate for size
- (NSSize)windowWillResize:(NSWindow*)sender
toSize:(NSSize)frameSize
{
NSRect frameRect = [sender frame]; // To set origin.
frameRect.size = frameSize; // Set to proposed size
NSRect contentRect = [sender contentRectForFrameRect:frameRect];
NSSize contentSize = contentRect.size;
float contentWidth = contentSize.width;
// Set displaView size.
[displayView setFrameSize:NSMakeSize(contentWidth, [self
newDisplayHeightFromWidth:contentWidth])];
// Abortive attempt to scale display to fit.
// NSSize fullSize = [self mainDisplaySize]; // From original
(large) window.
// float scale = fullSize.width / contentWidth;
// [displayView scaleUnitSquareToSize:NSMakeSize(scale, scale)];
contentRect.size = NSMakeSize(contentWidth, [self
contentHeightFromWidth:contentWidth]);
frameRect = [sender frameRectForContentRect:contentRect];
return frameRect.size;
}
_______________________________________________
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