开发者

How to center a CPWindow in Cappuccino

开发者 https://www.devze.com 2023-02-12 00:18 出处:网络
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:

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 setCent开发者_如何学运维er:[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.


CPWindow (and CPPanel) have a center method.

[aWindow center];


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号