M. Ryan
M. Ryan

Reputation: 7192

How to center a CPWindow in Cappuccino

I'm interested in having a CPWindow (specifically a CPPanel) be centered and auto-sized much like you might do the same for a CPView as follows:

[view setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];   
[view setCenter:[contentView center]];

However CPWindows seem to not have these same methods.

And while we're at it, how do you prevent a CPPanel from being dragged around? Is such a thing even possible?

Thanks.

Upvotes: 1

Views: 718

Answers (2)

Me1000
Me1000

Reputation: 1758

CPWindow (and CPPanel) have a center method.

[aWindow center];

Upvotes: 4

Alexander Ljungberg
Alexander Ljungberg

Reputation: 6362

There is no autoresizing for a window. You can centre a window or a panel within its browser window by simply placing it in the centre of the available size using code such as this:

var containerSize = [[aWindow platformWindow] contentBounds].size,
    aSize = [aWindow frame].size,
    targetFrame = CGRectMake((containerSize.width - aSize.width) / 2.0, (containerSize.height - aSize.height) / 2.0, aSize.width, aSize.height);

[aWindow setFrame:targetFrame display:YES animate:NO];

From there on you can update it to stay in the centre whenever the platform window resizes. Listen for CPWindowDidResizeNotification notifications sent by [aWindow platformWindow].

I can't think of an easy way to prevent a window from being dragged around short of removing its titlebar by creating it with the CPBorderlessWindowMask mask.

Upvotes: 3

Related Questions