Revision: 27830
          http://sourceforge.net/p/bibdesk/svn/27830
Author:   hofman
Date:     2022-08-23 15:39:40 +0000 (Tue, 23 Aug 2022)
Log Message:
-----------
float scale popup in zoomable text and pdf views in lower left corner. Adjust 
content and scroller insets of scrollview to allow space for it.

Modified Paths:
--------------
    trunk/bibdesk/BDSKZoomablePDFView.m
    trunk/bibdesk/BDSKZoomableTextView.m

Modified: trunk/bibdesk/BDSKZoomablePDFView.m
===================================================================
--- trunk/bibdesk/BDSKZoomablePDFView.m 2022-08-23 09:26:12 UTC (rev 27829)
+++ trunk/bibdesk/BDSKZoomablePDFView.m 2022-08-23 15:39:40 UTC (rev 27830)
@@ -57,6 +57,7 @@
 - (void)makeScalePopUpButton;
 - (void)scalePopUpAction:(id)sender;
 - (void)setScaleFactor:(CGFloat)factor adjustPopup:(BOOL)flag;
+- (void)updateScrollerInsets;
 
 @end
 
@@ -235,6 +236,10 @@
     [self updateColorFilters];
 }
 
+- (void)updateScrollerInsets {
+    [[self scrollView] setScrollerInsets:NSEdgeInsetsMake(0.0, 
[scalePopUpButton intrinsicContentSize].width + 3.0, 0.0, 0.0)];
+}
+
 - (void)makeScalePopUpButton {
     
     if (scalePopUpButton == nil) {
@@ -276,17 +281,14 @@
         [scalePopUpButton setTarget:self];
         [scalePopUpButton setAction:@selector(scalePopUpAction:)];
         
-        NSView *containerView = [[[NSView alloc] initWithFrame:[self frame]] 
autorelease];
-        [containerView setAutoresizingMask:NSViewWidthSizable | 
NSViewHeightSizable];
-        [[self superview] addSubview:containerView];
-        
-        backgroundView = [[BDSKColoredView alloc] initWithFrame:[self frame]];
+        NSView *containerView = [[[NSView alloc] 
initWithFrame:[scalePopUpButton frame]] autorelease];
+        backgroundView = [[BDSKColoredView alloc] 
initWithFrame:[scalePopUpButton frame]];
         [backgroundView setTranslatesAutoresizingMaskIntoConstraints:NO];
         [containerView addSubview:backgroundView];
         [scalePopUpButton setTranslatesAutoresizingMaskIntoConstraints:NO];
-        [self setTranslatesAutoresizingMaskIntoConstraints:NO];
         [containerView addSubview:scalePopUpButton];
-        [containerView addSubview:self];
+        [containerView setTranslatesAutoresizingMaskIntoConstraints:NO];
+        [self addSubview:containerView];
         
         NSArray *constraints = [NSMutableArray arrayWithObjects:
             [NSLayoutConstraint constraintWithLeadingMargin:0.0 
forItem:backgroundView toItem:containerView],
@@ -294,14 +296,20 @@
             [NSLayoutConstraint constraintWithTopMargin:0.0 
forItem:backgroundView toItem:containerView],
             [NSLayoutConstraint constraintWithBottomMargin:0.0 
forItem:backgroundView toItem:containerView],
             [NSLayoutConstraint constraintWithLeadingMargin:2.0 
forItem:scalePopUpButton toItem:containerView],
-            [NSLayoutConstraint constraintWithLeadingMargin:0.0 forItem:self 
toItem:containerView],
-            [NSLayoutConstraint constraintWithTrailingMargin:0.0 forItem:self 
toItem:containerView],
-            [NSLayoutConstraint constraintWithBottomMargin:1.0 
forItem:scalePopUpButton toItem:containerView],
-            [NSLayoutConstraint constraintWithTopSpacing:0.0 
forItem:scalePopUpButton toItem:self],
-            [NSLayoutConstraint constraintWithTopMargin:0.0 forItem:self 
toItem:containerView], nil];
-        [[constraints lastObject] setPriority:NSLayoutPriorityDefaultHigh - 
1.0];
+            [NSLayoutConstraint constraintWithTrailingMargin:1.0 
forItem:scalePopUpButton toItem:containerView],
+            [NSLayoutConstraint constraintWithTopMargin:1.0 
forItem:scalePopUpButton toItem:containerView],
+            [NSLayoutConstraint constraintWithBottomMargin:1.0 
forItem:scalePopUpButton toItem:containerView], nil];
         [containerView addConstraints:constraints];
         
+        constraints = [NSMutableArray arrayWithObjects:
+            [NSLayoutConstraint constraintWithLeadingMargin:0.0 
forItem:containerView toItem:self],
+            [NSLayoutConstraint constraintWithBottomMargin:0.0 
forItem:containerView toItem:self], nil];
+        [self addConstraints:constraints];
+        
+        [[self scrollView] setAutomaticallyAdjustsContentInsets:NO];
+        [[self scrollView] setContentInsets:NSEdgeInsetsMake(0.0, 0.0, 
[scalePopUpButton intrinsicContentSize].height + 2.0, 0.0)];
+        [self updateScrollerInsets];
+        
         BDSKSetHasDefaultAppearance(self);
         BDSKSetHasLightAppearance([self scrollView]);
         [self handleScrollerStyleDidChange:nil];
@@ -315,6 +323,7 @@
         [super setAutoScales:YES];
     else
         [self setScaleFactor:[selectedFactorObject doubleValue] 
adjustPopup:NO];
+    [self updateScrollerInsets];
 }
 
 - (NSUInteger)lowerIndexForScaleFactor:(CGFloat)scaleFactor {
@@ -357,6 +366,7 @@
         } else {
             NSUInteger i = [self indexForScaleFactor:newScaleFactor];
             [scalePopUpButton selectItemAtIndex:i];
+            [self updateScrollerInsets];
             newScaleFactor = BDSKDefaultScaleMenuFactors[i];
         }
     }
@@ -370,8 +380,10 @@
 - (void)setAutoScales:(BOOL)newAuto {
     [super setAutoScales:newAuto];
     
-    if(newAuto)
+    if(newAuto) {
                [scalePopUpButton selectItemAtIndex:0];
+        [self updateScrollerInsets];
+    }
 }
 
 - (IBAction)zoomIn:(id)sender{

Modified: trunk/bibdesk/BDSKZoomableTextView.m
===================================================================
--- trunk/bibdesk/BDSKZoomableTextView.m        2022-08-23 09:26:12 UTC (rev 
27829)
+++ trunk/bibdesk/BDSKZoomableTextView.m        2022-08-23 15:39:40 UTC (rev 
27830)
@@ -50,6 +50,7 @@
 - (void)makeScalePopUpButton;
 - (void)scalePopUpAction:(id)sender;
 - (void)setScaleFactor:(CGFloat)factor adjustPopup:(BOOL)flag;
+- (void)updateScrollerInsets;
 
 @end
 
@@ -105,6 +106,10 @@
 
 #pragma mark Instance methods - scaling related
 
+- (void)updateScrollerInsets {
+    [[self enclosingScrollView] setScrollerInsets:NSEdgeInsetsMake(0.0, 
[scalePopUpButton intrinsicContentSize].width + 3.0, 0.0, 0.0)];
+}
+
 - (void)makeScalePopUpButton {
     if (scalePopUpButton == nil) {
         NSScrollView *scrollView = [self enclosingScrollView];
@@ -154,22 +159,44 @@
         [containerView setAutoresizingMask:NSViewWidthSizable | 
NSViewHeightSizable];
         [[scrollView superview] addSubview:containerView];
         
-        [scalePopUpButton setTranslatesAutoresizingMaskIntoConstraints:NO];
         [scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
-        [containerView addSubview:scalePopUpButton];
         [containerView addSubview:scrollView];
         
-        NSView *contentView = [containerView contentView];
+        NSBox *backgroundView = [[[NSBox alloc] initWithFrame:[scrollView 
frame]] autorelease];
+        [backgroundView setBoxType:NSBoxCustom];
+        [backgroundView setBorderType:NSNoBorder];
+        [backgroundView setTitlePosition:NSNoTitle];
+        [backgroundView setBorderWidth:0.0];
+        [backgroundView setContentViewMargins:NSZeroSize];
+        [backgroundView setFillColor:[self backgroundColor]];
+        [backgroundView setTranslatesAutoresizingMaskIntoConstraints:NO];
+        [containerView addSubview:backgroundView];
+        
+        [scalePopUpButton setTranslatesAutoresizingMaskIntoConstraints:NO];
+        [backgroundView addSubview:scalePopUpButton];
+        
+        NSView *contentView = [backgroundView contentView];
         NSArray *constraints = [NSArray arrayWithObjects:
             [NSLayoutConstraint constraintWithLeadingMargin:2.0 
forItem:scalePopUpButton toItem:contentView],
+            [NSLayoutConstraint constraintWithTrailingMargin:1.0 
forItem:scalePopUpButton toItem:contentView],
+            [NSLayoutConstraint constraintWithBottomMargin:1.0 
forItem:scalePopUpButton toItem:contentView],
+            [NSLayoutConstraint constraintWithTopMargin:1.0 
forItem:scalePopUpButton toItem:contentView], nil];
+        [contentView addConstraints:constraints];
+        
+        contentView = [containerView contentView];
+        constraints = [NSArray arrayWithObjects:
+            [NSLayoutConstraint constraintWithLeadingMargin:0.0 
forItem:backgroundView toItem:contentView],
             [NSLayoutConstraint constraintWithLeadingMargin:0.0 
forItem:scrollView toItem:contentView],
             [NSLayoutConstraint constraintWithTrailingMargin:0.0 
forItem:scrollView toItem:contentView],
-            [NSLayoutConstraint constraintWithBottomMargin:1.0 
forItem:scalePopUpButton toItem:contentView],
-            [NSLayoutConstraint constraintWithTopSpacing:0.0 
forItem:scalePopUpButton toItem:scrollView],
-            [NSLayoutConstraint constraintWithTopMargin:0.0 forItem:scrollView 
toItem:contentView], nil];
-        [[constraints lastObject] setPriority:NSLayoutPriorityDefaultHigh - 
1.0];
+            [NSLayoutConstraint constraintWithBottomMargin:0.0 
forItem:backgroundView toItem:contentView],
+            [NSLayoutConstraint constraintWithTopMargin:0.0 forItem:scrollView 
toItem:contentView],
+            [NSLayoutConstraint constraintWithBottomMargin:0.0 
forItem:scrollView toItem:contentView], nil];
         [contentView addConstraints:constraints];
         
+        [scrollView setAutomaticallyAdjustsContentInsets:NO];
+        [scrollView setContentInsets:NSEdgeInsetsMake(0.0, 0.0, 
[scalePopUpButton intrinsicContentSize].height + 2.0, 0.0)];
+        [self updateScrollerInsets];
+        
         if (RUNNING_AFTER(10_14)) {
             [scrollView setDrawsBackground:NO];
             [self setDrawsBackground:NO];
@@ -182,6 +209,9 @@
     NSView *containerView = [[[self enclosingScrollView] superview] superview];
     if ([containerView respondsToSelector:@selector(setFillColor:)])
         [(NSBox *)containerView setFillColor:backgroundColor];
+    containerView = [[scalePopUpButton superview] superview];
+    if ([containerView respondsToSelector:@selector(setFillColor:)])
+        [(NSBox *)containerView setFillColor:backgroundColor];
 }
 
 - (void)scalePopUpAction:(id)sender {
@@ -192,6 +222,7 @@
         return;
     } else {
         [self setScaleFactor:[selectedFactorObject doubleValue] 
adjustPopup:NO];
+        [self updateScrollerInsets];
     }
 }
 
@@ -228,6 +259,7 @@
        if (flag) {
             NSUInteger i = [self indexForScaleFactor:newScaleFactor];
             [scalePopUpButton selectItemAtIndex:i];
+            [self updateScrollerInsets];
             newScaleFactor = BDSKDefaultScaleMenuFactors[i];
     }
        

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to