Revision: 25964 http://sourceforge.net/p/bibdesk/svn/25964 Author: hofman Date: 2021-05-16 16:21:16 +0000 (Sun, 16 May 2021) Log Message: ----------- Use auto layout for conditions views, update size of scrollview using auto layout
Modified Paths: -------------- trunk/bibdesk/BDSKConditionsView.m trunk/bibdesk/BDSKFilterController.m trunk/bibdesk/Base.lproj/BDSKFilter.xib Modified: trunk/bibdesk/BDSKConditionsView.m =================================================================== --- trunk/bibdesk/BDSKConditionsView.m 2021-05-16 08:57:56 UTC (rev 25963) +++ trunk/bibdesk/BDSKConditionsView.m 2021-05-16 16:21:16 UTC (rev 25964) @@ -48,58 +48,50 @@ return YES; } -- (NSSize)minimumSize { - NSArray *subviews = [self subviews]; - CGFloat height = ([subviews count] > 0) ? NSMaxY([[subviews lastObject] frame]) : 10.0; - return NSMakeSize(NSWidth([self frame]), height); -} - -- (void)setFrameSize:(NSSize)newSize { - if (newSize.height >= [self minimumSize].height) { - [super setFrameSize:newSize]; +- (void)updateSize { + NSSize size = NSZeroSize; + for (NSView *view in [self subviews]) { + NSSize fittingSize = [view fittingSize]; + size.width = fmax(size.width, fittingSize.width); + size.height += fittingSize.height + SEPARATION; } -} - -- (void)updateSize { - NSSize newSize = [self minimumSize]; - CGFloat oldHeight = NSHeight([self frame]); - CGFloat newHeight = newSize.height; - CGFloat dh = fmin(newHeight, MAX_HEIGHT) - fmin(oldHeight, MAX_HEIGHT); + size.height -= SEPARATION; + if (size.height <= 0.0) + size = NSMakeSize(10.0, 10.0); - if (newHeight < oldHeight) - [self setFrameSize:newSize]; + [self setFrameSize:size]; - // resize the window up to a maximal size - NSRect winFrame = [[self window] frame]; - winFrame.size.height += dh; - winFrame.origin.y -= dh; - - if ([[self window] isVisible]) - [[[self window] animator] setFrame:winFrame display:YES]; - else - [[self window] setFrame:winFrame display:NO]; - - if (newHeight > oldHeight) - [self setFrameSize:newSize]; + for (NSLayoutConstraint *constraint in [[self enclosingScrollView] constraints]) { + if ([constraint firstAttribute] == NSLayoutAttributeHeight) { + if ([[self window] isVisible]) + [[constraint animator] setConstant:fmin(size.height, MAX_HEIGHT)]; + else + [constraint setConstant:fmin(size.height, MAX_HEIGHT)]; + } else if ([constraint firstAttribute] == NSLayoutAttributeWidth) { + [constraint setConstant:size.width + 14.0]; + } + } } - (void)insertView:(NSView *)view atIndex:(NSUInteger)idx{ NSArray *subviews = [[[self subviews] copy] autorelease]; NSView *prevView = idx == 0 ? nil : [subviews objectAtIndex:idx - 1]; + NSView *nextView = idx == [subviews count] ? nil : [subviews objectAtIndex:idx]; - CGFloat yPosition = prevView ? NSMaxY([prevView frame]) + SEPARATION : 0.0; - NSSize size = [view frame].size; - NSInteger i, count = [subviews count]; - - [view setFrameOrigin:NSMakePoint(0.0, yPosition)]; - [view setFrameSize:NSMakeSize(NSWidth([self frame]), size.height)]; [self addSubview:view positioned:prevView ? NSWindowAbove : NSWindowBelow relativeTo:prevView]; - for (i = idx; i < count; i++) { - yPosition = NSMaxY([view frame]) + SEPARATION; - view = [subviews objectAtIndex:i]; - [view setFrameOrigin:NSMakePoint(0.0, yPosition)]; + if (nextView) { + for (NSLayoutConstraint *constraint in [self constraints]) { + if ([constraint firstItem] == nextView && [constraint firstAttribute] == NSLayoutAttributeTop) { + [self removeConstraint:constraint]; + break; + } + } } + [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:prevView ?: self attribute:prevView ? NSLayoutAttributeBottom : NSLayoutAttributeTop multiplier:1.0 constant:SEPARATION]]; + if (nextView) + [self addConstraint:[NSLayoutConstraint constraintWithItem:nextView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:SEPARATION]]; [self updateSize]; } @@ -113,18 +105,12 @@ NSUInteger idx = [subviews indexOfObjectIdenticalTo:view]; if (idx != NSNotFound) { - - NSPoint newPoint = [view frame].origin; - CGFloat dy = NSHeight([view frame]) + SEPARATION; - [view removeFromSuperview]; - NSUInteger count = [subviews count]; - - for (idx++; idx < count; idx++) { - view = [subviews objectAtIndex:idx]; - [view setFrameOrigin:newPoint]; - newPoint.y += dy; + if (idx + 1 < [subviews count]) { + NSView *prevView = idx == 0 ? nil : [subviews objectAtIndex:idx - 1]; + NSView *nextView = idx == [subviews count] - 1 ? nil : [subviews objectAtIndex:idx + 1]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:nextView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:prevView ?: self attribute:prevView ? NSLayoutAttributeBottom : NSLayoutAttributeTop multiplier:1.0 constant:SEPARATION]]; } [self updateSize]; @@ -135,6 +121,7 @@ NSArray *subviews = [[self subviews] copy]; [subviews makeObjectsPerformSelector:@selector(removeFromSuperviewWithoutNeedingDisplay)]; [subviews release]; + [self updateSize]; } Modified: trunk/bibdesk/BDSKFilterController.m =================================================================== --- trunk/bibdesk/BDSKFilterController.m 2021-05-16 08:57:56 UTC (rev 25963) +++ trunk/bibdesk/BDSKFilterController.m 2021-05-16 16:21:16 UTC (rev 25964) @@ -98,14 +98,6 @@ } - (void)windowDidLoad { - NSRect viewFrame = [conditionsView frame]; - CGFloat dw = [[[conditionControllers firstObject] view] fittingSize].width - NSWidth(viewFrame); - NSRect winFrame = [[self window] frame]; - winFrame.size.width += dw; - [[self window] setFrame:winFrame display:NO]; - viewFrame.size.width += dw; - [conditionsView setFrame:viewFrame]; - for (BDSKConditionController *controller in conditionControllers) { [conditionsView addView:[controller view]]; [controller startObserving]; @@ -118,11 +110,12 @@ [messageStartTextField setStringValue:NSLocalizedString(@"Match the following condition:", @"Label for smart group editor")]; [conjunctionPopUp setHidden:YES]; [messageEndTextField setHidden:YES]; + [[conditionControllers firstObject] setCanRemove:NO]; } else { [messageStartTextField setStringValue:NSLocalizedString(@"Match", @"Beginning of label for smart group editor")]; [conjunctionPopUp setHidden:NO]; [messageEndTextField setHidden:NO]; - [[messageStartTextField superview] setNeedsDisplayInRect:[messageStartTextField frame]]; + [[conditionControllers firstObject] setCanRemove:YES]; } } @@ -157,10 +150,8 @@ [conditionsView insertView:[newController view] atIndex:idx]; [newController startObserving]; [newController setCanRemove:(count > 0)]; - if (count == 1) { - [[conditionControllers objectAtIndex:0] setCanRemove:YES]; + if (count == 1) [self updateUI]; - } [conditionsView scrollRectToVisible:[[newController view] frame]]; [newController selectKeyText:self]; } @@ -178,10 +169,8 @@ [aConditionController stopObserving]; [conditionsView removeView:[aConditionController view]]; [conditionControllers removeObject:aConditionController]; - if ([conditionControllers count] == 1) { - [[conditionControllers objectAtIndex:0] setCanRemove:NO]; + if ([conditionControllers count] == 1) [self updateUI]; - } } - (BOOL)canRemoveCondition { Modified: trunk/bibdesk/Base.lproj/BDSKFilter.xib =================================================================== --- trunk/bibdesk/Base.lproj/BDSKFilter.xib 2021-05-16 08:57:56 UTC (rev 25963) +++ trunk/bibdesk/Base.lproj/BDSKFilter.xib 2021-05-16 16:21:16 UTC (rev 25964) @@ -35,9 +35,8 @@ <rect key="frame" x="3" y="3" width="660" height="68"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> - <scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" id="81"> + <scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="81"> <rect key="frame" x="8" y="7" width="644" height="54"/> - <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <clipView key="contentView" autoresizesSubviews="NO" drawsBackground="NO" copiesOnScroll="NO" id="vHk-Pm-is4"> <rect key="frame" x="0.0" y="0.0" width="644" height="54"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> @@ -49,6 +48,10 @@ </subviews> <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> </clipView> + <constraints> + <constraint firstAttribute="height" constant="54" id="AHk-Yz-ReG"/> + <constraint firstAttribute="width" constant="644" id="gtl-SM-seK"/> + </constraints> <scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="0.013333329999999999" controlSize="small" horizontal="YES" id="96"> <rect key="frame" x="-100" y="-100" width="606" height="11"/> <autoresizingMask key="autoresizingMask"/> @@ -59,6 +62,12 @@ </scroller> </scrollView> </subviews> + <constraints> + <constraint firstAttribute="trailing" secondItem="81" secondAttribute="trailing" constant="8" id="Jpw-jU-ZuB"/> + <constraint firstItem="81" firstAttribute="leading" secondItem="pK2-Il-BDi" secondAttribute="leading" constant="8" id="WcT-bz-kDQ"/> + <constraint firstItem="81" firstAttribute="top" secondItem="pK2-Il-BDi" secondAttribute="top" constant="7" id="f64-oa-4G5"/> + <constraint firstAttribute="bottom" secondItem="81" secondAttribute="bottom" constant="7" id="v5J-GK-EiA"/> + </constraints> </view> </box> <button verticalHuggingPriority="750" tag="1" translatesAutoresizingMaskIntoConstraints="NO" id="10"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit