aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPSplitView.m
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2014-11-29 00:44:02 +0100
committerMax <post@wickenrode.com>2014-11-29 00:44:02 +0100
commita8598d0fb4bab81a3c654f99d2e6eebc7d818086 (patch)
tree78d1fffa25a05e0163812dd7be00c731ae7f7103 /Source/SPSplitView.m
parent065d72ceb7e8213348490815f6f90ecf4de56061 (diff)
downloadsequelpro-a8598d0fb4bab81a3c654f99d2e6eebc7d818086.tar.gz
sequelpro-a8598d0fb4bab81a3c654f99d2e6eebc7d818086.tar.bz2
sequelpro-a8598d0fb4bab81a3c654f99d2e6eebc7d818086.zip
Change some split view width calculations.
* Attempt to fix the "<SPSplitView: ...>: the delegate <SPSplitView: ...> was sent -splitView:resizeSubviewsWithOldSize: and left the subview frames in an inconsistent state:" message that has been plaguing my console for some time. * This commit also adds a minimum width on the main area to prevent some strange UI bugs.
Diffstat (limited to 'Source/SPSplitView.m')
-rw-r--r--Source/SPSplitView.m33
1 files changed, 28 insertions, 5 deletions
diff --git a/Source/SPSplitView.m b/Source/SPSplitView.m
index b946496e..9d5b59d8 100644
--- a/Source/SPSplitView.m
+++ b/Source/SPSplitView.m
@@ -365,6 +365,27 @@
[super adjustSubviews];
return;
}
+
+
+ // Imagine width=9,viewCount=2 and suggestedSizes would return {4.5, 4.5}
+ // If we did a roundf() we would exceed the size limit (because we'd get {5,5}).
+ // However if we don't round, we might get two float values which don't add up anyway
+ // because of a precision issue.
+ // So let's do the following instead: round alernating between DOWN and UP.
+ // Finnally give the remainder to the last subview.
+ // Example with width=11,viewCount=3 -> 3 ; 4 ; 3 + (11 - 10) = 3;4;4
+ CGFloat *viewSizesRaw = calloc(sizeof(CGFloat), viewCount);
+ CGFloat spaceRemaining = totalAvailableSize;
+ for (i = 0; i < viewCount; i++) {
+ //recalculate value
+ CGFloat floatVal = [[viewSizes objectAtIndex:i] floatValue];
+ CGFloat rounded = viewSizesRaw[i] = ((i % 2) == 0)? floorf(floatVal) : ceilf(floatVal);
+ spaceRemaining -= rounded;
+ }
+ //last one gets the remainder
+ if(spaceRemaining) {
+ viewSizesRaw[i-1] += spaceRemaining;
+ }
CGFloat splitViewBreadth;
if ([self isVertical]) {
@@ -377,17 +398,17 @@
CGFloat originPosition = 0;
for (i = 0; i < viewCount; i++) {
NSView *eachSubview = [[self subviews] objectAtIndex:i];
- CGFloat viewSize = [[viewSizes objectAtIndex:i] floatValue];
+ CGFloat viewSize = viewSizesRaw[i];
NSRect viewFrame = [eachSubview frame];
if ([self isVertical]) {
- viewFrame.origin.x = roundf(originPosition);
- viewFrame.size.width = roundf(viewSize);
+ viewFrame.origin.x = originPosition;
+ viewFrame.size.width = viewSize;
viewFrame.size.height = splitViewBreadth;
} else {
- viewFrame.origin.y = roundf(originPosition);
+ viewFrame.origin.y = originPosition;
viewFrame.size.width = splitViewBreadth;
- viewFrame.size.height = roundf(viewSize);
+ viewFrame.size.height = viewSize;
}
[eachSubview setFrame:viewFrame];
@@ -398,6 +419,8 @@
originPosition += [self dividerThickness];
}
}
+
+ free(viewSizesRaw);
// Invalidate the cursor rects
[[self window] invalidateCursorRectsForView:self];