Revision: 14992 http://sourceforge.net/p/skim-app/code/14992 Author: hofman Date: 2025-03-20 17:37:33 +0000 (Thu, 20 Mar 2025) Log Message: ----------- Always relayout color swatch when control size changes. Support large control size, but we need to offset the reported size and pllacement of the segmented cell.
Modified Paths: -------------- trunk/SKColorSwatch.m Modified: trunk/SKColorSwatch.m =================================================================== --- trunk/SKColorSwatch.m 2025-03-20 10:16:57 UTC (rev 14991) +++ trunk/SKColorSwatch.m 2025-03-20 17:37:33 UTC (rev 14992) @@ -63,6 +63,9 @@ #define BEZEL_INSET_BOTTOM 2.0 #define COLOR_INSET 2.0 +#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 @@ -302,10 +305,16 @@ } - (void)setControlSize:(NSControlSize)controlSize { - [super setControlSize:controlSize]; - [backgroundView setControlSize:controlSize > NSControlSizeMini ? NSControlSizeRegular : controlSize]; - if ([self window]) { + if (controlSize != [self controlSize]) { + [super setControlSize:controlSize]; + [backgroundView setControlSize:controlSize]; CGFloat height = [[backgroundView cell] cellSize].height - BEZEL_INSET_TOP - BEZEL_INSET_BOTTOM; + if (controlSize == 3) { + height -= LARGE_SIZE_HEIGHT_OFFSET; + [backgroundView setFrame:NSInsetRect([self bounds], -LARGE_SIZE_WIDTH_OUTSET, 0.0)]; + } else { + [backgroundView setFrame:[self bounds]]; + } if (fabs(height - bezelHeight) > 0.0) { bezelHeight = height; [self updateSubviewLayout]; @@ -353,6 +362,8 @@ [super viewDidMoveToWindow]; if ([self window]) { CGFloat height = [[backgroundView cell] cellSize].height - BEZEL_INSET_TOP - BEZEL_INSET_BOTTOM; + if ([self controlSize] == 3) + height -= LARGE_SIZE_HEIGHT_OFFSET; if (fabs(height - bezelHeight) > 0.0) { bezelHeight = height; [self updateSubviewLayout]; @@ -491,6 +502,7 @@ itemView = [itemViews objectAtIndex:i]; } else { itemView = [[SKColorSwatchItemView alloc] init]; + [itemView setAutoresizingMask:NSViewNotSizable]; [self addSubview:itemView]; [itemViews addObject:itemView]; } @@ -882,7 +894,7 @@ } - (CGFloat)widthOffset { - return [self controlSize] == NSControlSizeSmall || [self controlSize] == NSControlSizeMini ? SMALL_BACKGROUND_WIDTH_OFFSET : BACKGROUND_WIDTH_OFFSET; + return [self controlSize] == NSControlSizeRegular ? BACKGROUND_WIDTH_OFFSET : SMALL_BACKGROUND_WIDTH_OFFSET; } - (instancetype)initWithFrame:(NSRect)frameRect { @@ -891,7 +903,7 @@ NSSegmentedCell *cell = [[NSSegmentedCell alloc] init]; [cell setSegmentCount:1]; [cell setSegmentStyle:NSSegmentStyleTexturedSquare]; - [cell setWidth:fmax(0.0, NSWidth(frameRect) - BACKGROUND_WIDTH_OFFSET) forSegment:0]; + [cell setWidth:fmax(0.0, NSWidth(frameRect) - [self widthOffset]) forSegment:0]; [self setCell:cell]; } return self; @@ -900,11 +912,11 @@ - (BOOL)canBecomeKeyView { return NO; } - (CGFloat)width { - return [[self cell] widthForSegment:0] + BACKGROUND_WIDTH_OFFSET; + return [[self cell] widthForSegment:0] + [self widthOffset]; } - (void)setWidth:(CGFloat)width { - [[self cell] setWidth:width - BACKGROUND_WIDTH_OFFSET forSegment:0]; + [[self cell] setWidth:width - [self widthOffset] 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