Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Use next edge when preferred edge rect would be out of bounds #132

Merged
merged 23 commits into from
Apr 12, 2014

Conversation

joshvera
Copy link
Contributor

@joshvera joshvera commented Apr 7, 2014

This fixes a bug where defaulting to the preferred edge when the popover's proposed rect isn't contained in the screen's visible frame, causes the popover to display incorrectly.

Before:

popover-edge-bug

After:
popover-edge-bug-fix

Also fixes a bug where a zero anchor point doesn't render the arrow on the edge.

Before:

arrow-edge-bug

After:
arrow-edge-bug-fix

@mdiep
Copy link
Contributor

mdiep commented Apr 7, 2014

Also fixes a bug where a zero anchor point doesn't render the arrow on the edge.

This was actually the intended behavior. The arrow is centered under the common section of the axis.

Instead of changing this, can we add a property that's similar to anchorPoint to determine the arrow position?

@joshvera
Copy link
Contributor Author

joshvera commented Apr 8, 2014

@mdiep Ah I see. I reverted that, but added 4a2b244. Should it be the caller's responsibility to provide an alignment rect? The result of that change looks like:

screen shot 2014-04-07 at 11 55 37 pm

@mdiep mdiep self-assigned this Apr 8, 2014
@@ -70,7 +70,7 @@ - (IBAction)showRBLPopover:(id)sender {
} else {
NSView *button = sender;
self.RBLPopover.behavior = self.behavior;
[self.RBLPopover showRelativeToRect:CGRectZero ofView:button preferredEdge:(CGRectEdge)self.preferredEdge];
[self.RBLPopover showRelativeToRect:button.bounds ofView:button preferredEdge:(CGRectEdge)self.preferredEdge];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are equivalent, FWIW.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mdiep
Copy link
Contributor

mdiep commented Apr 8, 2014

but added 4a2b244. Should it be the caller's responsibility to provide an alignment rect? The result of that change looks like:

This is to move the tip of the arrow closer to the actual button in this case? I'd been meaning to fix that up. ✨

@@ -289,7 +302,11 @@ - (void)showRelativeToRect:(CGRect)positioningRect ofView:(NSView *)positioningV

if (self.shown) {
if (self.backgroundView.popoverEdge == popoverEdge) {
CGSize size = [self.backgroundView sizeForBackgroundViewWithContentSize:contentViewSize popoverEdge:popoverEdge];
self.backgroundView.frame = (NSRect){ .size = size };
self.backgroundView.popoverEdge = popoverEdge;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.backgroundView.popoverEdge is already set since it's in the if statement.

Is there a reason we need to set the frame here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 about the -popoverEdge.

If we don't set the frame here, but we change the popover's -contentSize before calling this method, the frame of the -popoverWindow is recalculated, but the clipping path isn't updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm… that's a little strange because I'd expect everything to update when you set the contentSize. You shouldn't need to call showRelativeToRect:ofView:preferredEdge: to get the popover to use a new content size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but contentSize is just a property with no effects right now. We can make that change in a subsequent pull request if that's 🆒 with you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CGFloat minMidpointX = floor(minX + RBLPopoverBackgroundViewBorderRadius);
CGFloat maxMidpointX = floor(maxX - RBLPopoverBackgroundViewBorderRadius);
CGFloat minMidpointY = floor(minY + RBLPopoverBackgroundViewBorderRadius);
CGFloat maxMidpointY = floor(maxY - RBLPopoverBackgroundViewBorderRadius);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these would benefit from clearer names. They're describing the center points of the arcs. Midpoint doesn't really communicate that to me, but I don't have any great suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arcpoint? Centerpoint?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Centerpoint + a short comment explaining what they represent?

@mdiep
Copy link
Contributor

mdiep commented Apr 8, 2014

🌌

@joshvera
Copy link
Contributor Author

joshvera commented Apr 8, 2014

🚑

mdiep added a commit that referenced this pull request Apr 12, 2014
Use next edge when preferred edge rect would be out of bounds
@mdiep mdiep merged commit 4a5ffef into master Apr 12, 2014
@mdiep mdiep deleted the popover-edge-fixes branch April 12, 2014 14:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants