Revision: 26739
          http://sourceforge.net/p/bibdesk/svn/26739
Author:   hofman
Date:     2021-08-25 23:17:21 +0000 (Wed, 25 Aug 2021)
Log Message:
-----------
Use auto layout for button and image view in address text field

Modified Paths:
--------------
    trunk/bibdesk/BDSKAddressTextField.m

Modified: trunk/bibdesk/BDSKAddressTextField.m
===================================================================
--- trunk/bibdesk/BDSKAddressTextField.m        2021-08-25 22:58:54 UTC (rev 
26738)
+++ trunk/bibdesk/BDSKAddressTextField.m        2021-08-25 23:17:21 UTC (rev 
26739)
@@ -39,6 +39,7 @@
 #import "BDSKAddressTextField.h"
 #import "BDSKAddressTextFieldCell.h"
 #import "BDSKDragImageView.h"
+#import "NSLayoutConstraint_BDSKExtensions.h"
 
 #define CONTROL_SIZE 16.0
 #define CONTROL_MARGIN_X 3.0
@@ -59,23 +60,21 @@
     if (RUNNING_BEFORE(10_10))
         [[self cell] setBezelStyle:NSTextFieldSquareBezel];
     if (imageView == nil) {
-        NSRect rect, bounds = [self bounds];
-        rect.origin.x = CONTROL_MARGIN_X;
-        rect.origin.y = [self isFlipped] ? NSMaxY(bounds) - CONTROL_SIZE - 
CONTROL_MARGIN_Y : NSMinY(bounds) + CONTROL_MARGIN_Y;
-        rect.size.width = rect.size.height = CONTROL_SIZE;
-        imageView = [[BDSKDragImageView alloc] initWithFrame:rect];
+        imageView = [[BDSKDragImageView alloc] init];
         [imageView setImageScaling:NSImageScaleProportionallyUpOrDown];
-        [imageView setAutoresizingMask:NSViewMaxXMargin | NSViewMaxYMargin];
         [imageView setRefusesFirstResponder:YES];
+        [imageView setTranslatesAutoresizingMaskIntoConstraints:NO];
         [(BDSKDragImageView *)imageView setDelegate:self];
+        [imageView addConstraints:[NSArray arrayWithObjects:
+            [NSLayoutConstraint constraintWithWidth:CONTROL_SIZE 
forItem:imageView],
+            [NSLayoutConstraint constraintWithHeight:CONTROL_SIZE 
forItem:imageView], nil]];
         [self addSubview:imageView];
+        [self addConstraints:[NSArray arrayWithObjects:
+            [NSLayoutConstraint constraintWithLeadingMargin:CONTROL_MARGIN_X 
forItem:imageView toItem:self],
+            [NSLayoutConstraint constraintWithBottomMargin:CONTROL_MARGIN_Y 
forItem:imageView toItem:self], nil]];
     }
     if (button == nil) {
-        NSRect rect, bounds = [self bounds];
-        rect.origin.x = NSMaxX(bounds) - CONTROL_SIZE - CONTROL_MARGIN_X;
-        rect.origin.y = [self isFlipped] ? NSMaxY(bounds) - CONTROL_SIZE - 
CONTROL_MARGIN_Y : NSMinY(bounds) + CONTROL_MARGIN_Y;
-        rect.size.width = rect.size.height = CONTROL_SIZE;
-        button = [[NSButton alloc] initWithFrame:rect];
+        button = [[NSButton alloc] init];
         [button setButtonType:NSMomentaryChangeButton];
         [button setBordered:NO];
         [button setImagePosition:NSImageOnly];
@@ -82,7 +81,14 @@
         [[button cell] setImageScaling:NSImageScaleProportionallyDown];
         [button setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
         [button setRefusesFirstResponder:YES];
+        [button setTranslatesAutoresizingMaskIntoConstraints:NO];
+        [button addConstraints:[NSArray arrayWithObjects:
+            [NSLayoutConstraint constraintWithWidth:CONTROL_SIZE 
forItem:button],
+            [NSLayoutConstraint constraintWithHeight:CONTROL_SIZE 
forItem:button], nil]];
         [self addSubview:button];
+        [self addConstraints:[NSArray arrayWithObjects:
+            [NSLayoutConstraint constraintWithTrailingMargin:CONTROL_MARGIN_X 
forItem:button toItem:self],
+            [NSLayoutConstraint constraintWithBottomMargin:CONTROL_MARGIN_Y 
forItem:button toItem:self], nil]];
     }
 }
 

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

Reply via email to