[vlc-devel] [VLC 3.x 08/11] macosx: Use NSButton subclass for badge drawing

david.fuhrmann at gmail.com david.fuhrmann at gmail.com
Wed Aug 26 16:24:05 CEST 2020


Lgtm for the set.

Von meinem iPhone gesendet

> Am 26.08.2020 um 00:51 schrieb Marvin Scholz <epirat07 at gmail.com>:
> 
> For badges in source lists a NSInlineBezelStyle button should be used
> according to the documentation. This greatly improves the look of the
> badge, especially in selected state and Dark Aqua.
> 
> (cherry picked from commit 9385e8ba801e1a3baee3580f29e011e162b7d993)
> Signed-off-by: Marvin Scholz <epirat07 at gmail.com>
> ---
> modules/gui/macosx/Makefile.am                |  2 +
> modules/gui/macosx/UI/MainWindow.xib          | 28 ++++----
> modules/gui/macosx/VLCMainWindow.m            | 10 +--
> modules/gui/macosx/VLCSourceListBadgeButton.h | 34 ++++++++++
> modules/gui/macosx/VLCSourceListBadgeButton.m | 65 +++++++++++++++++++
> .../gui/macosx/VLCSourceListTableCellView.h   | 35 ++++++++++
> .../gui/macosx/VLCSourceListTableCellView.m   | 28 ++++++++
> 7 files changed, 186 insertions(+), 16 deletions(-)
> create mode 100644 modules/gui/macosx/VLCSourceListBadgeButton.h
> create mode 100644 modules/gui/macosx/VLCSourceListBadgeButton.m
> create mode 100644 modules/gui/macosx/VLCSourceListTableCellView.h
> create mode 100644 modules/gui/macosx/VLCSourceListTableCellView.m
> 
> diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
> index 9957a27c2a..eed481e31a 100644
> --- a/modules/gui/macosx/Makefile.am
> +++ b/modules/gui/macosx/Makefile.am
> @@ -89,6 +89,8 @@ libmacosx_plugin_la_SOURCES = \
>    gui/macosx/VLCRendererMenuController.h gui/macosx/VLCRendererMenuController.m \
>    gui/macosx/VLCResumeDialogController.h gui/macosx/VLCResumeDialogController.m \
>    gui/macosx/VLCSourceListItem.h gui/macosx/VLCSourceListItem.m \
> +    gui/macosx/VLCSourceListTableCellView.h gui/macosx/VLCSourceListTableCellView.m \
> +    gui/macosx/VLCSourceListBadgeButton.h gui/macosx/VLCSourceListBadgeButton.m \
>    gui/macosx/VLCTrackSynchronizationWindowController.h gui/macosx/VLCTrackSynchronizationWindowController.m \
>    gui/macosx/VLCVideoEffectsWindowController.h gui/macosx/VLCVideoEffectsWindowController.m \
>    gui/macosx/VLCFSPanelController.h gui/macosx/VLCFSPanelController.m \
> diff --git a/modules/gui/macosx/UI/MainWindow.xib b/modules/gui/macosx/UI/MainWindow.xib
> index 24687803f6..1a1888b619 100644
> --- a/modules/gui/macosx/UI/MainWindow.xib
> +++ b/modules/gui/macosx/UI/MainWindow.xib
> @@ -169,7 +169,7 @@
>                                                                                 <outlet property="textField" destination="WaJ-bS-EIG" id="8lv-jw-399"/>
>                                                                             </connections>
>                                                                         </tableCellView>
> -                                                                        <tableCellView identifier="DataCell" id="xB8-ec-7Yv" customClass="PXSourceListTableCellView">
> +                                                                        <tableCellView identifier="DataCell" id="xB8-ec-7Yv" customClass="VLCSourceListTableCellView">
>                                                                             <rect key="frame" x="1" y="20" width="233" height="17"/>
>                                                                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
>                                                                             <subviews>
> @@ -180,32 +180,38 @@
>                                                                                     </constraints>
>                                                                                     <imageCell key="cell" refusesFirstResponder="YES" imageScaling="proportionallyUpOrDown" image="NSActionTemplate" id="sFV-eO-qxM"/>
>                                                                                 </imageView>
> -                                                                                <textField horizontalHuggingPriority="1000" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="0ju-Z4-RED">
> -                                                                                    <rect key="frame" x="22" y="0.0" width="96" height="17"/>
> +                                                                                <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="0ju-Z4-RED">
> +                                                                                    <rect key="frame" x="22" y="0.0" width="190" height="17"/>
>                                                                                     <textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="oiO-3f-qfh">
>                                                                                         <font key="font" metaFont="system"/>
>                                                                                         <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
>                                                                                         <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
>                                                                                     </textFieldCell>
>                                                                                 </textField>
> -                                                                                <customView translatesAutoresizingMaskIntoConstraints="NO" id="581-8x-wSd" customClass="PXSourceListBadgeView">
> -                                                                                    <rect key="frame" x="117" y="0.0" width="113" height="17"/>
> -                                                                                </customView>
> +                                                                                <button hidden="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZtM-n7-Nyl" customClass="VLCSourceListBadgeButton">
> +                                                                                    <rect key="frame" x="212" y="-1" width="20" height="17"/>
> +                                                                                    <buttonCell key="cell" type="inline" title="0" bezelStyle="inline" alignment="center" refusesFirstResponder="YES" state="on" borderStyle="border" inset="2" id="ZsW-rM-biz">
> +                                                                                        <behavior key="behavior" lightByContents="YES"/>
> +                                                                                        <font key="font" metaFont="smallSystemBold"/>
> +                                                                                    </buttonCell>
> +                                                                                    <userDefinedRuntimeAttributes>
> +                                                                                        <userDefinedRuntimeAttribute type="boolean" keyPath="hideWhenZero" value="YES"/>
> +                                                                                    </userDefinedRuntimeAttributes>
> +                                                                                </button>
>                                                                             </subviews>
>                                                                             <constraints>
> -                                                                                <constraint firstAttribute="bottom" secondItem="581-8x-wSd" secondAttribute="bottom" id="2Q3-wj-d1S"/>
> -                                                                                <constraint firstItem="581-8x-wSd" firstAttribute="leading" secondItem="0ju-Z4-RED" secondAttribute="trailing" constant="1" id="6WD-xB-kFQ"/>
>                                                                                 <constraint firstItem="xTO-W7-AeC" firstAttribute="centerY" secondItem="xB8-ec-7Yv" secondAttribute="centerY" id="Cby-pa-mb0"/>
>                                                                                 <constraint firstItem="xTO-W7-AeC" firstAttribute="top" secondItem="xB8-ec-7Yv" secondAttribute="top" constant="1" id="Mdd-rm-8bF"/>
> +                                                                                <constraint firstAttribute="trailing" secondItem="ZtM-n7-Nyl" secondAttribute="trailing" constant="1" id="RBP-b5-dRm"/>
>                                                                                 <constraint firstItem="xTO-W7-AeC" firstAttribute="leading" secondItem="xB8-ec-7Yv" secondAttribute="leading" constant="3" id="TLD-5C-SXg"/>
> -                                                                                <constraint firstAttribute="trailing" secondItem="581-8x-wSd" secondAttribute="trailing" constant="3" id="YNk-XC-3aD"/>
> -                                                                                <constraint firstItem="581-8x-wSd" firstAttribute="top" secondItem="xB8-ec-7Yv" secondAttribute="top" id="hHf-BC-6Cf"/>
> +                                                                                <constraint firstItem="ZtM-n7-Nyl" firstAttribute="centerY" secondItem="xB8-ec-7Yv" secondAttribute="centerY" id="dd7-wK-AY9"/>
>                                                                                 <constraint firstAttribute="bottom" secondItem="xTO-W7-AeC" secondAttribute="bottom" constant="1" id="hUY-JB-o3u"/>
>                                                                                 <constraint firstItem="0ju-Z4-RED" firstAttribute="centerY" secondItem="xTO-W7-AeC" secondAttribute="centerY" id="oDe-uz-van"/>
> +                                                                                <constraint firstItem="ZtM-n7-Nyl" firstAttribute="leading" secondItem="0ju-Z4-RED" secondAttribute="trailing" constant="2" id="rGB-F0-G1W"/>
>                                                                                 <constraint firstItem="0ju-Z4-RED" firstAttribute="leading" secondItem="xTO-W7-AeC" secondAttribute="trailing" constant="7" id="tNX-nJ-GgZ"/>
>                                                                             </constraints>
>                                                                             <connections>
> -                                                                                <outlet property="badgeView" destination="581-8x-wSd" id="2mh-uw-UwM"/>
> +                                                                                <outlet property="badgeView" destination="ZtM-n7-Nyl" id="bsQ-mM-b7K"/>
>                                                                                 <outlet property="imageView" destination="xTO-W7-AeC" id="XKu-Yf-XVN"/>
>                                                                                 <outlet property="textField" destination="0ju-Z4-RED" id="e8e-hp-hAG"/>
>                                                                             </connections>
> diff --git a/modules/gui/macosx/VLCMainWindow.m b/modules/gui/macosx/VLCMainWindow.m
> index 529bd040e1..972d96d5f5 100644
> --- a/modules/gui/macosx/VLCMainWindow.m
> +++ b/modules/gui/macosx/VLCMainWindow.m
> @@ -45,6 +45,8 @@
> #import "PXSourceList/PXSourceList.h"
> #import "PXSourceList/PXSourceListDataSource.h"
> 
> +#import "VLCSourceListTableCellView.h"
> +
> #import "VLCMainWindowControlsBar.h"
> #import "VLCVoutView.h"
> #import "VLCVoutWindowController.h"
> @@ -1128,7 +1130,7 @@ - (void)sourceListSelectionDidChange:(NSNotification *)notification
> 
> - (NSView *)sourceList:(PXSourceList *)aSourceList viewForItem:(id)item
> {
> -    PXSourceListTableCellView *cellView = nil;
> +    VLCSourceListTableCellView *cellView = nil;
>     if ([aSourceList levelForItem:item] == 0)
>         cellView = [aSourceList makeViewWithIdentifier:@"HeaderCell" owner:nil];
>     else
> @@ -1151,13 +1153,11 @@ - (NSView *)sourceList:(PXSourceList *)aSourceList viewForItem:(id)item
>         i_playlist_size = p_playlist->p_playing->i_children;
>         PL_UNLOCK;
> 
> -        cellView.badgeView.badgeValue = i_playlist_size;
> +        cellView.badgeView.integerValue = i_playlist_size;
>     } else {
> -        cellView.badgeView.badgeValue = sourceListItem.badgeValue.integerValue;
> +        cellView.badgeView.integerValue = sourceListItem.badgeValue.integerValue;
>     }
> 
> -    cellView.badgeView.hidden = cellView.badgeView.badgeValue == 0;
> -
>     return cellView;
> }
> 
> diff --git a/modules/gui/macosx/VLCSourceListBadgeButton.h b/modules/gui/macosx/VLCSourceListBadgeButton.h
> new file mode 100644
> index 0000000000..422c907b1c
> --- /dev/null
> +++ b/modules/gui/macosx/VLCSourceListBadgeButton.h
> @@ -0,0 +1,34 @@
> +/*****************************************************************************
> + * VLCSourceListBadgeButton.h: MacOS X interface module
> + *****************************************************************************
> + * Copyright (C) 2018 VLC authors and VideoLAN
> + * $Id$
> + *
> + * Authors: Marvin Scholz <epirat07 at gmail dot 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 VLCSourceListBadgeButton : NSButton
> +
> + at property IBInspectable BOOL hideWhenZero;
> +
> + at end
> +
> +NS_ASSUME_NONNULL_END
> diff --git a/modules/gui/macosx/VLCSourceListBadgeButton.m b/modules/gui/macosx/VLCSourceListBadgeButton.m
> new file mode 100644
> index 0000000000..ec14deef04
> --- /dev/null
> +++ b/modules/gui/macosx/VLCSourceListBadgeButton.m
> @@ -0,0 +1,65 @@
> +/*****************************************************************************
> + * VLCSourceListBadgeButton.m: MacOS X interface module
> + *****************************************************************************
> + * Copyright (C) 2018 VLC authors and VideoLAN
> + * $Id$
> + *
> + * Authors: Marvin Scholz <epirat07 at gmail dot 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 "VLCSourceListBadgeButton.h"
> +
> + at implementation VLCSourceListBadgeButton
> +
> +/* Ignore clicks on this button as we use it as badge so we want clicks to
> + * pass-through us and not handle them.
> + */
> +- (NSView *)hitTest:(NSPoint)point
> +{
> +    return nil;
> +}
> +
> +/* Our badges show integer values so make it easier to set those by setting
> + * the title depending on the integer value.
> + */
> +- (void)setIntegerValue:(NSInteger)integerValue
> +{
> +    [super setIntegerValue:integerValue];
> +
> +    self.title = [@(integerValue) stringValue];
> +
> +    if (_hideWhenZero)
> +        [self setHidden:(integerValue == 0)];
> +}
> +
> +/* "Alias" for setIntegerValue for normal int vs NSInteger
> + */
> +- (void)setIntValue:(int)intValue
> +{
> +    [self setIntegerValue:intValue];
> +}
> +
> +/* Return zero size when hidden
> + */
> +- (NSSize)intrinsicContentSize
> +{
> +    if (_hideWhenZero && self.hidden)
> +        return CGSizeZero;
> +    return [super intrinsicContentSize];
> +}
> +
> + at end
> diff --git a/modules/gui/macosx/VLCSourceListTableCellView.h b/modules/gui/macosx/VLCSourceListTableCellView.h
> new file mode 100644
> index 0000000000..451e4a4793
> --- /dev/null
> +++ b/modules/gui/macosx/VLCSourceListTableCellView.h
> @@ -0,0 +1,35 @@
> +/*****************************************************************************
> + * VLCSourceListTableCellView.h: MacOS X interface module
> + *****************************************************************************
> + * Copyright (C) 2018 VLC authors and VideoLAN
> + * $Id$
> + *
> + * Authors: Marvin Scholz <epirat07 at gmail dot 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>
> +#import "VLCSourceListBadgeButton.h"
> +
> +NS_ASSUME_NONNULL_BEGIN
> +
> + at interface VLCSourceListTableCellView : NSTableCellView
> +
> + at property (weak, nonatomic) IBOutlet VLCSourceListBadgeButton *badgeView;
> +
> + at end
> +
> +NS_ASSUME_NONNULL_END
> diff --git a/modules/gui/macosx/VLCSourceListTableCellView.m b/modules/gui/macosx/VLCSourceListTableCellView.m
> new file mode 100644
> index 0000000000..b567f0d28c
> --- /dev/null
> +++ b/modules/gui/macosx/VLCSourceListTableCellView.m
> @@ -0,0 +1,28 @@
> +/*****************************************************************************
> + * VLCSourceListTableCellView.m: MacOS X interface module
> + *****************************************************************************
> + * Copyright (C) 2018 VLC authors and VideoLAN
> + * $Id$
> + *
> + * Authors: Marvin Scholz <epirat07 at gmail dot 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 "VLCSourceListTableCellView.h"
> +
> + at implementation VLCSourceListTableCellView
> +
> + at end
> -- 
> 2.24.3 (Apple Git-128)
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list