FIXED: Before this PR, only CPControl could use nib2cib-adjustment-frame. (#2831)

This commit is contained in:
Didier Korthoudt
2020-03-11 10:17:14 +01:00
committed by GitHub
parent 82e55b4761
commit a4ef18ddab
4 changed files with 38 additions and 28 deletions
+1 -2
View File
@@ -137,8 +137,7 @@ var CPControlBlackColor = [CPColor blackColor];
@"image-position": CPImageLeft,
@"image-scaling": CPScaleToFit,
@"min-size": CGSizeMakeZero(),
@"max-size": CGSizeMake(-1.0, -1.0),
@"nib2cib-adjustment-frame": CGRectMakeZero()
@"max-size": CGSizeMake(-1.0, -1.0)
};
}
+2 -1
View File
@@ -332,7 +332,8 @@ var CPViewHighDPIDrawingEnabled = YES;
+ (CPDictionary)themeAttributes
{
return @{
@"css-based": NO
@"css-based": NO,
@"nib2cib-adjustment-frame": CGRectMakeZero()
};
}
-25
View File
@@ -25,10 +25,6 @@
@import "NSCell.j"
@import "NSView.j"
@class Nib2Cib
@implementation CPControl (NSCoding)
- (id)NS_initWithCoder:(CPCoder)aCoder
@@ -68,27 +64,6 @@
[self setControlSize:[cell controlSize]];
}
- (CGRect)_nib2CibAdjustment
{
// Theme has not been loaded yet.
// Get attribute value directly from the theme or from the default value of the object otherwise.
var theme = [Nib2Cib defaultTheme];
return [theme valueForAttributeWithName:@"nib2cib-adjustment-frame" inState:[self themeState] forClass:[self class]] || [self currentValueForThemeAttribute:@"nib2cib-adjustment-frame"];
}
- (void)_adjustNib2CibSize
{
var frame = [self frame],
frameAdjustment = [self _nib2CibAdjustment];
if (frameAdjustment)
{
var finalFrame = CGRectMake(frame.origin.x + frameAdjustment.origin.x, frame.origin.y - frameAdjustment.origin.y, frame.size.width + frameAdjustment.size.width, frame.size.height + frameAdjustment.size.height);
[self setFrame:finalFrame];
}
}
@end
@implementation NSControl : CPControl
+35
View File
@@ -25,6 +25,7 @@
@import <AppKit/CPView.j>
@class Nib2Cib
var NSViewAutoresizingMask = 0x3F,
NSViewAutoresizesSubviewsMask = 1 << 8,
@@ -117,6 +118,40 @@ var NSViewAutoresizingMask = 0x3F,
[self setAutoresizingMask:autoresizingMask];
}
- (CGRect)_nib2CibAdjustment
{
// Theme has not been loaded yet.
// Get attribute value directly from the theme or from the default value of the object otherwise.
var theme = [Nib2Cib defaultTheme],
frameAdjustment = [theme valueForAttributeWithName:@"nib2cib-adjustment-frame" inState:[self themeState] forClass:[self class]];
if (frameAdjustment)
return frameAdjustment;
if ([self hasThemeAttribute:@"nib2cib-adjustment-frame"])
{
frameAdjustment = [self currentValueForThemeAttribute:@"nib2cib-adjustment-frame"];
if (frameAdjustment)
return frameAdjustment;
}
return nil;
}
- (void)_adjustNib2CibSize
{
var frame = [self frame],
frameAdjustment = [self _nib2CibAdjustment];
if (frameAdjustment)
{
var finalFrame = CGRectMake(frame.origin.x + frameAdjustment.origin.x, frame.origin.y - frameAdjustment.origin.y, frame.size.width + frameAdjustment.size.width, frame.size.height + frameAdjustment.size.height);
[self setFrame:finalFrame];
}
}
@end
@implementation NSView : CPView