[vlc-commits] macosx: Add helper class for multi-line text fields
David Fuhrmann
git at videolan.org
Tue Oct 3 11:42:55 CEST 2017
vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Mon Oct 2 14:41:41 2017 +0200| [8b20b9d81581627dc88140d7961e76c737e73aa1] | committer: David Fuhrmann
macosx: Add helper class for multi-line text fields
Autolayout on 10.7 cannot handle multi line text fields
automatically. Add a helper class which help calulating the
intrinsic size of the text fields.
Use that class first in resume dialog.
refs #17730
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8b20b9d81581627dc88140d7961e76c737e73aa1
---
.../package/macosx/VLC.xcodeproj/project.pbxproj | 10 ++++-
modules/gui/macosx/Makefile.am | 4 +-
modules/gui/macosx/UI/ResumeDialog.xib | 24 +++++------
modules/gui/macosx/VLCWrappableTextField.h | 42 +++++++++++++++++++
modules/gui/macosx/VLCWrappableTextField.m | 49 ++++++++++++++++++++++
5 files changed, 114 insertions(+), 15 deletions(-)
diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index 06b76880fb..f744a656f9 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1C06F2A31F08F1250068846F /* osx_notifications.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C06F2A21F08F1250068846F /* osx_notifications.m */; };
1C18BE471F2926700053D329 /* keychain.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C18BE461F2926700053D329 /* keychain.m */; };
+ 1C1C62011F8260A90052DD4F /* VLCWrappableTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C1C62001F8260A90052DD4F /* VLCWrappableTextField.m */; };
1C31138E1E508C6900D4DD76 /* VLCAboutWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C67C8A71D58C0A40079E1C1 /* VLCAboutWindowController.m */; };
1C3113901E508C6900D4DD76 /* VLCHelpWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C67C8A41D58C0980079E1C1 /* VLCHelpWindowController.m */; };
1C3113921E508C6900D4DD76 /* VLCAddonListItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DF0435F1972E26A0022B534 /* VLCAddonListItem.m */; };
@@ -106,6 +107,8 @@
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
1C06F2A21F08F1250068846F /* osx_notifications.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = osx_notifications.m; path = ../../../modules/notify/osx_notifications.m; sourceTree = "<group>"; };
1C18BE461F2926700053D329 /* keychain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = keychain.m; path = ../../../modules/keystore/keychain.m; sourceTree = "<group>"; };
+ 1C1C61FF1F8260A90052DD4F /* VLCWrappableTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCWrappableTextField.h; sourceTree = "<group>"; };
+ 1C1C62001F8260A90052DD4F /* VLCWrappableTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCWrappableTextField.m; sourceTree = "<group>"; };
1C39ABBC1DA9AB9B00FE052A /* VLCDocumentController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCDocumentController.h; sourceTree = "<group>"; };
1C39ABBD1DA9AB9B00FE052A /* VLCDocumentController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCDocumentController.m; sourceTree = "<group>"; };
1C5716AB1F5B142200678627 /* coreaudio_common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = coreaudio_common.c; path = ../../../modules/audio_output/coreaudio_common.c; sourceTree = "<group>"; };
@@ -937,6 +940,8 @@
7D9516B91C60B6AB00D14E1A /* VLCStatusBarIcon.m */,
1CD366791B7A242E0054E39F /* VLCTimeSelectionPanelController.h */,
1CD3667A1B7A242E0054E39F /* VLCTimeSelectionPanelController.m */,
+ 1C1C61FF1F8260A90052DD4F /* VLCWrappableTextField.h */,
+ 1C1C62001F8260A90052DD4F /* VLCWrappableTextField.m */,
6BBBB8AF1D10A96B001BD9BA /* Renderers */,
6B846FE81CF5D89500112E54 /* HUD UI Classes */,
5CCED71414C0D4A90057F8D1 /* VLCUIWidgets.h */,
@@ -1704,7 +1709,7 @@
};
};
};
- buildConfigurationList = C2F2A6EA09588F1B00018C74 /* Build configuration list for PBXProject "VLC" */;
+ buildConfigurationList = C2F2A6EA09588F1B00018C74 /* Build configuration list for PBXProject "vlc" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
@@ -1794,6 +1799,7 @@
1C18BE471F2926700053D329 /* keychain.m in Sources */,
1C3113C71E508C6900D4DD76 /* VLCOpenWindowController.m in Sources */,
1C3113C91E508C6900D4DD76 /* VLCOutput.m in Sources */,
+ 1C1C62011F8260A90052DD4F /* VLCWrappableTextField.m in Sources */,
6BBB05DA1EEFEA29003A1019 /* VLCHUDOutlineView.m in Sources */,
1C3113CB1E508C6900D4DD76 /* VLCPLItem.m in Sources */,
1C3113CD1E508C6900D4DD76 /* VLCPLModel.m in Sources */,
@@ -2024,7 +2030,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Default;
};
- C2F2A6EA09588F1B00018C74 /* Build configuration list for PBXProject "VLC" */ = {
+ C2F2A6EA09588F1B00018C74 /* Build configuration list for PBXProject "vlc" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C2F2A6EB09588F1B00018C74 /* Development */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index 89e4f9aa45..4dc10142c9 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -70,6 +70,7 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/Windows.h gui/macosx/Windows.m \
gui/macosx/VLCAudioEffectsWindowController.h gui/macosx/VLCAudioEffectsWindowController.m \
gui/macosx/VLCBookmarksWindowController.h gui/macosx/VLCBookmarksWindowController.m \
+ gui/macosx/VLCBottomBarView.h gui/macosx/VLCBottomBarView.m \
gui/macosx/VLCCoreDialogProvider.h gui/macosx/VLCCoreDialogProvider.m \
gui/macosx/VLCLogMessage.h gui/macosx/VLCLogMessage.m \
gui/macosx/VLCLogWindowController.h gui/macosx/VLCLogWindowController.m \
@@ -104,7 +105,8 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/VLCSliderCell.h gui/macosx/VLCSliderCell.m \
gui/macosx/VLCVolumeSlider.h gui/macosx/VLCVolumeSlider.m \
gui/macosx/VLCVolumeSliderCell.h gui/macosx/VLCVolumeSliderCell.m \
- gui/macosx/VLCBottomBarView.h gui/macosx/VLCBottomBarView.m
+ gui/macosx/VLCWrappableTextField.h gui/macosx/VLCWrappableTextField.m
+
# User interface compilation
diff --git a/modules/gui/macosx/UI/ResumeDialog.xib b/modules/gui/macosx/UI/ResumeDialog.xib
index 501adcdab5..f6a078e90c 100644
--- a/modules/gui/macosx/UI/ResumeDialog.xib
+++ b/modules/gui/macosx/UI/ResumeDialog.xib
@@ -21,18 +21,17 @@
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" hidesOnDeactivate="YES" oneShot="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
<windowStyleMask key="styleMask" titled="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
- <rect key="contentRect" x="196" y="240" width="550" height="160"/>
+ <rect key="contentRect" x="196" y="240" width="549" height="160"/>
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="778"/>
<value key="minSize" type="size" width="446" height="133"/>
<view key="contentView" id="2">
- <rect key="frame" x="0.0" y="0.0" width="550" height="160"/>
+ <rect key="frame" x="0.0" y="0.0" width="549" height="160"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
- <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" preferredMaxLayoutWidth="560" translatesAutoresizingMaskIntoConstraints="NO" id="3">
- <rect key="frame" x="102" y="83" width="430" height="32"/>
+ <textField horizontalHuggingPriority="750" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" preferredMaxLayoutWidth="0.0" translatesAutoresizingMaskIntoConstraints="NO" id="3" customClass="VLCWrappableTextField">
+ <rect key="frame" x="102" y="83" width="429" height="32"/>
<constraints>
- <constraint firstAttribute="height" relation="greaterThanOrEqual" constant="32" id="YO6-yf-hXE"/>
- <constraint firstAttribute="height" relation="lessThanOrEqual" constant="128" id="i6c-N2-KuS"/>
+ <constraint firstAttribute="width" relation="greaterThanOrEqual" constant="425" id="kkj-bo-hIa"/>
</constraints>
<textFieldCell key="cell" truncatesLastVisibleLine="YES" sendsActionOnEndEditing="YES" title="Do you want to resume this file?
This-is-a-file" id="4">
<font key="font" metaFont="cellTitle"/>
@@ -40,7 +39,7 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
- <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="42">
+ <textField horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="42">
<rect key="frame" x="102" y="123" width="132" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Continue playback?" id="43">
<font key="font" metaFont="systemBold"/>
@@ -56,7 +55,7 @@
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="VLC" id="56"/>
</imageView>
- <button translatesAutoresizingMaskIntoConstraints="NO" id="85X-TN-2Hu">
+ <button horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="85X-TN-2Hu">
<rect key="frame" x="102" y="59" width="219" height="18"/>
<buttonCell key="cell" type="check" title="Always continue media playback" bezelStyle="regularSquare" imagePosition="left" inset="2" id="xHm-jn-IdY">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@@ -66,8 +65,8 @@
<action selector="resumeSettingChanged:" target="-2" id="alS-ps-u5T"/>
</connections>
</button>
- <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="21">
- <rect key="frame" x="441" y="13" width="95" height="32"/>
+ <button horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="21">
+ <rect key="frame" x="440" y="13" width="95" height="32"/>
<buttonCell key="cell" type="push" title="Continue" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="22">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -79,8 +78,8 @@ DQ
<action selector="buttonClicked:" target="-2" id="54"/>
</connections>
</button>
- <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9">
- <rect key="frame" x="357" y="13" width="84" height="32"/>
+ <button horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9">
+ <rect key="frame" x="356" y="13" width="84" height="32"/>
<buttonCell key="cell" type="push" title="Restart" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="10">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -102,6 +101,7 @@ DQ
<constraint firstAttribute="bottom" secondItem="9" secondAttribute="bottom" constant="20" id="SZk-pu-Lgd"/>
<constraint firstAttribute="bottom" secondItem="21" secondAttribute="bottom" constant="20" id="fiW-7M-G63"/>
<constraint firstItem="55" firstAttribute="leading" secondItem="2" secondAttribute="leading" constant="20" id="lQU-ef-GZw"/>
+ <constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="85X-TN-2Hu" secondAttribute="trailing" constant="20" id="mew-JH-yRV"/>
<constraint firstItem="21" firstAttribute="top" secondItem="85X-TN-2Hu" secondAttribute="bottom" constant="20" id="p8X-Vs-WZx"/>
<constraint firstItem="21" firstAttribute="leading" secondItem="9" secondAttribute="trailing" constant="12" id="xrB-He-ihV"/>
<constraint firstItem="42" firstAttribute="leading" secondItem="55" secondAttribute="trailing" constant="19" id="yR0-JV-Hcv"/>
diff --git a/modules/gui/macosx/VLCWrappableTextField.h b/modules/gui/macosx/VLCWrappableTextField.h
new file mode 100644
index 0000000000..065bc547a5
--- /dev/null
+++ b/modules/gui/macosx/VLCWrappableTextField.h
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * VLCWrappableTextField.h
+ *****************************************************************************
+ * Copyright (C) 2017 VideoLAN and authors
+ * Author: David Fuhrmann <dfuhrmann at videolan dot org>
+ *
+ * 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>
+
+/**
+ * Helper class for wrappable text multi line text fields on 10.7.
+ *
+ * Makes sure to try to wrap the text while calulating an intrinsic size for
+ * the field.
+ *
+ * For this to work, make sure that:
+ * - Field has a minimum width (best is to use >= constraint)
+ * - Field has layout set to wrap
+ * - Fields preferred with setting is explicit with constant 0 (auto or runtime
+ * width are not compatible with 10.7)
+ * - If text can change, make sure to have vertical hugging priorities > 500 so
+ * that window height can shrink again if text gets smaller.
+ *
+ * TODO: Revisit that code one 10.7 is dropped.
+ */
+ at interface VLCWrappableTextField : NSTextField
+
+ at end
\ No newline at end of file
diff --git a/modules/gui/macosx/VLCWrappableTextField.m b/modules/gui/macosx/VLCWrappableTextField.m
new file mode 100644
index 0000000000..ea975ea78c
--- /dev/null
+++ b/modules/gui/macosx/VLCWrappableTextField.m
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * VLCWrappableTextField.m
+ *****************************************************************************
+ * Copyright (C) 2017 VideoLAN and authors
+ * Author: David Fuhrmann <dfuhrmann at videolan dot org>
+ *
+ * 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 "VLCWrappableTextField.h"
+
+
+ at implementation VLCWrappableTextField
+
+- (NSSize)intrinsicContentSize
+{
+ if (![self.cell wraps]) {
+ return [super intrinsicContentSize];
+ }
+
+ // Try to get minimum height needed, by assuming unlimited height being
+ // (theoretically) possible.
+ NSRect frame = [self frame];
+ frame.size.height = CGFLOAT_MAX;
+
+ CGFloat height = [self.cell cellSizeForBounds:frame].height;
+
+ return NSMakeSize(frame.size.width, height);
+}
+
+- (void)textDidChange:(NSNotification *)notification
+{
+ [super textDidChange:notification];
+ [self invalidateIntrinsicContentSize];
+}
+
+ at end
\ No newline at end of file
More information about the vlc-commits
mailing list