From 65cac6b19a87344b25ec235009248e6784076566 Mon Sep 17 00:00:00 2001 From: relikd Date: Thu, 11 Dec 2025 15:21:14 +0100 Subject: [PATCH] feat: expose more NSView methods --- baRSS/Helper/DrawImage.h | 1 + baRSS/Helper/DrawImage.m | 4 ++++ baRSS/NSCategories/NSView+Ext.h | 3 +++ baRSS/NSCategories/NSView+Ext.m | 3 +++ 4 files changed, 11 insertions(+) diff --git a/baRSS/Helper/DrawImage.h b/baRSS/Helper/DrawImage.h index 64af52e..fe7aec2 100644 --- a/baRSS/Helper/DrawImage.h +++ b/baRSS/Helper/DrawImage.h @@ -4,6 +4,7 @@ IB_DESIGNABLE @interface DrawSeparator : NSView @property (assign) BOOL invert; ++ (instancetype)withSize:(NSSize)size; @end diff --git a/baRSS/Helper/DrawImage.m b/baRSS/Helper/DrawImage.m index 764289e..491a74f 100644 --- a/baRSS/Helper/DrawImage.m +++ b/baRSS/Helper/DrawImage.m @@ -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]; diff --git a/baRSS/NSCategories/NSView+Ext.h b/baRSS/NSCategories/NSView+Ext.h index cd4393c..179ffa2 100644 --- a/baRSS/NSCategories/NSView+Ext.h +++ b/baRSS/NSCategories/NSView+Ext.h @@ -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; diff --git a/baRSS/NSCategories/NSView+Ext.m b/baRSS/NSCategories/NSView+Ext.m index 2d6a745..8e7d06d 100644 --- a/baRSS/NSCategories/NSView+Ext.m +++ b/baRSS/NSCategories/NSView+Ext.m @@ -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);