[vlc-commits] [Git][videolan/vlc][master] 20 commits: macosx: Add custom invalidation behaviour for VLCLibraryCollectionViewFlowLayout on bounds change

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sun Dec 25 00:21:48 UTC 2022



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
be39cc3b by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Add custom invalidation behaviour for VLCLibraryCollectionViewFlowLayout on bounds change

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

- - - - -
11603dbc by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Make audio collection view items dynamically sized

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

- - - - -
d2d58ff1 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Move item size calculation to own method

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

- - - - -
80ed297c by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Dynamically change number of collection view items in row depending on available width

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

- - - - -
926f07f9 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Fix jittering when resizing in the boundary between one item more or less being added to the layout row

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

- - - - -
d2de90cc by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Further extract collection view item size calculation to own method

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

- - - - -
bb044a1b by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Create new VLCLibraryCollectionViewDelegate class to unify all VLC library collection view delegate behaviour

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

- - - - -
288039a5 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Move dynamic collection view item sizing to new delegate class, convert for proper use in a delegate class

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

- - - - -
f546c78e by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Move remaining delegate methods from VLCLibraryAudioDataSource to VLCLibraryCollectionViewDelegate

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

- - - - -
55c0d493 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Separate more of audio collection view setup from VLCLibraryAudioDataSource, move into more logical VLCLibraryAudioViewController

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

- - - - -
106c1b67 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Add a VLCLibraryCollectionViewDataSource with method allowing for polymorphic access to underlying data item

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

- - - - -
623d1226 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Make audio library collection view data source and video library collection view data source compliant with VLCLibraryCollectionViewDataSource protocol

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

- - - - -
b069be45 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Move delegate methods in VLCLibraryVideoCollectionViewContainerViewDataSource to general VLCLibraryCollectionViewDelegate

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

- - - - -
a53ae489 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Set new VLCLibraryCollectionViewDelegate as delegate for video library collection views

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

- - - - -
6279fcd1 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Add ability to disable dynamic item sizing in VLCLibraryCollectionViewDelegate

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

- - - - -
274ac2e0 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Disable dynamic collection view item sizing in horizontal carousel video collection view

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

- - - - -
b087bd1f by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Publicly declare collection view delegate object as readonly property in VLCLibraryVideoCollectionViewContainerView

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

- - - - -
7948204c by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Add ability to set static item size in VLCLibraryCollectionViewDelegate

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

- - - - -
43f32991 by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Make setter for VLCLibraryVideoCollectionViewsStackViewController collectionViewItemSize property set the static item size in the container's collection view delegate

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

- - - - -
c315516b by Claudio Cambra at 2022-12-25T00:03:43+00:00
macosx: Calculate horizontal video collection view using static item size in collection view delegate

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

- - - - -


15 changed files:

- extras/package/macosx/VLC.xcodeproj/project.pbxproj
- modules/gui/macosx/Makefile.am
- + modules/gui/macosx/library/VLCLibraryCollectionViewDataSource.h
- + modules/gui/macosx/library/VLCLibraryCollectionViewDelegate.h
- + modules/gui/macosx/library/VLCLibraryCollectionViewDelegate.m
- modules/gui/macosx/library/VLCLibraryCollectionViewFlowLayout.m
- modules/gui/macosx/library/VLCLibraryWindow.m
- modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.h
- modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
- modules/gui/macosx/library/audio-library/VLCLibraryAudioViewController.m
- modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerView.h
- modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerView.m
- modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerViewDataSource.h
- modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerViewDataSource.m
- modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewsStackViewController.m


Changes:

=====================================
extras/package/macosx/VLC.xcodeproj/project.pbxproj
=====================================
@@ -77,10 +77,8 @@
 		1CCC89052078A3D500E5626F /* TextfieldPanel.xib in Sources */ = {isa = PBXBuildFile; fileRef = 6B8224151E4D2A9000833BE1 /* TextfieldPanel.xib */; };
 		1CCC89062078A3D500E5626F /* TimeSelectionPanel.xib in Sources */ = {isa = PBXBuildFile; fileRef = 6B8224161E4D2A9000833BE1 /* TimeSelectionPanel.xib */; };
 		1CFE8D591EA0D42A00E94451 /* VLCErrorWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1CFE8D581EA0D42A00E94451 /* VLCErrorWindowController.m */; };
+		5317FE04294E3DD3001702F0 /* VLCLibraryCollectionViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5317FE03294E3DD3001702F0 /* VLCLibraryCollectionViewDelegate.m */; };
 		5325C57D29302E6800B2B63A /* VLCLibraryAudioViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5325C57B29302E6800B2B63A /* VLCLibraryAudioViewController.m */; };
-		5325C56A292D59FB00B2B63A /* VLCLibraryVideoCollectionViewContainerViewDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 5325C569292D59FB00B2B63A /* VLCLibraryVideoCollectionViewContainerViewDataSource.m */; };
-		5325C56D292D5CEB00B2B63A /* VLCLibraryVideoGroupDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 5325C56C292D5CEB00B2B63A /* VLCLibraryVideoGroupDescriptor.m */; };
-		5325C570292D5E8F00B2B63A /* VLCLibraryVideoCollectionViewContainerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5325C56F292D5E8F00B2B63A /* VLCLibraryVideoCollectionViewContainerView.m */; };
 		5362550D293FD639005D64FA /* VLCLibraryWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5362550C293FD639005D64FA /* VLCLibraryWindowController.m */; };
 		536283F0291146BC00640C15 /* VLCLibraryTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 536283DE291146BC00640C15 /* VLCLibraryTableView.m */; };
 		536283F1291146BC00640C15 /* VLCLibraryAlbumTracksDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 536283DF291146BC00640C15 /* VLCLibraryAlbumTracksDataSource.m */; };
@@ -238,14 +236,11 @@
 		1CFE8D561EA0D3D300E94451 /* ErrorPanel.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ErrorPanel.xib; sourceTree = "<group>"; };
 		1CFE8D571EA0D42A00E94451 /* VLCErrorWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCErrorWindowController.h; sourceTree = "<group>"; };
 		1CFE8D581EA0D42A00E94451 /* VLCErrorWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCErrorWindowController.m; sourceTree = "<group>"; };
+		5317FE02294E3DD3001702F0 /* VLCLibraryCollectionViewDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryCollectionViewDelegate.h; sourceTree = "<group>"; };
+		5317FE03294E3DD3001702F0 /* VLCLibraryCollectionViewDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryCollectionViewDelegate.m; sourceTree = "<group>"; };
+		5317FE05294E8D1A001702F0 /* VLCLibraryCollectionViewDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryCollectionViewDataSource.h; sourceTree = "<group>"; };
 		5325C57B29302E6800B2B63A /* VLCLibraryAudioViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryAudioViewController.m; sourceTree = "<group>"; };
 		5325C57C29302E6800B2B63A /* VLCLibraryAudioViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCLibraryAudioViewController.h; sourceTree = "<group>"; };
-		5325C568292D59FB00B2B63A /* VLCLibraryVideoCollectionViewContainerViewDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryVideoCollectionViewContainerViewDataSource.h; sourceTree = "<group>"; };
-		5325C569292D59FB00B2B63A /* VLCLibraryVideoCollectionViewContainerViewDataSource.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryVideoCollectionViewContainerViewDataSource.m; sourceTree = "<group>"; };
-		5325C56B292D5CEB00B2B63A /* VLCLibraryVideoGroupDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryVideoGroupDescriptor.h; sourceTree = "<group>"; };
-		5325C56C292D5CEB00B2B63A /* VLCLibraryVideoGroupDescriptor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryVideoGroupDescriptor.m; sourceTree = "<group>"; };
-		5325C56E292D5E8F00B2B63A /* VLCLibraryVideoCollectionViewContainerView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryVideoCollectionViewContainerView.h; sourceTree = "<group>"; };
-		5325C56F292D5E8F00B2B63A /* VLCLibraryVideoCollectionViewContainerView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryVideoCollectionViewContainerView.m; sourceTree = "<group>"; };
 		5362550B293FD639005D64FA /* VLCLibraryWindowController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryWindowController.h; sourceTree = "<group>"; };
 		5362550C293FD639005D64FA /* VLCLibraryWindowController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryWindowController.m; sourceTree = "<group>"; };
 		536283DC291146BC00640C15 /* VLCLibraryAlbumTracksDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCLibraryAlbumTracksDataSource.h; sourceTree = "<group>"; };
@@ -1155,6 +1150,9 @@
 				7D713D312201AE350042BEB7 /* VLCLibraryWindow.m */,
 				5362550B293FD639005D64FA /* VLCLibraryWindowController.h */,
 				5362550C293FD639005D64FA /* VLCLibraryWindowController.m */,
+				5317FE02294E3DD3001702F0 /* VLCLibraryCollectionViewDelegate.h */,
+				5317FE03294E3DD3001702F0 /* VLCLibraryCollectionViewDelegate.m */,
+				5317FE05294E8D1A001702F0 /* VLCLibraryCollectionViewDataSource.h */,
 			);
 			path = library;
 			sourceTree = "<group>";
@@ -1308,16 +1306,16 @@
 		53B447EB293BB47A00857588 /* video-library */ = {
 			isa = PBXGroup;
 			children = (
+				53B447F1293BB47A00857588 /* VLCLibraryVideoCollectionViewContainerView.h */,
 				53B447EC293BB47A00857588 /* VLCLibraryVideoCollectionViewContainerView.m */,
+				53B447F2293BB47A00857588 /* VLCLibraryVideoCollectionViewContainerViewDataSource.h */,
 				53B447ED293BB47A00857588 /* VLCLibraryVideoCollectionViewContainerViewDataSource.m */,
-				53B447EE293BB47A00857588 /* VLCLibraryVideoTableViewDataSource.h */,
+				53B447F5293BB47B00857588 /* VLCLibraryVideoCollectionViewsStackViewController.h */,
 				53B447EF293BB47A00857588 /* VLCLibraryVideoCollectionViewsStackViewController.m */,
 				53B447F0293BB47A00857588 /* VLCLibraryVideoGroupDescriptor.h */,
-				53B447F1293BB47A00857588 /* VLCLibraryVideoCollectionViewContainerView.h */,
-				53B447F2293BB47A00857588 /* VLCLibraryVideoCollectionViewContainerViewDataSource.h */,
-				53B447F3293BB47A00857588 /* VLCLibraryVideoTableViewDataSource.m */,
 				53B447F4293BB47A00857588 /* VLCLibraryVideoGroupDescriptor.m */,
-				53B447F5293BB47B00857588 /* VLCLibraryVideoCollectionViewsStackViewController.h */,
+				53B447EE293BB47A00857588 /* VLCLibraryVideoTableViewDataSource.h */,
+				53B447F3293BB47A00857588 /* VLCLibraryVideoTableViewDataSource.m */,
 			);
 			path = "video-library";
 			sourceTree = "<group>";
@@ -1842,6 +1840,7 @@
 				1CCC88FD2078A3D500E5626F /* Open.xib in Sources */,
 				1CCC88FE2078A3D500E5626F /* PlaylistAccessoryView.xib in Sources */,
 				1CCC89002078A3D500E5626F /* PopupPanel.xib in Sources */,
+				5317FE04294E3DD3001702F0 /* VLCLibraryCollectionViewDelegate.m in Sources */,
 				53628402291147C500640C15 /* VLCBasicView.m in Sources */,
 				7DFBDCAB2269E77F00B700A5 /* VLCLibraryModel.m in Sources */,
 				1CCC89012078A3D500E5626F /* Preferences.xib in Sources */,


=====================================
modules/gui/macosx/Makefile.am
=====================================
@@ -58,6 +58,9 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/imported/SPMediaKeyTap/SPMediaKeyTap.m \
 	gui/macosx/library/VLCInputItem.h \
 	gui/macosx/library/VLCInputItem.m \
+	gui/macosx/library/VLCLibraryCollectionViewDataSource.h \
+	gui/macosx/library/VLCLibraryCollectionViewDelegate.h \
+	gui/macosx/library/VLCLibraryCollectionViewDelegate.m \
 	gui/macosx/library/VLCLibraryCollectionViewFlowLayout.h \
 	gui/macosx/library/VLCLibraryCollectionViewFlowLayout.m \
 	gui/macosx/library/VLCLibraryCollectionViewItem.h \


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewDataSource.h
=====================================
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * VLCLibraryCollectionViewDataSource.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <developer at claudiocambra.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+ at protocol VLCMediaLibraryItemProtocol;
+
+ at protocol VLCLibraryCollectionViewDataSource <NSCollectionViewDataSource>
+
+- (id<VLCMediaLibraryItemProtocol>)libraryItemAtIndexPath:(NSIndexPath *)indexPath
+                                        forCollectionView:(NSCollectionView *)collectionView;
+
+ at end
+
+NS_ASSUME_NONNULL_END


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewDelegate.h
=====================================
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * VLCLibraryCollectionViewDelegate.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <developer at claudiocambra.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+ at interface VLCLibraryCollectionViewDelegate : NSObject <NSCollectionViewDelegate, NSCollectionViewDelegateFlowLayout>
+
+ at property (readwrite, assign) BOOL dynamicItemSizing;
+ at property (readwrite, assign) NSSize staticItemSize;
+
+ at end
+
+NS_ASSUME_NONNULL_END


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewDelegate.m
=====================================
@@ -0,0 +1,178 @@
+/*****************************************************************************
+ * VLCLibraryCollectionViewDelegate.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <developer at claudiocambra.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCLibraryCollectionViewDelegate.h"
+
+#import "VLCLibraryCollectionViewDataSource.h"
+#import "VLCLibraryCollectionViewFlowLayout.h"
+#import "VLCLibraryDataTypes.h"
+
+ at implementation VLCLibraryCollectionViewDelegate
+
+- (instancetype)init
+{
+    self = [super init];
+    if (self) {
+        _dynamicItemSizing = YES;
+        _staticItemSize = NSMakeSize(214, 260);
+    }
+    return self;
+}
+
+- (void)collectionView:(NSCollectionView *)collectionView didSelectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
+{
+    NSIndexPath *indexPath = indexPaths.anyObject;
+    if (!indexPath) {
+        return;
+    }
+
+    VLCLibraryCollectionViewFlowLayout *collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout*)collectionView.collectionViewLayout;
+    if(collectionViewFlowLayout) {
+        [collectionViewFlowLayout expandDetailSectionAtIndex:indexPath];
+    }
+}
+
+- (void)collectionView:(NSCollectionView *)collectionView didDeselectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
+{
+    NSIndexPath *indexPath = indexPaths.anyObject;
+    if (!indexPath) {
+        return;
+    }
+
+    VLCLibraryCollectionViewFlowLayout *collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout*)collectionView.collectionViewLayout;
+    if (collectionViewFlowLayout) {
+        [collectionViewFlowLayout collapseDetailSectionAtIndex:indexPath];
+    }
+}
+
+- (NSSize)collectionView:(NSCollectionView *)collectionView
+                  layout:(NSCollectionViewLayout *)collectionViewLayout
+  sizeForItemAtIndexPath:(NSIndexPath *)indexPath
+{
+    if (!_dynamicItemSizing) {
+        return _staticItemSize;
+    }
+    
+    VLCLibraryCollectionViewFlowLayout *collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout*)collectionViewLayout;
+    if (collectionViewLayout) {
+        VLCLibraryCollectionViewFlowLayout *collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout*)collectionViewLayout;
+        return [self adjustedItemSizeForCollectionView:collectionView
+                                            withLayout:collectionViewFlowLayout];
+    }
+
+    return NSZeroSize;
+}
+
+- (NSSize)adjustedItemSizeForCollectionView:(NSCollectionView *)collectionView
+                                 withLayout:(VLCLibraryCollectionViewFlowLayout *)collectionViewLayout
+{
+    static const CGFloat maxItemWidth = 280;
+    static const CGFloat minItemWidth = 180;
+
+    static uint numItemsInRow = 5;
+
+    NSSize itemSize = [self itemSizeForCollectionView:collectionView
+                                           withLayout:collectionViewLayout
+                               withNumberOfItemsInRow:numItemsInRow];
+
+    while (itemSize.width > maxItemWidth) {
+        ++numItemsInRow;
+        itemSize = [self itemSizeForCollectionView:collectionView
+                                        withLayout:collectionViewLayout
+                            withNumberOfItemsInRow:numItemsInRow];
+    }
+    while (itemSize.width < minItemWidth) {
+        --numItemsInRow;
+        itemSize = [self itemSizeForCollectionView:collectionView
+                                        withLayout:collectionViewLayout
+                            withNumberOfItemsInRow:numItemsInRow];
+    }
+
+    return itemSize;
+}
+
+- (NSSize)itemSizeForCollectionView:(NSCollectionView *)collectionView
+                        withLayout:(VLCLibraryCollectionViewFlowLayout *)collectionViewLayout
+            withNumberOfItemsInRow:(uint)numItemsInRow
+{
+    NSParameterAssert(numItemsInRow > 0);
+    NSParameterAssert(collectionView);
+    NSParameterAssert(collectionViewLayout);
+
+    const NSEdgeInsets sectionInsets = collectionViewLayout.sectionInset;
+    const CGFloat interItemSpacing = collectionViewLayout.minimumInteritemSpacing;
+
+    const CGFloat rowOfItemsWidth = collectionView.bounds.size.width -
+                                    (sectionInsets.left +
+                                     sectionInsets.right +
+                                     (interItemSpacing * (numItemsInRow - 1)) +
+                                     1);
+
+    const CGFloat itemWidth = rowOfItemsWidth / numItemsInRow;
+    return NSMakeSize(itemWidth, itemWidth + 46); // Text fields height needed
+}
+
+- (BOOL)collectionView:(NSCollectionView *)collectionView
+canDragItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
+             withEvent:(NSEvent *)event
+{
+    return YES;
+}
+
+- (BOOL)collectionView:(NSCollectionView *)collectionView
+writeItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
+          toPasteboard:(NSPasteboard *)pasteboard
+{
+    if (![collectionView.dataSource conformsToProtocol:@protocol(VLCLibraryCollectionViewDataSource)]) {
+        return NO;
+    }
+
+    NSObject<VLCLibraryCollectionViewDataSource> *vlcDataSource = (NSObject<VLCLibraryCollectionViewDataSource>*)collectionView.dataSource;
+
+    NSUInteger numberOfIndexPaths = indexPaths.count;
+    NSMutableArray *encodedLibraryItemsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];
+    NSMutableArray *filePathsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];
+
+    for (NSIndexPath *indexPath in indexPaths) {
+
+        id<VLCMediaLibraryItemProtocol> libraryItem = [vlcDataSource libraryItemAtIndexPath:indexPath
+                                                                          forCollectionView:collectionView];
+
+        VLCMediaLibraryMediaItem *mediaItem = libraryItem.firstMediaItem;
+        [encodedLibraryItemsArray addObject:mediaItem];
+
+        VLCMediaLibraryFile *file = mediaItem.files.firstObject;
+        if (file) {
+            NSURL *url = [NSURL URLWithString:file.MRL];
+            [filePathsArray addObject:url.path];
+        }
+    }
+
+    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:encodedLibraryItemsArray];
+    [pasteboard declareTypes:@[VLCMediaLibraryMediaItemPasteboardType, NSFilenamesPboardType] owner:self];
+    [pasteboard setPropertyList:filePathsArray forType:NSFilenamesPboardType];
+    [pasteboard setData:data forType:VLCMediaLibraryMediaItemPasteboardType];
+
+    return YES;
+}
+
+ at end


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewFlowLayout.m
=====================================
@@ -68,6 +68,8 @@ static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
     
     VLCExpandAnimationType _animationType;
     CGFloat _prevProvidedAnimationStep;
+
+    BOOL _invalidateAll;
 }
 
 @property (nonatomic, readwrite) BOOL detailViewIsAnimating;
@@ -88,6 +90,8 @@ static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
         
         _animationType = VLCExpandAnimationTypeDefault;
         _prevProvidedAnimationStep = 0;
+
+        _invalidateAll = NO;
         
         [self resetLayout];
     }
@@ -173,6 +177,25 @@ static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
     return contentSize;
 }
 
+- (BOOL)shouldInvalidateLayoutForBoundsChange:(NSRect)newBounds
+{
+    [super shouldInvalidateLayoutForBoundsChange:newBounds];
+    _invalidateAll = YES;
+    return YES;
+}
+
+- (void)invalidateLayoutWithContext:(NSCollectionViewLayoutInvalidationContext *)context
+{
+    NSCollectionViewFlowLayoutInvalidationContext *flowLayoutContext = (NSCollectionViewFlowLayoutInvalidationContext *)context;
+    if (flowLayoutContext && _invalidateAll) {
+        flowLayoutContext.invalidateFlowLayoutAttributes = YES;
+        flowLayoutContext.invalidateFlowLayoutDelegateMetrics = YES;
+        _invalidateAll = NO;
+    }
+
+    [super invalidateLayoutWithContext:context];
+}
+
 - (NSCollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
 {
     NSCollectionViewLayoutAttributes *attributes = [super layoutAttributesForItemAtIndexPath:indexPath];


=====================================
modules/gui/macosx/library/VLCLibraryWindow.m
=====================================
@@ -342,7 +342,6 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
     const NSEdgeInsets collectionViewSectionInset = NSEdgeInsetsMake(20., 20., 20., 20.);
 
     NSCollectionViewFlowLayout *audioLibraryCollectionViewLayout = _audioLibraryCollectionView.collectionViewLayout;
-    audioLibraryCollectionViewLayout.itemSize = CGSizeMake(214., 260.);
     audioLibraryCollectionViewLayout.minimumLineSpacing = collectionItemSpacing;
     audioLibraryCollectionViewLayout.minimumInteritemSpacing = collectionItemSpacing;
     audioLibraryCollectionViewLayout.sectionInset = collectionViewSectionInset;


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.h
=====================================
@@ -23,6 +23,7 @@
 #import <Cocoa/Cocoa.h>
 
 #import "library/VLCLibraryTableView.h"
+#import "library/VLCLibraryCollectionViewDataSource.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
@@ -37,7 +38,7 @@ typedef NS_ENUM(NSUInteger, VLCAudioLibrarySegment) {
     VLCAudioLibraryGenresSegment
 };
 
- at interface VLCLibraryAudioDataSource : NSObject <VLCLibraryTableViewDataSource, NSTableViewDelegate, NSCollectionViewDataSource, NSCollectionViewDelegate>
+ at interface VLCLibraryAudioDataSource : NSObject <VLCLibraryTableViewDataSource, NSTableViewDelegate, VLCLibraryCollectionViewDataSource>
 
 @property (readwrite, assign) VLCLibraryModel *libraryModel;
 @property (readwrite, assign) VLCLibraryGroupDataSource *groupDataSource;


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
=====================================
@@ -69,7 +69,6 @@ static NSString *VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
 
 @interface VLCLibraryAudioDataSource ()
 {
-    VLCLibraryCollectionViewFlowLayout *_collectionViewFlowLayout;
     NSArray *_displayedCollection;
     enum vlc_ml_parent_type _currentParentType;
 
@@ -258,7 +257,7 @@ static NSString *VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
     NSSet *indexPathSet = [NSSet setWithObject:newIndexPath];
     [_collectionView selectItemsAtIndexPaths:indexPathSet scrollPosition:NSCollectionViewScrollPositionTop];
     // selectItemsAtIndexPaths does not call any delegate methods so we do it manually
-    [self collectionView:_collectionView didSelectItemsAtIndexPaths:indexPathSet];
+    [_collectionView.delegate collectionView:_collectionView didSelectItemsAtIndexPaths:indexPathSet];
     _selectedCollectionViewItem = nil;
 }
 
@@ -306,7 +305,6 @@ static NSString *VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
 - (void)setupCollectionView
 {
     _collectionView.dataSource = self;
-    _collectionView.delegate = self;
 
     [_collectionView registerClass:[VLCLibraryCollectionViewItem class] forItemWithIdentifier:VLCLibraryCellIdentifier];
 
@@ -324,9 +322,6 @@ static NSString *VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
     [_collectionView registerNib:mediaItemSupplementaryDetailView
       forSupplementaryViewOfKind:VLCLibraryCollectionViewMediaItemSupplementaryDetailViewKind
                   withIdentifier:VLCLibraryCollectionViewMediaItemSupplementaryDetailViewIdentifier];
-
-    _collectionViewFlowLayout = [[VLCLibraryCollectionViewFlowLayout alloc] init];
-    _collectionView.collectionViewLayout = _collectionViewFlowLayout;
 }
 
 - (void)setupTableViews
@@ -431,7 +426,11 @@ static NSString *VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
 
 - (void)reloadViews
 {
-    [_collectionViewFlowLayout resetLayout];
+    VLCLibraryCollectionViewFlowLayout *collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout *)_collectionView.collectionViewLayout;
+    if (collectionViewFlowLayout) {
+        [collectionViewFlowLayout resetLayout];
+    }
+    
     [self.collectionView reloadData];
     [self.collectionSelectionTableView reloadData];
     [self.groupSelectionTableView reloadData];
@@ -632,7 +631,7 @@ static NSString *VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
     [VLCMain.sharedInstance.libraryController appendItemToPlaylist:mediaItem playImmediately:YES];
 }
 
-#pragma mark - collection view data source and delegation
+#pragma mark - collection view data source
 
 - (NSInteger)collectionView:(NSCollectionView *)collectionView
      numberOfItemsInSection:(NSInteger)section
@@ -653,26 +652,6 @@ static NSString *VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
     return viewItem;
 }
 
-- (void)collectionView:(NSCollectionView *)collectionView didSelectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
-{
-    NSIndexPath *indexPath = indexPaths.anyObject;
-    if (!indexPath) {
-        return;
-    }
-
-    [_collectionViewFlowLayout expandDetailSectionAtIndex:indexPath];
-}
-
-- (void)collectionView:(NSCollectionView *)collectionView didDeselectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
-{
-    NSIndexPath *indexPath = indexPaths.anyObject;
-    if (!indexPath) {
-        return;
-    }
-
-    [_collectionViewFlowLayout collapseDetailSectionAtIndex:indexPath];
-}
-
 - (NSView *)collectionView:(NSCollectionView *)collectionView
 viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
                atIndexPath:(NSIndexPath *)indexPath
@@ -715,6 +694,12 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
     return nil;
 }
 
+- (id<VLCMediaLibraryItemProtocol>)libraryItemAtIndexPath:(NSIndexPath *)indexPath
+                                        forCollectionView:(NSCollectionView *)collectionView
+{
+    return _displayedCollection[indexPath.item];
+}
+
 @end
 
 @implementation VLCLibraryGroupDataSource


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioViewController.m
=====================================
@@ -24,6 +24,8 @@
 
 #import "main/VLCMain.h"
 #import "extensions/NSString+Helpers.h"
+#import "library/VLCLibraryCollectionViewDelegate.h"
+#import "library/VLCLibraryCollectionViewFlowLayout.h"
 #import "library/VLCLibraryController.h"
 #import "library/VLCLibraryModel.h"
 #import "library/VLCLibraryNavigationStack.h"
@@ -34,6 +36,8 @@
 {
     NSArray<NSString *> *_placeholderImageNames;
     NSArray<NSString *> *_placeholderLabelStrings;
+
+    VLCLibraryCollectionViewDelegate *_audioLibraryCollectionViewDelegate;
 }
 @end
 
@@ -100,6 +104,11 @@
     _audioLibraryCollectionView.selectable = YES;
     _audioLibraryCollectionView.allowsMultipleSelection = NO;
     _audioLibraryCollectionView.allowsEmptySelection = YES;
+
+    _audioLibraryCollectionViewDelegate = [[VLCLibraryCollectionViewDelegate alloc] init];
+    _audioLibraryCollectionView.delegate = _audioLibraryCollectionViewDelegate;
+
+    _audioLibraryCollectionView.collectionViewLayout = [[VLCLibraryCollectionViewFlowLayout alloc] init];
 }
 
 - (void)setupAudioTableViews


=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerView.h
=====================================
@@ -25,6 +25,7 @@
 #import "library/video-library/VLCLibraryVideoGroupDescriptor.h"
 
 @class VLCSubScrollView;
+ at class VLCLibraryCollectionViewDelegate;
 @class VLCLibraryCollectionViewFlowLayout;
 @class VLCLibraryVideoCollectionViewGroupDescriptor;
 @class VLCLibraryVideoCollectionViewContainerViewDataSource;
@@ -34,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
 @interface VLCLibraryVideoCollectionViewContainerView : NSView
 
 @property (readonly) NSCollectionView *collectionView;
+ at property (readonly) VLCLibraryCollectionViewDelegate *collectionViewDelegate;
 @property (readonly) VLCLibraryCollectionViewFlowLayout *collectionViewLayout;
 @property (readonly) VLCSubScrollView *scrollView;
 @property (readonly) VLCLibraryVideoCollectionViewContainerViewDataSource *dataSource;


=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerView.m
=====================================
@@ -22,6 +22,7 @@
 
 #import "VLCLibraryVideoCollectionViewContainerView.h"
 
+#import "library/VLCLibraryCollectionViewDelegate.h"
 #import "library/VLCLibraryCollectionViewFlowLayout.h"
 #import "library/VLCLibraryCollectionViewSupplementaryElementView.h"
 
@@ -101,7 +102,6 @@
 {
     _collectionViewLayout = [[VLCLibraryCollectionViewFlowLayout alloc] init];
     _collectionViewLayout.headerReferenceSize = [VLCLibraryCollectionViewSupplementaryElementView defaultHeaderSize];
-    _collectionViewLayout.itemSize = CGSizeMake(214., 260.);
 
     _collectionView = [[NSCollectionView alloc] initWithFrame:NSZeroRect];
     _collectionView.postsFrameChangedNotifications = YES;
@@ -109,6 +109,9 @@
     _collectionView.selectable = YES;
     _collectionView.allowsEmptySelection = YES;
     _collectionView.allowsMultipleSelection = NO;
+
+    _collectionViewDelegate = [[VLCLibraryCollectionViewDelegate alloc] init];
+    _collectionView.delegate = _collectionViewDelegate;
 }
 
 - (void)setupScrollView
@@ -146,6 +149,7 @@
                                             NSCollectionViewScrollDirectionHorizontal :
                                             NSCollectionViewScrollDirectionVertical;
     _scrollView.scrollSelf = _groupDescriptor.isHorizontalBarCollectionView;
+    _collectionViewDelegate.dynamicItemSizing = !_groupDescriptor.isHorizontalBarCollectionView;
 }
 
 - (void)setVideoGroup:(VLCLibraryVideoGroup)group
@@ -180,6 +184,7 @@
                                  scrollViewInsets.bottom +
                                  collectionViewLayoutInset.top +
                                  collectionViewLayoutInset.bottom;
+    const CGFloat itemHeight = _collectionViewDelegate.staticItemSize.height;
     const CGFloat width = scrollViewInsets.left +
                           scrollViewInsets.right +
                           collectionViewLayoutInset.left +
@@ -190,14 +195,12 @@
         // If we don't return a size larger than 0 then we run into issues with the collection
         // view layout not trying to properly calculate its size. So let's return something
         NSLog(@"Unable to provide accurate height for container -- providing rough size");
-        const CGFloat roughValue = _collectionViewLayout.itemSize.height + insetsHeight;
+        const CGFloat roughValue = itemHeight + insetsHeight;
         return NSMakeSize(width, roughValue);
     }
 
     if (_groupDescriptor.isHorizontalBarCollectionView) {
-        const CGFloat viewHeight = _collectionViewLayout.itemSize.height +
-                                   insetsHeight +
-                                   15; // Account for horizontal scrollbar
+        const CGFloat viewHeight = itemHeight + insetsHeight + 15; // Account for horizontal scrollbar
         return NSMakeSize(width, viewHeight);
     }
 


=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerViewDataSource.h
=====================================
@@ -22,12 +22,14 @@
 
 #import <Cocoa/Cocoa.h>
 
+#import "library/VLCLibraryCollectionViewDataSource.h"
+
 @class VLCLibraryVideoCollectionViewContainerView;
 @class VLCLibraryVideoCollectionViewGroupDescriptor;
 
 NS_ASSUME_NONNULL_BEGIN
 
- at interface VLCLibraryVideoCollectionViewContainerViewDataSource : NSObject <NSCollectionViewDataSource, NSCollectionViewDelegate>
+ at interface VLCLibraryVideoCollectionViewContainerViewDataSource : NSObject <VLCLibraryCollectionViewDataSource>
 
 @property (readwrite, assign) NSCollectionView *collectionView;
 @property (readwrite, assign, nonatomic) VLCLibraryVideoCollectionViewGroupDescriptor *groupDescriptor;


=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerViewDataSource.m
=====================================
@@ -104,7 +104,6 @@
 
     _collectionViewFlowLayout = collectionViewLayout;
     _collectionView.dataSource = self;
-    _collectionView.delegate = self;
 
     [_collectionView registerClass:[VLCLibraryCollectionViewItem class]
              forItemWithIdentifier:VLCLibraryCellIdentifier];
@@ -165,60 +164,10 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
     return nil;
 }
 
-- (void)collectionView:(NSCollectionView *)collectionView didSelectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
+- (id<VLCMediaLibraryItemProtocol>)libraryItemAtIndexPath:(NSIndexPath *)indexPath
+                                        forCollectionView:(NSCollectionView *)collectionView
 {
-    NSIndexPath *indexPath = indexPaths.anyObject;
-    if (!indexPath) {
-        NSLog(@"Bad index path on item selection");
-        return;
-    }
-
-    [_collectionViewFlowLayout expandDetailSectionAtIndex:indexPath];
-}
-
-- (void)collectionView:(NSCollectionView *)collectionView didDeselectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
-{
-    NSIndexPath *indexPath = indexPaths.anyObject;
-    if (!indexPath) {
-        NSLog(@"Bad index path on item deselection");
-        return;
-    }
-
-    [_collectionViewFlowLayout collapseDetailSectionAtIndex:indexPath];
-}
-
-
-- (BOOL)collectionView:(NSCollectionView *)collectionView
-canDragItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
-             withEvent:(NSEvent *)event
-{
-    return YES;
-}
-
-- (BOOL)collectionView:(NSCollectionView *)collectionView
-writeItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
-          toPasteboard:(NSPasteboard *)pasteboard
-{
-    NSUInteger numberOfIndexPaths = indexPaths.count;
-    NSMutableArray *encodedLibraryItemsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];
-    NSMutableArray *filePathsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];
-    for (NSIndexPath *indexPath in indexPaths) {
-        VLCMediaLibraryMediaItem *mediaItem = _collectionArray[indexPath.item];
-        [encodedLibraryItemsArray addObject:mediaItem];
-
-        VLCMediaLibraryFile *file = mediaItem.files.firstObject;
-        if (file) {
-            NSURL *url = [NSURL URLWithString:file.MRL];
-            [filePathsArray addObject:url.path];
-        }
-    }
-
-    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:encodedLibraryItemsArray];
-    [pasteboard declareTypes:@[VLCMediaLibraryMediaItemPasteboardType, NSFilenamesPboardType] owner:self];
-    [pasteboard setPropertyList:filePathsArray forType:NSFilenamesPboardType];
-    [pasteboard setData:data forType:VLCMediaLibraryMediaItemPasteboardType];
-
-    return YES;
+    return _collectionArray[indexPath.item];
 }
 
 @end


=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewsStackViewController.m
=====================================
@@ -22,6 +22,7 @@
 
 #import "VLCLibraryVideoCollectionViewsStackViewController.h"
 
+#import "library/VLCLibraryCollectionViewDelegate.h"
 #import "library/VLCLibraryCollectionViewFlowLayout.h"
 #import "library/VLCLibraryCollectionViewSupplementaryElementView.h"
 #import "library/VLCLibraryModel.h"
@@ -139,7 +140,7 @@
     _collectionViewItemSize = collectionViewItemSize;
 
     for (VLCLibraryVideoCollectionViewContainerView *containerView in _collectionViewContainers) {
-        containerView.collectionViewLayout.itemSize = collectionViewItemSize;
+        containerView.collectionViewDelegate.staticItemSize = collectionViewItemSize;
     }
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/84f13e3a85e863afb0b456282746c801a5cad813...c315516b95b9b0a0cb7555e25ab80f29fb5f33e6

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/84f13e3a85e863afb0b456282746c801a5cad813...c315516b95b9b0a0cb7555e25ab80f29fb5f33e6
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