Skip to content

Commit

Permalink
Fixed it so that pop ups are properly placed over their buttons.
Browse files Browse the repository at this point in the history
Reviewed by me.
  • Loading branch information
Francisco Ryan Tolmasky I committed Jan 29, 2009
1 parent d0db803 commit 3ac6b3c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
5 changes: 5 additions & 0 deletions AppKit/CPMenu.j
Expand Up @@ -949,6 +949,11 @@ var STICKY_TIME_INTERVAL = 500,
return self;
}

- (CGFloat)overlapOffsetWidth
{
return LEFT_MARGIN;
}

- (void)setFont:(CPFont)aFont
{
[_menuView setFont:aFont];
Expand Down
8 changes: 2 additions & 6 deletions AppKit/CPMenuItem.j
Expand Up @@ -1028,7 +1028,6 @@ var _CPMenuItemSelectionColor = nil,
[_imageAndTextView setText:[_menuItem title]];
[_imageAndTextView setTextColor:[self textColor]];
[_imageAndTextView setFrameOrigin:CGPointMake(x, VERTICAL_MARGIN)];

[_imageAndTextView sizeToFit];

var frame = [_imageAndTextView frame];
Expand Down Expand Up @@ -1066,12 +1065,9 @@ var _CPMenuItemSelectionColor = nil,
[self setFrameSize:_minSize];
}

- (float)calculatedLeftMargin
- (CGFloat)overlapOffsetWidth
{
if (_belongsToMenuBar)
return 0.0;

return LEFT_MARGIN + ([[_menuItem menu] showsStateColumn] ? STATE_COLUMN_WIDTH : 0.0) + [_menuItem indentationLevel] * INDENTATION_WIDTH;
return LEFT_MARGIN + ([[_menuItem menu] showsStateColumn] ? STATE_COLUMN_WIDTH : 0.0);
}

- (void)setShowsStateColumn:(BOOL)shouldShowStateColumn
Expand Down
17 changes: 11 additions & 6 deletions AppKit/CPPopUpButton.j
Expand Up @@ -639,19 +639,24 @@ var CPPopUpButtonArrowsImage = nil;
[menuWindow setDelegate:self];
[menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle];

var menuOrigin = [theWindow convertBaseToBridge:[self convertPoint:CGPointMakeZero() toView:nil]];

// Pull Down Menus show up directly below their buttons.
if (_pullsDown)
menuOrigin.y += CGRectGetHeight([self frame]);
var menuOrigin = [theWindow convertBaseToBridge:[self convertPoint:CGPointMake(0.0, CGRectGetMaxY([self bounds])) toView:nil]];

// Pop Up Menus attempt to show up "on top" of the selected item.
else
{
var contentRect = [menuWindow rectForItemAtIndex:_selectedIndex];
// This is confusing, I KNOW, so let me explain it to you.
// We want the *content* of the selected menu item to overlap the *content* of our pop up.
// 1. So calculate where our content is, then calculate where the menu item is.
// 2. Move LEFT by whatever indentation we have (offsetWidths, aka, window margin, item margin, etc).
// 3. MOVE UP by the difference in sizes of the content and menu item, this will only work if the content is vertically centered.
var contentRect = [self convertRect:[self contentRectForBounds:[self bounds]] toView:nil],
menuOrigin = [theWindow convertBaseToBridge:contentRect.origin],
menuItemRect = [menuWindow rectForItemAtIndex:_selectedIndex];

menuOrigin.x -= CGRectGetMinX(contentRect) + [[[menu itemAtIndex:_selectedIndex] _menuItemView] calculatedLeftMargin];
menuOrigin.y -= CGRectGetMinY(contentRect);
menuOrigin.x -= CGRectGetMinX(menuItemRect) + [menuWindow overlapOffsetWidth] + [[[menu itemAtIndex:_selectedIndex] _menuItemView] overlapOffsetWidth];
menuOrigin.y -= CGRectGetMinY(menuItemRect) + (CGRectGetHeight(menuItemRect) - CGRectGetHeight(contentRect)) / 2.0;
}

[menuWindow setFrameOrigin:menuOrigin];
Expand Down

0 comments on commit 3ac6b3c

Please sign in to comment.