Revision: 12156
          http://sourceforge.net/p/skim-app/code/12156
Author:   hofman
Date:     2021-03-02 15:41:43 +0000 (Tue, 02 Mar 2021)
Log Message:
-----------
Ivar for bezel height, set it according to background cell height when moving 
to a window, it is larger in the toolbar

Modified Paths:
--------------
    trunk/SKColorSwatch.h
    trunk/SKColorSwatch.m

Modified: trunk/SKColorSwatch.h
===================================================================
--- trunk/SKColorSwatch.h       2021-03-02 15:10:39 UTC (rev 12155)
+++ trunk/SKColorSwatch.h       2021-03-02 15:41:43 UTC (rev 12156)
@@ -46,6 +46,8 @@
     NSMutableArray *colors;
     NSMutableArray *itemViews;
     SKColorSwatchBackgroundView *backgroundView;
+    CGFloat bezelHeight;
+    
     NSInteger clickedIndex;
     NSInteger selectedIndex;
     NSInteger focusedIndex;

Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m       2021-03-02 15:10:39 UTC (rev 12155)
+++ trunk/SKColorSwatch.m       2021-03-02 15:41:43 UTC (rev 12156)
@@ -58,12 +58,10 @@
 
 #define COLOR_KEY       @"color"
 
-#define BEZEL_HEIGHT    22.0
-#define BEZEL_INSET_LR  1.0
-#define BEZEL_INSET_T   1.0
-#define BEZEL_INSET_B   2.0
-#define COLOR_INSET     2.0
-#define COLOR_DISTANCE  19.0
+#define BEZEL_INSET_LEFTRIGHT   1.0
+#define BEZEL_INSET_TOP         1.0
+#define BEZEL_INSET_BOTTOM      2.0
+#define COLOR_INSET             2.0
 
 #define BACKGROUND_WIDTH_OFFSET 6.0
 
@@ -130,6 +128,8 @@
     selectedIndex = -1;
     draggedIndex = -1;
     
+    bezelHeight = 22.0;
+    
     [self registerForDraggedTypes:[NSColor 
readableTypesForPasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]]];
 }
 
@@ -142,6 +142,8 @@
         autoResizes = YES;
         selects = NO;
         
+        [self commonInit];
+        
         SKColorSwatchBackgroundView *view = [[SKColorSwatchBackgroundView 
alloc] initWithFrame:[self bounds]];
         [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
         [view setWidth:[self fitWidth]];
@@ -154,7 +156,6 @@
         [self addSubview:itemView];
         itemViews = [[NSMutableArray alloc] initWithObjects:itemView, nil];
         [itemView release];
-        [self commonInit];
     }
     return self;
 }
@@ -168,6 +169,8 @@
         autoResizes = [decoder decodeBoolForKey:AUTORESIZES_KEY];
         selects = [decoder decodeBoolForKey:SELECTS_KEY];
         
+        [self commonInit];
+        
         itemViews = [[NSMutableArray alloc] init];
         
         for (NSView *view in [self subviews]) {
@@ -176,8 +179,6 @@
             else if ([view isKindOfClass:[SKColorSwatchItemView class]])
                 [itemViews addObject:view];
         }
-        
-        [self commonInit];
     }
     return self;
 }
@@ -207,16 +208,20 @@
 
 #pragma mark Layout
 
+- (CGFloat)distanceBetweenColors {
+    return bezelHeight - COLOR_INSET;
+}
+
 - (NSSize)contentSizeForNumberOfColors:(NSUInteger)count {
-    return NSMakeSize(BEZEL_HEIGHT + (count - 1) * COLOR_DISTANCE, 
BEZEL_HEIGHT);
+    return NSMakeSize(bezelHeight + (count - 1) * [self 
distanceBetweenColors], bezelHeight);
 }
 
 - (NSRect)frameForColorAtIndex:(NSInteger)anIndex {
     NSEdgeInsets insets = [self alignmentRectInsets];
-    NSRect rect = NSMakeRect(insets.left, insets.bottom, BEZEL_HEIGHT, 
BEZEL_HEIGHT);
+    NSRect rect = NSMakeRect(insets.left, insets.bottom, bezelHeight, 
bezelHeight);
     rect = NSInsetRect(rect, COLOR_INSET, COLOR_INSET);
     if (anIndex > 0)
-        rect.origin.x += anIndex * COLOR_DISTANCE;
+        rect.origin.x += anIndex * [self distanceBetweenColors];
     return rect;
 }
 
@@ -226,7 +231,7 @@
         i--;
     NSRect rect = NSInsetRect([self frameForColorAtIndex:i], -1.0, -1.0);
     if (collapsedIndex == anIndex)
-        rect.size.width -= COLOR_DISTANCE;
+        rect.size.width -= [self distanceBetweenColors];
     return rect;
 }
 
@@ -237,7 +242,7 @@
     for (i = 0; i < count; i++) {
         if (NSMouseInRect(point, rect, [self isFlipped]))
             return i;
-        rect.origin.x += COLOR_DISTANCE;
+        rect.origin.x += [self distanceBetweenColors];
     }
     return -1;
 }
@@ -250,7 +255,7 @@
     for (i = 0; i < count; i++) {
         if (point.x < x)
             return i;
-        x += COLOR_DISTANCE;
+        x += [self distanceBetweenColors];
     }
     return count;
 }
@@ -276,7 +281,7 @@
 }
 
 - (NSEdgeInsets)alignmentRectInsets {
-    return NSEdgeInsetsMake(BEZEL_INSET_T, BEZEL_INSET_LR, BEZEL_INSET_B, 
BEZEL_INSET_LR);
+    return NSEdgeInsetsMake(BEZEL_INSET_TOP, BEZEL_INSET_LEFTRIGHT, 
BEZEL_INSET_BOTTOM, BEZEL_INSET_LEFTRIGHT);
 }
 
 - (void)updateSubviewLayout {
@@ -336,8 +341,15 @@
 
 - (void)viewDidMoveToWindow {
     [super viewDidMoveToWindow];
-    if ([self window])
-        [self handleKeyOrMainStateChanged:nil];
+    if ([self window]) {
+        CGFloat height = [[backgroundView cell] cellSize].height - 
BEZEL_INSET_TOP - BEZEL_INSET_BOTTOM;
+        if (fabs(height - bezelHeight) > 0.0) {
+            bezelHeight = height;
+            [self updateSubviewLayout];
+            if (autoResizes)
+                [self sizeToFit];
+        }
+    }
 }
 
 #pragma mark Event handling and actions

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to