[vlc-commits] [Git][videolan/vlc][master] 15 commits: macosx: Add constrainToFillView convenience method on NSView

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Mon Nov 11 10:38:38 UTC 2024



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


Commits:
9701ef9b by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Add constrainToFillView convenience method on NSView

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

- - - - -
09343613 by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Add constrainToFillSuperview method on NSView extension

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

- - - - -
55157bdf by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Directly create and apply loading overlay view constraints on creation, do not keep constraints around

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

- - - - -
a5a3e872 by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Remove unused constraint dictionary on videoview when presenting it in library window

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

- - - - -
45494532 by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Use convenience constrainToFillSuperview when presenting video view in library window

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

- - - - -
a339db66 by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Use convenience constrainToFillSuperview when adding scrollview to video grid container view

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

- - - - -
471b64e7 by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Use convenience constrainToFillSuperview when applying child subview to sidebar root view

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

- - - - -
5069263f by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Use convenience constrainToFillSuperview when setting decorative view in detached audio window

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

- - - - -
7fbf030a by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Apply constraints after setting audio decorative view as subview, use constrainToFillSuperview too

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

- - - - -
082bf186 by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Use constrainToFillSuperview convenience method when setting voutView back onto voutContainingView

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

- - - - -
19e78a02 by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Use constrainToFillSuperview convenience method when applying view on pip view controller

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

- - - - -
f3bac512 by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Improve names of constraints on superviews convenience methods

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

- - - - -
db8dcc3a by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Log warning when trying to apply constraints to fill superview when there is no valid superview

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

- - - - -
1175c9ed by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: When filling superview, apply the constraints to the superview, not self

Potentially avoid a retain cycle

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

- - - - -
2e4b4748 by Claudio Cambra at 2024-11-11T10:20:55+00:00
macosx: Assert when applying constraints to fill view that the superview is valid

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

- - - - -


8 changed files:

- modules/gui/macosx/extensions/NSView+VLCAdditions.h
- modules/gui/macosx/extensions/NSView+VLCAdditions.m
- modules/gui/macosx/library/VLCLibraryWindow.h
- modules/gui/macosx/library/VLCLibraryWindow.m
- modules/gui/macosx/library/VLCLibraryWindowSidebarRootViewController.m
- modules/gui/macosx/library/home-library/VLCLibraryHomeViewVideoGridContainerView.m
- modules/gui/macosx/windows/VLCDetachedAudioWindow.m
- modules/gui/macosx/windows/video/VLCMainVideoViewController.m


Changes:

=====================================
modules/gui/macosx/extensions/NSView+VLCAdditions.h
=====================================
@@ -32,6 +32,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property (readonly) BOOL shouldShowDarkAppearance;
 
 - (void)enableSubviews:(BOOL)enabled;
+- (NSArray<NSLayoutConstraint *> *)constraintsToFillView:(NSView *)view activate:(BOOL)activate;
+- (NSArray<NSLayoutConstraint *> *)applyConstraintsToFillSuperview;
 
 @end
 


=====================================
modules/gui/macosx/extensions/NSView+VLCAdditions.m
=====================================
@@ -78,4 +78,24 @@
     }
 }
 
+- (NSArray<NSLayoutConstraint *> *)applyConstraintsToFillSuperview
+{
+    NSAssert(self.superview, @"View must have a valid superview when applying fill constraints!");
+    return [self.superview constraintsToFillView:self activate:YES];
+}
+
+- (NSArray<NSLayoutConstraint *> *)constraintsToFillView:(NSView *)view activate:(BOOL)activate
+{
+    NSArray<NSLayoutConstraint *> * const constraints = @[
+        [self.leadingAnchor constraintEqualToAnchor:view.leadingAnchor],
+        [self.trailingAnchor constraintEqualToAnchor:view.trailingAnchor],
+        [self.topAnchor constraintEqualToAnchor:view.topAnchor],
+        [self.bottomAnchor constraintEqualToAnchor:view.bottomAnchor]
+    ];
+    if (activate) {
+        [NSLayoutConstraint activateConstraints:constraints];
+    }
+    return constraints;
+}
+
 @end


=====================================
modules/gui/macosx/library/VLCLibraryWindow.h
=====================================
@@ -116,7 +116,6 @@ extern const NSUserInterfaceItemIdentifier VLCLibraryWindowIdentifier;
 @property (nonatomic, readwrite, strong) IBOutlet VLCCustomEmptyLibraryBrowseButton *placeholderGoToBrowseButton;
 
 @property (readonly) VLCLoadingOverlayView *loadingOverlayView;
- at property (readonly) NSArray<NSLayoutConstraint *> *loadingOverlayViewConstraints;
 @property (readonly) NSArray<NSLayoutConstraint *> *placeholderImageViewConstraints;
 @property (readonly) VLCNoResultsLabel *noResultsLabel;
 


=====================================
modules/gui/macosx/library/VLCLibraryWindow.m
=====================================
@@ -215,36 +215,6 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
 {
     _loadingOverlayView = [[VLCLoadingOverlayView alloc] init];
     self.loadingOverlayView.translatesAutoresizingMaskIntoConstraints = NO;
-    _loadingOverlayViewConstraints = @[
-        [NSLayoutConstraint constraintWithItem:self.loadingOverlayView
-                                     attribute:NSLayoutAttributeTop
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.libraryTargetView
-                                     attribute:NSLayoutAttributeTop
-                                    multiplier:1
-                                      constant:0],
-        [NSLayoutConstraint constraintWithItem:self.loadingOverlayView
-                                     attribute:NSLayoutAttributeRight
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.libraryTargetView
-                                     attribute:NSLayoutAttributeRight
-                                    multiplier:1
-                                      constant:0],
-        [NSLayoutConstraint constraintWithItem:self.loadingOverlayView
-                                     attribute:NSLayoutAttributeBottom
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.libraryTargetView
-                                     attribute:NSLayoutAttributeBottom
-                                    multiplier:1
-                                      constant:0],
-        [NSLayoutConstraint constraintWithItem:self.loadingOverlayView
-                                     attribute:NSLayoutAttributeLeft
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.libraryTargetView
-                                     attribute:NSLayoutAttributeLeft
-                                    multiplier:1
-                                      constant:0]
-    ];
 }
 
 #pragma mark - misc. user interactions
@@ -778,42 +748,12 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
 
     NSLog(@"Presenting video view in main library window.");
 
-    NSView *videoView = self.videoViewController.view;
+    NSView * const videoView = self.videoViewController.view;
     videoView.translatesAutoresizingMaskIntoConstraints = NO;
     videoView.hidden = NO;
 
     [_libraryTargetView addSubview:videoView];
-    NSDictionary *dict = NSDictionaryOfVariableBindings(videoView);
-    [_libraryTargetView addConstraints:@[
-        [NSLayoutConstraint constraintWithItem:videoView
-                                     attribute:NSLayoutAttributeTop
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:_libraryTargetView
-                                     attribute:NSLayoutAttributeTop
-                                    multiplier:1.
-                                      constant:0.],
-        [NSLayoutConstraint constraintWithItem:videoView
-                                     attribute:NSLayoutAttributeBottom
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:_libraryTargetView
-                                     attribute:NSLayoutAttributeBottom
-                                    multiplier:1.
-                                      constant:0.],
-        [NSLayoutConstraint constraintWithItem:videoView
-                                     attribute:NSLayoutAttributeLeft
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:_libraryTargetView
-                                     attribute:NSLayoutAttributeLeft
-                                    multiplier:1.
-                                      constant:0.],
-        [NSLayoutConstraint constraintWithItem:videoView
-                                     attribute:NSLayoutAttributeRight
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:_libraryTargetView
-                                     attribute:NSLayoutAttributeRight
-                                    multiplier:1.
-                                      constant:0.]
-    ]];
+    [videoView applyConstraintsToFillSuperview];
 }
 
 - (void)enableVideoPlaybackAppearance
@@ -870,7 +810,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
 
     NSArray * const views = [self.libraryTargetView.subviews arrayByAddingObject:self.loadingOverlayView];
     self.libraryTargetView.subviews = views;
-    [self.libraryTargetView addConstraints:self.loadingOverlayViewConstraints];
+    [self.loadingOverlayView applyConstraintsToFillSuperview];
 
     [NSAnimationContext runAnimationGroup:^(NSAnimationContext * const context) {
         context.duration = 0.5;
@@ -893,7 +833,6 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
         context.duration = 1.0;
         self.loadingOverlayView.animator.alphaValue = 0.0;
     } completionHandler:^{
-        [self.libraryTargetView removeConstraints:self.loadingOverlayViewConstraints];
         NSMutableArray * const views = self.libraryTargetView.subviews.mutableCopy;
         [views removeObject:self.loadingOverlayView];
         self.libraryTargetView.subviews = views.copy;


=====================================
modules/gui/macosx/library/VLCLibraryWindowSidebarRootViewController.m
=====================================
@@ -24,6 +24,7 @@
 
 #import "extensions/NSFont+VLCAdditions.h"
 #import "extensions/NSString+Helpers.h"
+#import "extensions/NSView+VLCAdditions.h"
 #import "extensions/NSWindow+VLCAdditions.h"
 
 #import "main/VLCMain.h"
@@ -229,12 +230,7 @@
     NSView * const view = viewController.view;
     self.targetView.subviews = @[view];
     view.translatesAutoresizingMaskIntoConstraints = NO;
-    [NSLayoutConstraint activateConstraints:@[
-        [view.topAnchor constraintEqualToAnchor:self.targetView.topAnchor],
-        [view.bottomAnchor constraintEqualToAnchor:self.targetView.bottomAnchor],
-        [view.leadingAnchor constraintEqualToAnchor:self.targetView.leadingAnchor],
-        [view.trailingAnchor constraintEqualToAnchor:self.targetView.trailingAnchor]
-    ]];
+    [view applyConstraintsToFillSuperview];
 }
 
 - (void)setMainVideoModeEnabled:(BOOL)mainVideoModeEnabled


=====================================
modules/gui/macosx/library/home-library/VLCLibraryHomeViewVideoGridContainerView.m
=====================================
@@ -22,6 +22,8 @@
 
 #import "VLCLibraryHomeViewVideoGridContainerView.h"
 
+#import "extensions/NSView+VLCAdditions.h"
+
 #import "library/VLCLibraryCollectionViewDelegate.h"
 #import "library/VLCLibraryCollectionViewFlowLayout.h"
 #import "library/VLCLibraryCollectionViewItem.h"
@@ -62,40 +64,7 @@
     [self setupScrollView];
 
     [self addSubview:_scrollView];
-    [self addConstraints:@[
-        [NSLayoutConstraint constraintWithItem:_scrollView
-                                     attribute:NSLayoutAttributeTop
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self
-                                     attribute:NSLayoutAttributeTop
-                                    multiplier:1
-                                      constant:0
-        ],
-        [NSLayoutConstraint constraintWithItem:_scrollView
-                                     attribute:NSLayoutAttributeBottom
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self
-                                     attribute:NSLayoutAttributeBottom
-                                    multiplier:1
-                                      constant:0
-        ],
-        [NSLayoutConstraint constraintWithItem:_scrollView
-                                     attribute:NSLayoutAttributeLeft
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self
-                                     attribute:NSLayoutAttributeLeft
-                                    multiplier:1
-                                      constant:0
-        ],
-        [NSLayoutConstraint constraintWithItem:_scrollView
-                                     attribute:NSLayoutAttributeRight
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self
-                                     attribute:NSLayoutAttributeRight
-                                    multiplier:1
-                                      constant:0
-        ],
-    ]];
+    [self.scrollView applyConstraintsToFillSuperview];
 
     [self setContentHuggingPriority:NSLayoutPriorityDefaultLow
                      forOrientation:NSLayoutConstraintOrientationHorizontal];


=====================================
modules/gui/macosx/windows/VLCDetachedAudioWindow.m
=====================================
@@ -55,40 +55,7 @@
     [self.contentView addSubview:self.decorativeView 
                       positioned:NSWindowBelow
                       relativeTo:self.overlayView];
-    [self.contentView addConstraints:@[
-        [NSLayoutConstraint constraintWithItem:self.decorativeView
-                                     attribute:NSLayoutAttributeTop
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.contentView
-                                     attribute:NSLayoutAttributeTop
-                                    multiplier:1.
-                                      constant:0.
-        ],
-        [NSLayoutConstraint constraintWithItem:self.decorativeView
-                                     attribute:NSLayoutAttributeBottom
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.contentView
-                                     attribute:NSLayoutAttributeBottom
-                                    multiplier:1.
-                                      constant:0.
-        ],
-        [NSLayoutConstraint constraintWithItem:self.decorativeView
-                                     attribute:NSLayoutAttributeLeft
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.contentView
-                                     attribute:NSLayoutAttributeLeft
-                                    multiplier:1.
-                                      constant:0.
-        ],
-        [NSLayoutConstraint constraintWithItem:self.decorativeView
-                                     attribute:NSLayoutAttributeRight
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.contentView
-                                     attribute:NSLayoutAttributeRight
-                                    multiplier:1.
-                                      constant:0.
-        ],
-    ]];
+    [self.decorativeView applyConstraintsToFillSuperview];
 }
 
 - (void)awakeFromNib


=====================================
modules/gui/macosx/windows/video/VLCMainVideoViewController.m
=====================================
@@ -23,6 +23,7 @@
 
 #import "VLCMainVideoViewController.h"
 
+#import "extensions/NSView+VLCAdditions.h"
 #import "extensions/NSWindow+VLCAdditions.h"
 
 #import "library/VLCInputItem.h"
@@ -67,10 +68,7 @@
     [super viewWillAppear];
 
     if (self.view.superview) {
-        [self.view.superview.topAnchor constraintEqualToAnchor:self.view.topAnchor].active = YES;
-        [self.view.superview.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;
-        [self.view.superview.leftAnchor constraintEqualToAnchor:self.view.leftAnchor].active = YES;
-        [self.view.superview.rightAnchor constraintEqualToAnchor:self.view.rightAnchor].active = YES;
+        [self.view applyConstraintsToFillSuperview];
     }
 }
 
@@ -201,40 +199,7 @@
 
     NSView * const targetView = decorativeViewVisible ? self.audioDecorativeView : self.voutView;
     self.voutContainingView.subviews = @[targetView];
-    [self.voutContainingView addConstraints:@[
-        [NSLayoutConstraint constraintWithItem:targetView
-                                     attribute:NSLayoutAttributeTop
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.voutContainingView
-                                     attribute:NSLayoutAttributeTop
-                                    multiplier:1.
-                                      constant:0.
-        ],
-        [NSLayoutConstraint constraintWithItem:targetView
-                                     attribute:NSLayoutAttributeBottom
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.voutContainingView
-                                     attribute:NSLayoutAttributeBottom
-                                    multiplier:1.
-                                      constant:0.
-        ],
-        [NSLayoutConstraint constraintWithItem:targetView
-                                     attribute:NSLayoutAttributeLeft
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.voutContainingView
-                                     attribute:NSLayoutAttributeLeft
-                                    multiplier:1.
-                                      constant:0.
-        ],
-        [NSLayoutConstraint constraintWithItem:targetView
-                                     attribute:NSLayoutAttributeRight
-                                     relatedBy:NSLayoutRelationEqual
-                                        toItem:self.voutContainingView
-                                     attribute:NSLayoutAttributeRight
-                                    multiplier:1.
-                                      constant:0.
-        ],
-    ]];
+    [targetView applyConstraintsToFillSuperview];
 
     if (decorativeViewVisible) {
         [self setAutohideControls:NO];
@@ -584,12 +549,7 @@
     [self.view addSubview:self.voutContainingView
                positioned:NSWindowBelow
                relativeTo:self.mainControlsView];
-    [NSLayoutConstraint activateConstraints:@[
-        [self.voutContainingView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
-        [self.voutContainingView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
-        [self.voutContainingView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
-        [self.voutContainingView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor]
-    ]];
+    [self.voutContainingView applyConstraintsToFillSuperview];
     _voutViewController = nil;
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/71c2622ab992a4bb4485e5e151f3019e60543d35...2e4b474815dad0bd2a9d1e274610670665989fbd

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/71c2622ab992a4bb4485e5e151f3019e60543d35...2e4b474815dad0bd2a9d1e274610670665989fbd
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