feat: expose more NSView methods

This commit is contained in:
relikd
2025-12-11 15:21:14 +01:00
parent 2ec1743dd9
commit 65cac6b19a
4 changed files with 11 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
IB_DESIGNABLE
@interface DrawSeparator : NSView
@property (assign) BOOL invert;
+ (instancetype)withSize:(NSSize)size;
@end

View File

@@ -5,6 +5,10 @@
@implementation DrawSeparator
+ (instancetype)withSize:(NSSize)size {
return [[super alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
}
- (void)drawRect:(NSRect)r {
NSColor *color = [NSColor darkGrayColor];
NSColor *transparent = [color colorWithAlphaComponent:0.0];

View File

@@ -61,7 +61,10 @@ static inline CGFloat NSMaxWidth(NSView *a, NSView *b) { return Max(NSWidth(a.fr
- (instancetype)placeIn:(NSView*)parent xRight:(CGFloat)x y:(CGFloat)y;
- (instancetype)placeIn:(NSView*)parent xRight:(CGFloat)x yTop:(CGFloat)y;
// Modify existing UI elements
- (instancetype)alignTop;
- (instancetype)alignRight;
- (instancetype)sizableWidthAndHeight;
- (instancetype)sizableWidth;
- (instancetype)sizeToRight:(CGFloat)rightPadding;
- (instancetype)sizeWidthToFit;
- (instancetype)tooltip:(NSString*)tt;

View File

@@ -269,6 +269,9 @@
/// Modify @c .autoresizingMask; Add @c NSViewWidthSizable @c | @c NSViewHeightSizable flags
- (instancetype)sizableWidthAndHeight { self.autoresizingMask |= NSViewWidthSizable | NSViewHeightSizable; return self; }
/// Modify @c .autoresizingMask; Add @c NSViewWidthSizable flags
- (instancetype)sizableWidth { self.autoresizingMask |= NSViewWidthSizable; return self; }
/// Extend frame in its @c superview and stick to right with padding. Adds @c NSViewWidthSizable to @c autoresizingMask
- (instancetype)sizeToRight:(CGFloat)rightPadding {
SetFrameWidth(self, NSWidth(self.superview.frame) - NSMinX(self.frame) - rightPadding + self.alignmentRectInsets.right);