[vlc-commits] [Git][videolan/vlc][master] 9 commits: macosx: Allow adjustment of number of items in collection view row via defaults keyvalue
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Feb 5 09:11:20 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
b5a74723 by Claudio Cambra at 2025-02-05T08:27:29+00:00
macosx: Allow adjustment of number of items in collection view row via defaults keyvalue
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
c07362e7 by Claudio Cambra at 2025-02-05T08:27:29+00:00
macosx: Only effect adjustment when the number of items in row has changed
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
549be659 by Claudio Cambra at 2025-02-05T08:27:29+00:00
macosx: Prevent item size values going below 0 and becoming illegal
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
419191bf by Claudio Cambra at 2025-02-05T08:27:29+00:00
macosx: Actually set item size during adjustment in collection view
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
eba084c3 by Claudio Cambra at 2025-02-05T08:27:29+00:00
macosx: Remove internal state in collection view item sizing method
This method's hidden state is a micro optimisation since this method
only gets called when the collection view sizing actually changes. Yet
it makes accurately setting the adjustment more difficult. So let's
remove it
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
07b609a2 by Claudio Cambra at 2025-02-05T08:27:29+00:00
macosx: Provide extern within nonnull block
Fixes warning
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
56cd4f82 by Claudio Cambra at 2025-02-05T08:27:29+00:00
macosx: Add ability to make collection view items larger or smaller via CMD+ and CMD-
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
08085e96 by Claudio Cambra at 2025-02-05T08:27:29+00:00
macosx: Emit notification when the collection view item sizing had been adjusted
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
c6af4fe3 by Claudio Cambra at 2025-02-05T08:27:29+00:00
macosx: Present message in sidebar when collection view item sizing is adjusted
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
5 changed files:
- modules/gui/macosx/library/VLCLibraryCollectionView.h
- modules/gui/macosx/library/VLCLibraryCollectionView.m
- modules/gui/macosx/library/VLCLibraryUIUnits.h
- modules/gui/macosx/library/VLCLibraryUIUnits.m
- modules/gui/macosx/views/VLCStatusNotifierView.m
Changes:
=====================================
modules/gui/macosx/library/VLCLibraryCollectionView.h
=====================================
@@ -24,6 +24,9 @@
NS_ASSUME_NONNULL_BEGIN
+extern NSString * const VLCLibraryCollectionViewItemAdjustmentBigger;
+extern NSString * const VLCLibraryCollectionViewItemAdjustmentSmaller;
+
@interface VLCLibraryCollectionView : NSCollectionView
@end
=====================================
modules/gui/macosx/library/VLCLibraryCollectionView.m
=====================================
@@ -22,6 +22,12 @@
#import "VLCLibraryCollectionView.h"
+#import "library/VLCLibraryCollectionViewFlowLayout.h"
+#import "library/VLCLibraryUIUnits.h"
+
+NSString * const VLCLibraryCollectionViewItemAdjustmentBigger = @"VLCLibraryCollectionViewItemAdjustmentBigger";
+NSString * const VLCLibraryCollectionViewItemAdjustmentSmaller = @"VLCLibraryCollectionViewItemAdjustmentSmaller";
+
@implementation VLCLibraryCollectionView
- (void)layout
@@ -33,4 +39,36 @@
[super layout];
}
+- (void)keyDown:(NSEvent *)event
+{
+ if (![self.collectionViewLayout isKindOfClass:VLCLibraryCollectionViewFlowLayout.class] ||
+ !(event.modifierFlags & NSCommandKeyMask)) {
+ return;
+ }
+
+ const unichar key = [event.charactersIgnoringModifiers.lowercaseString characterAtIndex:0];
+ if (key != '+' && key != '-') {
+ return;
+ }
+
+ NSUserDefaults * const defaults = NSUserDefaults.standardUserDefaults;
+ NSInteger collectionViewAdjustment =
+ [defaults integerForKey:VLCLibraryCollectionViewItemAdjustmentKey];
+ NSNotification *notification;
+ if (key == '+') {
+ collectionViewAdjustment--;
+ notification =
+ [NSNotification notificationWithName:VLCLibraryCollectionViewItemAdjustmentBigger
+ object:self];
+ } else if (key == '-') {
+ collectionViewAdjustment++;
+ notification =
+ [NSNotification notificationWithName:VLCLibraryCollectionViewItemAdjustmentSmaller
+ object:self];
+ }
+ [defaults setInteger:collectionViewAdjustment forKey:VLCLibraryCollectionViewItemAdjustmentKey];
+ [NSNotificationCenter.defaultCenter postNotification:notification];
+ [self.collectionViewLayout invalidateLayout];
+}
+
@end
=====================================
modules/gui/macosx/library/VLCLibraryUIUnits.h
=====================================
@@ -31,6 +31,8 @@ typedef NS_ENUM(NSUInteger, VLCLibraryCollectionViewItemAspectRatio) {
NS_ASSUME_NONNULL_BEGIN
+extern NSString * const VLCLibraryCollectionViewItemAdjustmentKey;
+
@interface VLCLibraryUIUnits : NSObject
// Note that these values are not necessarily linked to the layout defined in the .xib files.
=====================================
modules/gui/macosx/library/VLCLibraryUIUnits.m
=====================================
@@ -34,6 +34,8 @@
#import "windows/controlsbar/VLCControlsBarCommon.h"
+NSString * const VLCLibraryCollectionViewItemAdjustmentKey = @"VLCLibraryCollectionViewItemAdjustmentKey";
+
@implementation VLCLibraryUIUnits
+ (const CGFloat)largeSpacing
@@ -126,8 +128,8 @@
withLayout:(VLCLibraryCollectionViewFlowLayout *)collectionViewLayout
withItemsAspectRatio:(VLCLibraryCollectionViewItemAspectRatio)itemsAspectRatio
{
- static uint numItemsInRow = 5;
- static uint minItemsInRow = 2;
+ uint numItemsInRow = 5;
+ static const uint kMinItemsInCollectionViewRow = 1;
NSSize itemSize = [self itemSizeForCollectionView:collectionView
withLayout:collectionViewLayout
@@ -141,7 +143,7 @@
withItemsAspectRatio:itemsAspectRatio
withNumberOfItemsInRow:numItemsInRow];
}
- while (itemSize.width < VLCLibraryUIUnits.dynamicCollectionViewItemMinimumWidth && numItemsInRow > minItemsInRow) {
+ while (itemSize.width < VLCLibraryUIUnits.dynamicCollectionViewItemMinimumWidth && numItemsInRow > kMinItemsInCollectionViewRow) {
--numItemsInRow;
itemSize = [self itemSizeForCollectionView:collectionView
withLayout:collectionViewLayout
@@ -149,6 +151,16 @@
withNumberOfItemsInRow:numItemsInRow];
}
+ const NSInteger adjustment =
+ [NSUserDefaults.standardUserDefaults integerForKey:VLCLibraryCollectionViewItemAdjustmentKey];
+ if (adjustment != 0 && numItemsInRow + adjustment > kMinItemsInCollectionViewRow) {
+ numItemsInRow += adjustment;
+ itemSize = [self itemSizeForCollectionView:collectionView
+ withLayout:collectionViewLayout
+ withItemsAspectRatio:itemsAspectRatio
+ withNumberOfItemsInRow:numItemsInRow];
+ }
+
return itemSize;
}
@@ -170,7 +182,7 @@
(interItemSpacing * (numItemsInRow - 1)) +
1);
- const CGFloat itemWidth = rowOfItemsWidth / numItemsInRow;
+ const CGFloat itemWidth = MAX(rowOfItemsWidth / numItemsInRow, 1);
const CGFloat itemHeight = itemsAspectRatio == VLCLibraryCollectionViewItemAspectRatioDefaultItem ?
itemWidth + VLCLibraryCollectionViewItem.bottomTextViewsHeight :
(itemWidth * [VLCLibraryCollectionViewItem videoHeightAspectRatioMultiplier]) + VLCLibraryCollectionViewItem.bottomTextViewsHeight;
=====================================
modules/gui/macosx/views/VLCStatusNotifierView.m
=====================================
@@ -23,6 +23,7 @@
#import "VLCStatusNotifierView.h"
#import "extensions/NSString+Helpers.h"
+#import "library/VLCLibraryCollectionView.h"
#import "library/VLCLibraryModel.h"
NSString * const VLCStatusNotifierViewActivated = @"VLCStatusNotifierViewActivated";
@@ -144,6 +145,10 @@ NSString * const VLCStatusNotifierViewDeactivated = @"VLCStatusNotifierViewDeact
[self presentTransientMessage:self.libraryItemsLoadedMessage];
[self removeMessage:self.loadingLibraryItemsMessage];
}
+ } else if ([notificationName isEqualToString:VLCLibraryCollectionViewItemAdjustmentBigger]) {
+ [self presentTransientMessage:_NS("Increased grid view item size")];
+ } else if ([notificationName isEqualToString:VLCLibraryCollectionViewItemAdjustmentSmaller]) {
+ [self presentTransientMessage:_NS("Decreased grid view item size")];
}
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/259a7cfb63be47330ebc463ad2ee548e881dc384...c6af4fe30801e1a37acaa478698c80e5141854f6
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/259a7cfb63be47330ebc463ad2ee548e881dc384...c6af4fe30801e1a37acaa478698c80e5141854f6
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