Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
74dae2f6 by Claudio Cambra at 2026-01-20T07:16:10+00:00
macosx: Store and cache title attributes and height in 
VLCLibraryHomeViewActionButtonCell

Signed-off-by: Claudio Cambra <[email protected]>

- - - - -
6ef7f72c by Claudio Cambra at 2026-01-20T07:16:10+00:00
macosx: Break away image rendering in aciton button cell into drawImage

Signed-off-by: Claudio Cambra <[email protected]>

- - - - -
9daf4438 by Claudio Cambra at 2026-01-20T07:16:10+00:00
macosx: Break away title rendering in action button cell into drawTitle

Signed-off-by: Claudio Cambra <[email protected]>

- - - - -
806ee58c by Claudio Cambra at 2026-01-20T07:16:10+00:00
macosx: Break away bezel rendering in action button cell into drawBezel

Signed-off-by: Claudio Cambra <[email protected]>

- - - - -
f39b1c2c by Claudio Cambra at 2026-01-20T07:16:10+00:00
macosx: FInish leveraging intended methods for button cell customisation in 
VLCLibraryHomeViewActionsView

Signed-off-by: Claudio Cambra <[email protected]>

- - - - -


1 changed file:

- modules/gui/macosx/library/home-library/VLCLibraryHomeViewActionButtonCell.m


Changes:

=====================================
modules/gui/macosx/library/home-library/VLCLibraryHomeViewActionButtonCell.m
=====================================
@@ -32,56 +32,64 @@
 @property BOOL prevIsHighlighted;
 @property NSRect prevFrame;
 
+@property (readonly) NSDictionary<NSAttributedStringKey, id> 
*cachedTitleAttributes;
+@property (readonly) CGFloat cachedTitleHeight;
+
 @end
 
 @implementation VLCLibraryHomeViewActionButtonCell
 
-- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
+- (NSRect)titleRectForBounds:(NSRect)bounds
 {
-    [NSColor.VLCSubtleBorderColor setStroke];
-    [NSColor.windowBackgroundColor setFill];
-
-    const CGFloat cellMinX = NSMinX(cellFrame);
-    const CGFloat cellMinY = NSMinY(cellFrame);
-    const CGFloat cellMaxX = NSMaxX(cellFrame);
-    const CGFloat cellMaxY = NSMaxY(cellFrame);
-
-    NSBezierPath * const separatorPath =
-        [NSBezierPath bezierPathWithRoundedRect:cellFrame
-                                        xRadius:VLCLibraryUIUnits.cornerRadius
-                                        
yRadius:VLCLibraryUIUnits.cornerRadius];
-    separatorPath.lineWidth = VLCLibraryUIUnits.borderThickness;
-    [separatorPath stroke];
-    [separatorPath fill];
+    return bounds;
+}
 
-    const CGSize cellSize = cellFrame.size;
-    const CGFloat cellWidth = cellSize.width;
-    const CGFloat cellHeight = cellSize.height;
+- (NSRect)imageRectForBounds:(NSRect)bounds
+{
+    return bounds;
+}
 
+- (NSDictionary<NSAttributedStringKey, id> *)titleAttributes
+{
+    if (_cachedTitleAttributes) {
+        return _cachedTitleAttributes;
+    }
     NSMutableParagraphStyle * const titleParagraphStyle = 
[[NSMutableParagraphStyle alloc] init];
     titleParagraphStyle.alignment = NSTextAlignmentCenter;
-    NSDictionary<NSAttributedStringKey, id> * const titleAttributes = @{
+    _cachedTitleAttributes = @{
         NSForegroundColorAttributeName: NSColor.controlTextColor,
         NSFontAttributeName: NSFont.VLCLibrarySubsectionSubheaderFont,
         NSParagraphStyleAttributeName: titleParagraphStyle
     };
-    const NSSize titleSize = [self.title sizeWithAttributes:titleAttributes];
-    const CGFloat titleHeight = titleSize.height + 
VLCLibraryUIUnits.smallSpacing;
-    [self.title drawInRect:CGRectMake(cellMinX + 
VLCLibraryUIUnits.smallSpacing,
-                                      cellMaxY - titleHeight,
-                                      cellWidth - 
VLCLibraryUIUnits.smallSpacing * 2,
-                                      titleHeight)
-            withAttributes:titleAttributes];
+    return _cachedTitleAttributes;
+}
+
+- (CGFloat)titleHeightWithAttributes:(NSDictionary<NSAttributedStringKey, id> 
*)attributes
+{
+    if (_cachedTitleHeight) {
+        return _cachedTitleHeight;
+    }
+    const NSSize titleSize = [self.title sizeWithAttributes:attributes];
+    _cachedTitleHeight = titleSize.height + VLCLibraryUIUnits.smallSpacing;
+    return _cachedTitleHeight;
+}
+
+- (void)drawImage:(NSImage *)image withFrame:(NSRect)frame inView:(NSView 
*)controlView
+{
+    const CGSize cellSize = frame.size;
+    const CGFloat cellWidth = cellSize.width;
+    const CGFloat cellHeight = cellSize.height;
+    const CGFloat titleHeight = [self titleHeightWithAttributes:[self 
titleAttributes]];
 
     const CGSize imageSize = self.image.size;
 
     if (self.cachedImage != self.image ||
         self.prevIsHighlighted != self.isHighlighted ||
-        !NSEqualRects(self.prevFrame, cellFrame)) {
+        !NSEqualRects(self.prevFrame, frame)) {
 
         self.cachedImage = [NSImage imageWithSize:imageSize
                                           flipped:NO
-                                   drawingHandler:^BOOL(NSRect dstRect) {
+                                   drawingHandler:^BOOL(NSRect __unused 
dstRect) {
             if (self.isHighlighted) {
                 [NSColor.VLCSubtleBorderColor set];
             } else {
@@ -94,7 +102,7 @@
         }];
 
         self.prevIsHighlighted = self.isHighlighted;
-        self.prevFrame = cellFrame;
+        self.prevFrame = frame;
     } 
 
     const CGFloat originalImageAspectRatio = imageSize.width / 
imageSize.height;
@@ -111,7 +119,7 @@
         imageHeight = imageWidth / originalImageAspectRatio;
     }
 
-    const CGPoint cellOrigin = cellFrame.origin;
+    const CGPoint cellOrigin = frame.origin;
     const NSRect imageRect = NSMakeRect(cellOrigin.x + (cellWidth - 
imageWidth) / 2,
                                         cellOrigin.y + (cellHeight - 
imageHeight) / 2,
                                         imageWidth,
@@ -119,4 +127,35 @@
     [self.cachedImage drawInRect:imageRect];
 }
 
+- (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)cellFrame 
inView:(NSView *)controlView
+{
+    const CGFloat cellMinX = NSMinX(cellFrame);
+    const CGFloat cellMaxY = NSMaxY(cellFrame);
+    const CGSize cellSize = cellFrame.size;
+    const CGFloat cellWidth = cellSize.width;
+
+    NSDictionary<NSAttributedStringKey, id> * const titleAttributes = [self 
titleAttributes];
+    const CGFloat titleHeight = [self 
titleHeightWithAttributes:titleAttributes];
+    const NSRect titleRect = CGRectMake(cellMinX + 
VLCLibraryUIUnits.smallSpacing,
+                                      cellMaxY - titleHeight,
+                                      cellWidth - 
VLCLibraryUIUnits.smallSpacing * 2,
+                                      titleHeight);
+    [self.title drawInRect:titleRect withAttributes:titleAttributes];
+    return titleRect;
+}
+
+- (void)drawBezelWithFrame:(NSRect)frame inView:(NSView *)controlView
+{
+    [NSColor.VLCSubtleBorderColor setStroke];
+    [NSColor.windowBackgroundColor setFill];
+
+    NSBezierPath * const separatorPath =
+        [NSBezierPath bezierPathWithRoundedRect:frame
+                                        xRadius:VLCLibraryUIUnits.cornerRadius
+                                        
yRadius:VLCLibraryUIUnits.cornerRadius];
+    separatorPath.lineWidth = VLCLibraryUIUnits.borderThickness;
+    [separatorPath stroke];
+    [separatorPath fill];
+}
+
 @end



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/d2db1d61e42bc59211b057abc4838d1fcee936d0...f39b1c2ca24b334d34133b6a0a0d8c20a3f93e20

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/d2db1d61e42bc59211b057abc4838d1fcee936d0...f39b1c2ca24b334d34133b6a0a0d8c20a3f93e20
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to