Revision: 15008 http://sourceforge.net/p/skim-app/code/15008 Author: hofman Date: 2025-03-23 16:21:06 +0000 (Sun, 23 Mar 2025) Log Message: ----------- Set bezel width instead of 'frame' width
Modified Paths: -------------- trunk/SKColorSwatch.m Modified: trunk/SKColorSwatch.m =================================================================== --- trunk/SKColorSwatch.m 2025-03-23 09:44:53 UTC (rev 15007) +++ trunk/SKColorSwatch.m 2025-03-23 16:21:06 UTC (rev 15008) @@ -66,11 +66,11 @@ #define LARGE_SIZE_HEIGHT_OFFSET 10.0 #define LARGE_SIZE_WIDTH_OUTSET 6.0 -#define BACKGROUND_WIDTH_OFFSET 6.0 -#define SMALL_BACKGROUND_WIDTH_OFFSET 2.0 +#define BACKGROUND_WIDTH_OFFSET 4.0 +#define ALT_BACKGROUND_WIDTH_OFFSET 0.0 @interface SKColorSwatchBackgroundView : NSControl -@property (nonatomic) CGFloat width; +@property (nonatomic) CGFloat bezelWidth; @end typedef NS_ENUM(NSUInteger, SKColorSwatchDropLocation) { @@ -103,7 +103,6 @@ @interface SKColorSwatch () @property (nonatomic) NSInteger selectedColorIndex; -@property (nonatomic, readonly) CGFloat fitWidth; - (NSRect)frameForItemViewAtIndex:(NSInteger)anIndex collapsedIndex:(NSInteger)collapsedIndex; - (void)setColor:(NSColor *)color atIndex:(NSInteger)i fromPanel:(BOOL)fromPanel; @end @@ -111,7 +110,7 @@ @implementation SKColorSwatch @synthesize colors, autoResizes, selects, alternate, clickedColorIndex=clickedIndex, selectedColorIndex=selectedIndex; -@dynamic color, fitWidth; +@dynamic color; - (Class)valueClassForBinding:(NSString *)binding { if ([binding isEqualToString:COLORS_KEY]) @@ -143,7 +142,7 @@ SKColorSwatchBackgroundView *view = [[SKColorSwatchBackgroundView alloc] initWithFrame:[self bounds]]; [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; - [view setWidth:[self fitWidth]]; + [view setBezelWidth:[self intrinsicContentSize].width]; [self addSubview:view]; backgroundView = view; @@ -260,10 +259,6 @@ return size; } -- (CGFloat)fitWidth { - return [self sizeForNumberOfColors:[colors count]].width; -} - - (NSSize)intrinsicContentSize { return [self contentSizeForNumberOfColors:[colors count]]; } @@ -280,7 +275,7 @@ NSUInteger i, iMax = [itemViews count]; for (i = 0; i < iMax; i++) [[itemViews objectAtIndex:i] setFrame:[self frameForItemViewAtIndex:i collapsedIndex:-1]]; - [backgroundView setWidth:[self fitWidth]]; + [backgroundView setBezelWidth:[self intrinsicContentSize].width]; [self invalidateIntrinsicContentSize]; } @@ -622,7 +617,7 @@ for (SKColorSwatchItemView *itemView in itemViews) [[itemView animator] setFrame:[self frameForItemViewAtIndex:i++ collapsedIndex:collapsedIndex]]; if (NSEqualSizes(size, NSZeroSize) == NO) { - [[backgroundView animator] setWidth:size.width]; + [[backgroundView animator] setBezelWidth:size.width - 2.0 * BEZEL_INSET_LEFTRIGHT]; if (autoResizes) [[self animator] setFrameSize:size]; } @@ -879,7 +874,7 @@ @implementation SKColorSwatchBackgroundView -@dynamic width; +@dynamic bezelWidth; + (id)defaultAnimationForKey:(NSString *)key { if ([key isEqualToString:@"width"]) { @@ -890,10 +885,6 @@ return [super defaultAnimationForKey:key]; } -- (CGFloat)widthOffset { - return [self controlSize] == NSControlSizeRegular ? BACKGROUND_WIDTH_OFFSET : SMALL_BACKGROUND_WIDTH_OFFSET; -} - - (instancetype)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; if (self) { @@ -900,7 +891,7 @@ NSSegmentedCell *cell = [[NSSegmentedCell alloc] init]; [cell setSegmentCount:1]; [cell setSegmentStyle:NSSegmentStyleTexturedSquare]; - [cell setWidth:fmax(0.0, NSWidth(frameRect) - [self widthOffset]) forSegment:0]; + [cell setWidth:fmax(0.0, NSWidth(frameRect) - BACKGROUND_WIDTH_OFFSET - 2.0 * BEZEL_INSET_LEFTRIGHT) forSegment:0]; [self setCell:cell]; } return self; @@ -908,12 +899,14 @@ - (BOOL)canBecomeKeyView { return NO; } -- (CGFloat)width { - return [[self cell] widthForSegment:0] + [self widthOffset]; +#define WIDTH_OFFSET ([self controlSize] == NSControlSizeRegular ? BACKGROUND_WIDTH_OFFSET : ALT_BACKGROUND_WIDTH_OFFSET) + +- (CGFloat)bezelWidth { + return [[self cell] widthForSegment:0] + WIDTH_OFFSET; } -- (void)setWidth:(CGFloat)width { - [[self cell] setWidth:width - [self widthOffset] forSegment:0]; +- (void)setBezelWidth:(CGFloat)width { + [[self cell] setWidth:width - WIDTH_OFFSET forSegment:0]; [self setNeedsDisplay:YES]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit