[vlc-commits] [Git][videolan/vlc][master] 2 commits: macosx: Add VLCSubScrollView for nested scroll views
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Mon Sep 5 13:51:58 UTC 2022
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
449b9be4 by Claudio Cambra at 2022-09-05T11:24:28+00:00
macosx: Add VLCSubScrollView for nested scroll views
Signed-off-by: Claudio Cambra <claudio.cambra at gmail.com>
- - - - -
9471dc80 by Claudio Cambra at 2022-09-05T11:24:28+00:00
macosx: Make supplementary view scroll views scroll parent scroll views once at end scroll position
Signed-off-by: Claudio Cambra <claudio.cambra at gmail.com>
- - - - -
8 changed files:
- modules/gui/macosx/Makefile.am
- modules/gui/macosx/UI/VLCLibraryCollectionViewAlbumSupplementaryDetailView.xib
- modules/gui/macosx/UI/VLCLibraryCollectionViewAudioGroupSupplementaryDetailView.xib
- modules/gui/macosx/library/VLCLibraryAudioDataSource.m
- modules/gui/macosx/library/VLCLibraryCollectionViewSupplementaryDetailView.h
- modules/gui/macosx/library/VLCLibraryCollectionViewSupplementaryDetailView.m
- + modules/gui/macosx/views/VLCSubScrollView.h
- + modules/gui/macosx/views/VLCSubScrollView.m
Changes:
=====================================
modules/gui/macosx/Makefile.am
=====================================
@@ -233,6 +233,8 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/views/VLCSlider.m \
gui/macosx/views/VLCSliderCell.h \
gui/macosx/views/VLCSliderCell.m \
+ gui/macosx/views/VLCSubScrollView.h \
+ gui/macosx/views/VLCSubScrollView.m \
gui/macosx/views/VLCTimeField.h \
gui/macosx/views/VLCTimeField.m \
gui/macosx/views/VLCTrackingView.h \
=====================================
modules/gui/macosx/UI/VLCLibraryCollectionViewAlbumSupplementaryDetailView.xib
=====================================
@@ -118,7 +118,7 @@
<constraint firstItem="QuO-3G-BMT" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="HnP-Fk-juB" secondAttribute="trailing" constant="5" id="aD2-Ry-CuA"/>
</constraints>
</customView>
- <scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="52" horizontalPageScroll="10" verticalLineScroll="52" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" id="9ZS-oy-iP9">
+ <scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="52" horizontalPageScroll="10" verticalLineScroll="52" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" id="9ZS-oy-iP9" customClass="VLCSubScrollView">
<rect key="frame" x="0.0" y="0.0" width="701" height="198"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
<clipView key="contentView" drawsBackground="NO" id="3V4-tX-owM">
@@ -213,6 +213,7 @@
<outlet property="albumTitleTextField" destination="nCe-dY-YMM" id="h3l-p0-w3e"/>
<outlet property="albumTracksTableView" destination="eEJ-WA-0aM" id="l8k-M9-a8e"/>
<outlet property="albumYearAndDurationTextField" destination="QuO-3G-BMT" id="y34-rD-uR"/>
+ <outlet property="internalScrollView" destination="9ZS-oy-iP9" id="afa-6P-b12"/>
<outlet property="playAlbumButton" destination="ntd-VT-2KS" id="ah5-as-eqw"/>
</connections>
<point key="canvasLocation" x="-237.5" y="-284"/>
@@ -221,6 +222,6 @@
<resources>
<image name="no-art" width="128" height="128"/>
<image name="play.fill" catalog="system" width="12" height="13"/>
- <image name="plus" catalog="system" width="14" height="13"/>
+ <image name="plus" catalog="system" width="15" height="13"/>
</resources>
</document>
=====================================
modules/gui/macosx/UI/VLCLibraryCollectionViewAudioGroupSupplementaryDetailView.xib
=====================================
@@ -23,7 +23,7 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
- <scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" id="9ZS-oy-iP9">
+ <scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" id="9ZS-oy-iP9" customClass="VLCSubScrollView">
<rect key="frame" x="0.0" y="0.0" width="701" height="198"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" drawsBackground="NO" id="3V4-tX-owM">
@@ -84,6 +84,7 @@
<connections>
<outlet property="audioGroupAlbumsTableView" destination="eEJ-WA-0aM" id="l8k-M9-a8e"/>
<outlet property="audioGroupNameTextField" destination="nCe-dY-YMM" id="h3l-p0-w3e"/>
+ <outlet property="internalScrollView" destination="9ZS-oy-iP9" id="afa-6P-b12"/>
<outlet property="tableClipView" destination="3V4-tX-owM" id="t4b-1e-Cl1"/>
<outlet property="tableScrollView" destination="9ZS-oy-iP9" id="tab-L3-Scr"/>
</connections>
=====================================
modules/gui/macosx/library/VLCLibraryAudioDataSource.m
=====================================
@@ -39,6 +39,7 @@
#import "extensions/NSString+Helpers.h"
#import "views/VLCImageView.h"
+#import "views/VLCSubScrollView.h"
@interface VLCLibraryAudioDataSource () <NSCollectionViewDelegate, NSCollectionViewDataSource>
{
@@ -397,6 +398,8 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
VLCMediaLibraryAlbum *album = _displayedCollection[indexPath.item];
albumSupplementaryDetailView.representedAlbum = album;
albumSupplementaryDetailView.selectedItem = [collectionView itemAtIndex:indexPath.item];
+ albumSupplementaryDetailView.parentScrollView = [VLCMain sharedInstance].libraryWindow.audioCollectionViewScrollView;
+ albumSupplementaryDetailView.internalScrollView.scrollParentY = YES;
return albumSupplementaryDetailView;
@@ -407,6 +410,8 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
id<VLCMediaLibraryAudioGroupProtocol> audioGroup = _displayedCollection[indexPath.item];
audioGroupSupplementaryDetailView.representedAudioGroup = audioGroup;
audioGroupSupplementaryDetailView.selectedItem = [collectionView itemAtIndex:indexPath.item];
+ audioGroupSupplementaryDetailView.parentScrollView = [VLCMain sharedInstance].libraryWindow.audioCollectionViewScrollView;
+ audioGroupSupplementaryDetailView.internalScrollView.scrollParentY = YES;
return audioGroupSupplementaryDetailView;
}
=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewSupplementaryDetailView.h
=====================================
@@ -19,16 +19,21 @@
* 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 class VLCSubScrollView;
+
// This class can be subclassed to create new supplementary detail views for library views.
// It provides a consistent background and properties. It is not meant to be used directly.
@interface VLCLibraryCollectionViewSupplementaryDetailView : NSView <NSCollectionViewElement>
@property (readwrite, assign) NSCollectionViewItem *selectedItem;
+ at property (readwrite, assign) NSScrollView *parentScrollView;
+ at property (readwrite, assign) VLCSubScrollView *internalScrollView;
@end
=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewSupplementaryDetailView.m
=====================================
@@ -21,6 +21,7 @@
*****************************************************************************/
#import "VLCLibraryCollectionViewSupplementaryDetailView.h"
+#import "views/VLCSubScrollView.h"
static const CGFloat kArrowHeight = 20.;
static const CGFloat kArrowWidth = 50.;
@@ -79,5 +80,24 @@ static const CGFloat kBackgroundCornerRadius = 10.;
[backgroundPath stroke];
}
+- (NSScrollView *)parentScrollView
+{
+ if(_internalScrollView == nil) {
+ return nil;
+ }
+
+ return _internalScrollView.parentScrollView;
+}
+
+- (void)setParentScrollView:(NSScrollView *)parentScrollView
+{
+ if(_internalScrollView == nil) {
+ NSLog(@"Library collection view supplementary view has no internal scroll view -- cannot set parent scrollview.");
+ return;
+ }
+
+ _internalScrollView.parentScrollView = parentScrollView;
+}
+
@end
=====================================
modules/gui/macosx/views/VLCSubScrollView.h
=====================================
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * VLCSubScrollView.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <claudio.cambra at gmail.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
+
+// Use this scrollview when you are putting a scrollview within another scrollview.
+
+ at interface VLCSubScrollView : NSScrollView
+
+ at property (readwrite, assign) NSScrollView *parentScrollView;
+ at property (readwrite, assign) BOOL scrollParentY;
+ at property (readwrite, assign) BOOL scrollParentX;
+
+ at end
+
+NS_ASSUME_NONNULL_END
=====================================
modules/gui/macosx/views/VLCSubScrollView.m
=====================================
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * VLCSubScrollView.h: MacOS X interface module
+ *****************************************************************************
+ *
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <claudio.cambra at gmail.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 "VLCSubScrollView.h"
+
+ at implementation VLCSubScrollView
+
+- (instancetype)init
+{
+ self = [super init];
+
+ if(self) {
+ _scrollParentX = NO;
+ _scrollParentY = NO;
+ }
+
+ return self;
+}
+
+- (void)scrollWheel:(NSEvent *)event
+{
+ [super scrollWheel:event];
+
+ if(_parentScrollView == nil || (!_scrollParentX && !_scrollParentY)) {
+ return;
+ }
+
+ // Sometimes scroll views initialise with the Y value being almost 0, but not quite (e.g. 0.000824)
+ const BOOL isViewAtYStartAndScrollUp = self.verticalScroller.floatValue <= 0.01 && event.deltaY > 0;
+ const BOOL isViewAtYEndAndScrollDown = self.verticalScroller.floatValue >= 1. && event.deltaY < 0;
+ const BOOL isViewAtXStartAndScrollLeft = self.horizontalScroller.floatValue <= 0.01 && event.deltaX > 0;
+ const BOOL isViewAtXEndAndScrollRight = self.horizontalScroller.floatValue >= 1 && event.deltaX < 0;
+
+ const BOOL isSubScrollViewScrollableY = self.documentView.frame.size.height > self.documentVisibleRect.size.height;
+ const BOOL isSubScrollViewScrollableX = self.documentView.frame.size.width > self.documentVisibleRect.size.width;
+
+ const BOOL shouldScrollParentY = _scrollParentY && (!isSubScrollViewScrollableY || isViewAtYStartAndScrollUp || isViewAtYEndAndScrollDown);
+ const BOOL shouldScrollParentX = _scrollParentX && (!isSubScrollViewScrollableX || isViewAtXStartAndScrollLeft || isViewAtXEndAndScrollRight);
+
+ if(shouldScrollParentY || shouldScrollParentX) {
+ [_parentScrollView scrollWheel:event];
+ }
+}
+
+ at end
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e76f2c7d5e10909df0eea20101ebe3687d6b45d9...9471dc800c94ddc08bea1e5ebe935d94dd0a305e
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e76f2c7d5e10909df0eea20101ebe3687d6b45d9...9471dc800c94ddc08bea1e5ebe935d94dd0a305e
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