Skip to content

Commit

Permalink
keep annotation window in viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuwei committed Aug 20, 2017
1 parent 3769525 commit 1603406
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/AnnotationWinController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ -(void)awakeFromNib{
- (void)showWindow:(NSPoint)origin {
NSSize size;
size.width = 170;
size.height = 258;
size.height = 256;// max-height of sharedCandidates
[[self panel] setMinSize:size];
[[self panel] setContentSize: size];
[[self panel] setAlphaValue: 0.9];
Expand Down
28 changes: 27 additions & 1 deletion src/InputController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,37 @@ -(void)showAnnotation:(NSAttributedString*)candidateString{
NSRect currentFrame = [sharedCandidates candidateFrame];
NSRect tempRect;
[_currentClient attributesForCharacterIndex:0 lineHeightRectangle:&tempRect];
NSPoint insertionPoint = NSMakePoint(NSMinX(tempRect), NSMinY(tempRect));
NSPoint windowInsertionPoint = NSMakePoint(NSMinX(tempRect), NSMinY(tempRect));
windowInsertionPoint.x = windowInsertionPoint.x + currentFrame.size.width;
NSRect rect = [[NSScreen mainScreen] frame];
int screenWidth = (int)rect.size.width;


if ((insertionPoint.x + currentFrame.size.width + 170 + 20) >= screenWidth) {
windowInsertionPoint.x = insertionPoint.x - 170 - 20;
}

if (screenWidth - insertionPoint.x < 170) {
windowInsertionPoint.x = screenWidth - currentFrame.size.width - 170 - 20;
}

if (windowInsertionPoint.y <= currentFrame.size.height) {
windowInsertionPoint.y = currentFrame.size.height + windowInsertionPoint.y + 28; //28 is line-height
} else {
windowInsertionPoint.y = windowInsertionPoint.y - 6;
}


[_annotationWin setAnnotation: translations];
[_annotationWin showWindow: windowInsertionPoint];
}else{

// int screenHeight = (int)rect.size.height;
// NSLog(@"sharedCandidates currentFrame: %@, windowInsertionPoint:%@, screen width: %d screen height %d",
// NSStringFromRect(currentFrame),
// NSStringFromPoint(windowInsertionPoint),
// screenWidth, screenHeight);
} else {
[_annotationWin hideWindow];
}
}
Expand Down

0 comments on commit 1603406

Please sign in to comment.