Skip to content

Instantly share code, notes, and snippets.

@dbrajkovic
Created March 9, 2011 14:58
Show Gist options
  • Save dbrajkovic/862332 to your computer and use it in GitHub Desktop.
Save dbrajkovic/862332 to your computer and use it in GitHub Desktop.
A subclass of TNAttachedWindow that prevents a window from going too far to the left off screen.
/*
* STAttachedWindow.j
* stocktwits-desktop-2
*
* Created by Daniel Brajkovic on 12/13/10.
* Copyright Witton Technology Group 2010. All rights reserved.
*/
@import "TNAttachedWindow.j"
@implementation STAttachedWindow : TNAttachedWindow
{
}
- (void)positionRelativeToView:(CPView)aView gravity:(int)aGravity
{
var frameView = [aView frame],
posX = frameView.origin.x + CPRectGetWidth(frameView),
posY = frameView.origin.y + (CPRectGetHeight(frameView) / 2.0) - (CPRectGetHeight([self frame]) / 2.0),
point = [self computeOrigin:aView gravity:aGravity],
offsetY = 0;
if (point.x < frameView.origin.x ) {
offsetX = frameView.origin.x - point.x
point.x = frameView.origin.x ;
var cursorPoint = [_cursorView frameOrigin];
cursorPoint.x = (frameView.origin.x + CPRectGetWidth(frameView)) /2 ;
[_cursorView setFrameOrigin:cursorPoint];
}
if (point.y < 0)
{
offsetY = point.y;
point.y = 0;
var cursorPoint = [_cursorView frameOrigin];
cursorPoint.y += offsetY;
[_cursorView setFrameOrigin:cursorPoint];
}
[self setFrameOrigin:point];
[self makeKeyAndOrderFront:nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment