[vlc-commits] [Git][videolan/vlc][master] 6 commits: macosx: Connect outlet for 1:1 aspect ratio for image view in VLCLibraryCollectionViewItem

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Jan 16 17:19:50 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
7f2eccd1 by Claudio Cambra at 2023-01-16T16:52:09+00:00
macosx: Connect outlet for 1:1 aspect ratio for image view in VLCLibraryCollectionViewItem

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
eaa998e6 by Claudio Cambra at 2023-01-16T16:52:09+00:00
macosx: Make aspect ratio for VLCLibraryCollectionViewItem 16:10 when it is representing a video media item

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
867da29a by Claudio Cambra at 2023-01-16T16:52:09+00:00
macosx: Add defaultVideoItemSize class method to VLCLibraryCollectionViewItem

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
6f800b94 by Claudio Cambra at 2023-01-16T16:52:09+00:00
macosx: Cut down on use of magic numbers in VLCLibraryCollectionViewItem, use const methods for values

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
4e0e5261 by Claudio Cambra at 2023-01-16T16:52:09+00:00
macosx: Make VLCLibraryCollectionViewDelegate correctly size for video collection view items

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
894ecb9f by Claudio Cambra at 2023-01-16T16:52:09+00:00
macosx: Ensure all library video collection view items are sized correctly

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


11 changed files:

- modules/gui/macosx/UI/VLCLibraryCollectionViewItem.xib
- modules/gui/macosx/library/VLCLibraryCollectionViewDelegate.h
- modules/gui/macosx/library/VLCLibraryCollectionViewDelegate.m
- modules/gui/macosx/library/VLCLibraryCollectionViewItem.h
- modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
- modules/gui/macosx/library/VLCLibraryUIUnits.h
- modules/gui/macosx/library/VLCLibraryUIUnits.m
- modules/gui/macosx/library/VLCLibraryWindow.m
- modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m
- modules/gui/macosx/library/media-source/VLCMediaSourceDataSource.m
- modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerView.m


Changes:

=====================================
modules/gui/macosx/UI/VLCLibraryCollectionViewItem.xib
=====================================
@@ -9,12 +9,13 @@
             <connections>
                 <outlet property="addToPlaylistButton" destination="Ubz-8I-W2F" id="k0q-b1-PZi"/>
                 <outlet property="annotationTextField" destination="tm2-NW-WsZ" id="Miy-RS-Rol"/>
-                <outlet property="secondaryInfoTextField" destination="VAn-gF-QiZ" id="U8T-Cs-HaL"/>
                 <outlet property="highlightBox" destination="Vwd-1n-Sbd" id="h1g-hL-1gh"/>
+                <outlet property="imageViewAspectRatioConstraint" destination="f7c-vp-30m" id="2As-9A-WOn"/>
                 <outlet property="mediaImageView" destination="2aB-sB-hfY" id="Sv0-G1-KNm"/>
                 <outlet property="mediaTitleTextField" destination="OBS-Eh-1mT" id="h1n-PU-IAx"/>
                 <outlet property="playInstantlyButton" destination="S3I-5Z-qgS" id="JlC-bE-i5Y"/>
                 <outlet property="progressIndicator" destination="dFt-oZ-h9P" id="JC6-gk-Mid"/>
+                <outlet property="secondaryInfoTextField" destination="VAn-gF-QiZ" id="U8T-Cs-HaL"/>
                 <outlet property="unplayedIndicatorTextField" destination="u2r-zy-XEW" id="56s-K4-Kxr"/>
                 <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
             </connections>


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewDelegate.h
=====================================
@@ -22,12 +22,15 @@
 
 #import <Cocoa/Cocoa.h>
 
+#import "VLCLibraryUIUnits.h"
+
 NS_ASSUME_NONNULL_BEGIN
 
 @interface VLCLibraryCollectionViewDelegate : NSObject <NSCollectionViewDelegate, NSCollectionViewDelegateFlowLayout>
 
 @property (readwrite, assign) BOOL dynamicItemSizing;
 @property (readwrite, assign) NSSize staticItemSize;
+ at property (readwrite, assign) VLCLibraryCollectionViewItemAspectRatio itemsAspectRatio;
 
 @end
 


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewDelegate.m
=====================================
@@ -26,7 +26,6 @@
 #import "VLCLibraryCollectionViewFlowLayout.h"
 #import "VLCLibraryCollectionViewItem.h"
 #import "VLCLibraryDataTypes.h"
-#import "VLCLibraryUIUnits.h"
 
 @implementation VLCLibraryCollectionViewDelegate
 
@@ -36,6 +35,7 @@
     if (self) {
         _dynamicItemSizing = YES;
         _staticItemSize = [VLCLibraryCollectionViewItem defaultSize];
+        _itemsAspectRatio = VLCLibraryCollectionViewItemAspectRatioDefaultItem;
     }
     return self;
 }
@@ -78,7 +78,8 @@
     if (collectionViewLayout) {
         VLCLibraryCollectionViewFlowLayout *collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout*)collectionViewLayout;
         return [VLCLibraryUIUnits adjustedCollectionViewItemSizeForCollectionView:collectionView
-                                                                       withLayout:collectionViewFlowLayout];
+                                                                       withLayout:collectionViewFlowLayout
+                                                             withItemsAspectRatio:_itemsAspectRatio];
     }
 
     return NSZeroSize;


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewItem.h
=====================================
@@ -32,9 +32,12 @@ extern NSString *VLCLibraryCellIdentifier;
 
 @interface VLCLibraryCollectionViewItem : NSCollectionViewItem
 
-// NOTE: These will need to be changed after changed to XIB
-+ (NSSize)defaultSize;
-+ (CGFloat)bottomTextViewsHeight;
+// NOTE: These will need to be changed after changes to XIB
++ (const NSSize)defaultSize;
++ (const NSSize)defaultVideoItemSize;
++ (const CGFloat)defaultWidth;
++ (const CGFloat)bottomTextViewsHeight;
++ (const CGFloat)videoHeightAspectRatioMultiplier;
 
 @property (readwrite, assign) IBOutlet NSTextField *mediaTitleTextField;
 @property (readwrite, assign) IBOutlet NSTextField *annotationTextField;
@@ -45,6 +48,7 @@ extern NSString *VLCLibraryCellIdentifier;
 @property (readwrite, assign) IBOutlet NSButton *addToPlaylistButton;
 @property (readwrite, assign) IBOutlet VLCLinearProgressIndicator *progressIndicator;
 @property (readwrite, assign) IBOutlet NSBox *highlightBox;
+ at property (readwrite, assign) IBOutlet NSLayoutConstraint *imageViewAspectRatioConstraint;
 
 @property (readwrite, retain, nonatomic) id<VLCMediaLibraryItemProtocol> representedItem;
 


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
=====================================
@@ -47,18 +47,32 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
 {
     VLCLibraryController *_libraryController;
     VLCLibraryMenuController *_menuController;
+
+    NSLayoutConstraint *_videoImageViewAspectRatioConstraint;
 }
 @end
 
 @implementation VLCLibraryCollectionViewItem
 
-+ (NSSize)defaultSize
++ (const NSSize)defaultSize
 {
-    CGFloat width = 214;
+    const CGFloat width = [VLCLibraryCollectionViewItem defaultWidth];
     return CGSizeMake(width, width + [self bottomTextViewsHeight]);
 }
 
-+ (CGFloat)bottomTextViewsHeight
++ (const NSSize)defaultVideoItemSize
+{
+    const CGFloat width = [VLCLibraryCollectionViewItem defaultWidth];
+    const CGFloat imageViewHeight = width * [VLCLibraryCollectionViewItem videoHeightAspectRatioMultiplier];
+    return CGSizeMake(width, imageViewHeight + [self bottomTextViewsHeight]);
+}
+
++ (const CGFloat)defaultWidth
+{
+    return 214.;
+}
+
++ (const CGFloat)bottomTextViewsHeight
 {
     return [VLCLibraryUIUnits smallSpacing] +
            16 +
@@ -67,6 +81,11 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
            [VLCLibraryUIUnits smallSpacing];
 }
 
++ (const CGFloat)videoHeightAspectRatioMultiplier
+{
+    return 10. / 16.;
+}
+
 - (instancetype)initWithNibName:(NSNibName)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
 {
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -94,6 +113,16 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
 
 - (void)awakeFromNib
 {
+    _videoImageViewAspectRatioConstraint = [NSLayoutConstraint constraintWithItem:_mediaImageView
+                                                                        attribute:NSLayoutAttributeHeight
+                                                                        relatedBy:NSLayoutRelationEqual
+                                                                        toItem:_mediaImageView
+                                                                        attribute:NSLayoutAttributeWidth
+                                                                       multiplier:[VLCLibraryCollectionViewItem videoHeightAspectRatioMultiplier]
+                                                                        constant:1];
+    _videoImageViewAspectRatioConstraint.priority = NSLayoutPriorityRequired;
+    _videoImageViewAspectRatioConstraint.active = NO;
+
     [(VLCTrackingView *)self.view setViewToHide:self.playInstantlyButton];
     self.secondaryInfoTextField.textColor = [NSColor VLClibrarySubtitleColor];
     self.annotationTextField.font = [NSFont VLClibraryCellAnnotationFont];
@@ -200,8 +229,15 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
     // TODO: Add handling for the other types
     if([_representedItem isKindOfClass:[VLCMediaLibraryMediaItem class]]) {
         VLCMediaLibraryMediaItem *mediaItem = (VLCMediaLibraryMediaItem *)_representedItem;
-        VLCMediaLibraryTrack *videoTrack = mediaItem.firstVideoTrack;
-        [self showVideoSizeIfNeededForWidth:videoTrack.videoWidth andHeight:videoTrack.videoHeight];
+
+        if (mediaItem.mediaType == VLC_ML_MEDIA_TYPE_VIDEO) {
+            VLCMediaLibraryTrack *videoTrack = mediaItem.firstVideoTrack;
+            [self showVideoSizeIfNeededForWidth:videoTrack.videoWidth
+                                      andHeight:videoTrack.videoHeight];
+            _videoImageViewAspectRatioConstraint.active = YES;
+        } else {
+            _videoImageViewAspectRatioConstraint.active = NO;
+        }
 
         CGFloat position = mediaItem.progress;
         if (position > VLCLibraryCollectionViewItemMinimalDisplayedProgress && position < VLCLibraryCollectionViewItemMaximumDisplayedProgress) {


=====================================
modules/gui/macosx/library/VLCLibraryUIUnits.h
=====================================
@@ -24,6 +24,11 @@
 
 @class VLCLibraryCollectionViewFlowLayout;
 
+typedef NS_ENUM(NSUInteger, VLCLibraryCollectionViewItemAspectRatio) {
+    VLCLibraryCollectionViewItemAspectRatioDefaultItem = 0,
+    VLCLibraryCollectionViewItemAspectRatioVideoItem,
+};
+
 NS_ASSUME_NONNULL_BEGIN
 
 @interface VLCLibraryUIUnits : NSObject
@@ -47,7 +52,8 @@ NS_ASSUME_NONNULL_BEGIN
 + (const CGFloat)dynamicCollectionViewItemMaximumWidth;
 
 + (const NSSize)adjustedCollectionViewItemSizeForCollectionView:(NSCollectionView *)collectionView
-                                                     withLayout:(VLCLibraryCollectionViewFlowLayout *)collectionViewLayout;
+                                                     withLayout:(VLCLibraryCollectionViewFlowLayout *)collectionViewLayout
+                                           withItemsAspectRatio:(VLCLibraryCollectionViewItemAspectRatio)itemsAspectRatio;
 
 @end
 


=====================================
modules/gui/macosx/library/VLCLibraryUIUnits.m
=====================================
@@ -84,23 +84,27 @@
 
 + (const NSSize)adjustedCollectionViewItemSizeForCollectionView:(NSCollectionView *)collectionView
                                                      withLayout:(VLCLibraryCollectionViewFlowLayout *)collectionViewLayout
+                                           withItemsAspectRatio:(VLCLibraryCollectionViewItemAspectRatio)itemsAspectRatio
 {
     static uint numItemsInRow = 5;
 
     NSSize itemSize = [self itemSizeForCollectionView:collectionView
                                            withLayout:collectionViewLayout
+                                 withItemsAspectRatio:itemsAspectRatio
                                withNumberOfItemsInRow:numItemsInRow];
 
     while (itemSize.width > [VLCLibraryUIUnits dynamicCollectionViewItemMaximumWidth]) {
         ++numItemsInRow;
         itemSize = [self itemSizeForCollectionView:collectionView
                                         withLayout:collectionViewLayout
+                              withItemsAspectRatio:itemsAspectRatio
                             withNumberOfItemsInRow:numItemsInRow];
     }
     while (itemSize.width < [VLCLibraryUIUnits dynamicCollectionViewItemMinimumWidth]) {
         --numItemsInRow;
         itemSize = [self itemSizeForCollectionView:collectionView
                                         withLayout:collectionViewLayout
+                              withItemsAspectRatio:itemsAspectRatio
                             withNumberOfItemsInRow:numItemsInRow];
     }
 
@@ -109,6 +113,7 @@
 
 + (const NSSize)itemSizeForCollectionView:(NSCollectionView *)collectionView
                                withLayout:(VLCLibraryCollectionViewFlowLayout *)collectionViewLayout
+                     withItemsAspectRatio:(VLCLibraryCollectionViewItemAspectRatio)itemsAspectRatio
                    withNumberOfItemsInRow:(uint)numItemsInRow
 {
     NSParameterAssert(numItemsInRow > 0);
@@ -125,7 +130,11 @@
                                      1);
 
     const CGFloat itemWidth = rowOfItemsWidth / numItemsInRow;
-    return NSMakeSize(itemWidth, itemWidth + [VLCLibraryCollectionViewItem bottomTextViewsHeight]);
+    const CGFloat itemHeight = itemsAspectRatio == VLCLibraryCollectionViewItemAspectRatioDefaultItem ?
+        itemWidth + [VLCLibraryCollectionViewItem bottomTextViewsHeight] :
+        (itemWidth * [VLCLibraryCollectionViewItem videoHeightAspectRatioMultiplier]) + [VLCLibraryCollectionViewItem bottomTextViewsHeight];
+
+    return NSMakeSize(itemWidth, itemHeight);
 }
 
 @end


=====================================
modules/gui/macosx/library/VLCLibraryWindow.m
=====================================
@@ -330,7 +330,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
     audioLibraryGridModeListSelectionCollectionViewLayout.minimumInteritemSpacing = collectionItemSpacing;
 
     VLCLibraryVideoCollectionViewsStackViewController *videoLibraryStackViewController = _libraryVideoViewController.libraryVideoCollectionViewsStackViewController;
-    videoLibraryStackViewController.collectionViewItemSize = [VLCLibraryCollectionViewItem defaultSize];
+    videoLibraryStackViewController.collectionViewItemSize = [VLCLibraryCollectionViewItem defaultVideoItemSize];
     videoLibraryStackViewController.collectionViewMinimumLineSpacing = collectionItemSpacing;
     videoLibraryStackViewController.collectionViewMinimumInteritemSpacing = collectionItemSpacing;
     videoLibraryStackViewController.collectionViewSectionInset = collectionViewSectionInset;


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m
=====================================
@@ -285,7 +285,8 @@ referenceSizeForHeaderInSection:(NSInteger)section
     VLCLibraryCollectionViewFlowLayout *collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout*)collectionViewLayout;
     NSAssert(collectionViewLayout, @"This should be a flow layout and thus a valid pointer");
     return [VLCLibraryUIUnits adjustedCollectionViewItemSizeForCollectionView:collectionView
-                                                                   withLayout:collectionViewFlowLayout];
+                                                                   withLayout:collectionViewFlowLayout
+                                                         withItemsAspectRatio:VLCLibraryCollectionViewItemAspectRatioDefaultItem];
 }
 
 #pragma mark - table view data source and delegation


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceDataSource.m
=====================================
@@ -113,7 +113,8 @@
     VLCLibraryCollectionViewFlowLayout *collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout*)collectionViewLayout;
     NSAssert(collectionViewLayout, @"This should be a flow layout and thus a valid pointer");
     return [VLCLibraryUIUnits adjustedCollectionViewItemSizeForCollectionView:collectionView
-                                                                   withLayout:collectionViewFlowLayout];
+                                                                   withLayout:collectionViewFlowLayout
+                                                         withItemsAspectRatio:VLCLibraryCollectionViewItemAspectRatioDefaultItem];
 }
 
 #pragma mark - table view data source and delegation


=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerView.m
=====================================
@@ -112,6 +112,7 @@
     _collectionView.allowsMultipleSelection = NO;
 
     _collectionViewDelegate = [[VLCLibraryCollectionViewDelegate alloc] init];
+    _collectionViewDelegate.itemsAspectRatio = VLCLibraryCollectionViewItemAspectRatioVideoItem;
     _collectionView.delegate = _collectionViewDelegate;
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/eb57ab5d0952977ebd33bfc984b723cc64117f87...894ecb9fc83a2ae784fb5ed072ad15623c4c5229

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


VideoLAN code repository instance


More information about the vlc-commits mailing list