[vlc-commits] qml: move clamp function to Helpers

Prince Gupta git at videolan.org
Tue Apr 6 13:11:57 UTC 2021


vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Wed Mar 17 20:05:26 2021 +0530| [dc7fa3cb40dcdad9b560f0e6464b7c715e4c4ba1] | committer: Pierre Lamot

qml: move clamp function to Helpers

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=dc7fa3cb40dcdad9b560f0e6464b7c715e4c4ba1
---

 modules/gui/qt/maininterface/qml/BannerSources.qml     | 11 ++++-------
 modules/gui/qt/maininterface/qml/MainDisplay.qml       |  7 ++++---
 modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml | 11 ++++++-----
 modules/gui/qt/util/qml/Helpers.js                     |  4 ++++
 modules/gui/qt/widgets/qml/HorizontalResizeHandle.qml  |  5 +----
 5 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/modules/gui/qt/maininterface/qml/BannerSources.qml b/modules/gui/qt/maininterface/qml/BannerSources.qml
index 92594f7271..7c217b5693 100644
--- a/modules/gui/qt/maininterface/qml/BannerSources.qml
+++ b/modules/gui/qt/maininterface/qml/BannerSources.qml
@@ -27,6 +27,7 @@ import "qrc:///style/"
 import "qrc:///widgets/" as Widgets
 import "qrc:///menus/" as Menus
 import "qrc:///util/KeyHelper.js" as KeyHelper
+import "qrc:///util/Helpers.js" as Helpers
 
 Widgets.NavigableFocusScope {
     id: root
@@ -325,15 +326,11 @@ Widgets.NavigableFocusScope {
                         enabled: status === Loader.Ready
                         y: (VLCStyle.localToolbar_height - item.height) / 2
                         width: !!item
-                               ? clamp(localMenuView.availableWidth
-                                       , localMenuGroup.item.minimumWidth || localMenuGroup.item.implicitWidth
-                                       , localMenuGroup.item.maximumWidth || localMenuGroup.item.implicitWidth)
+                               ? Helpers.clamp(localMenuView.availableWidth,
+                                               localMenuGroup.item.minimumWidth || localMenuGroup.item.implicitWidth,
+                                               localMenuGroup.item.maximumWidth || localMenuGroup.item.implicitWidth)
                                : 0
 
-                        function clamp(num, min, max) {
-                          return num <= min ? min : num >= max ? max : num;
-                        }
-
                         onVisibleChanged: {
                             //reset the focus on the global group when the local group is hidden,
                             //this avoids losing the focus if the subview changes
diff --git a/modules/gui/qt/maininterface/qml/MainDisplay.qml b/modules/gui/qt/maininterface/qml/MainDisplay.qml
index 1fc3f2fdaa..91789efaf0 100644
--- a/modules/gui/qt/maininterface/qml/MainDisplay.qml
+++ b/modules/gui/qt/maininterface/qml/MainDisplay.qml
@@ -25,6 +25,7 @@ import "qrc:///style/"
 import "qrc:///main/" as Main
 import "qrc:///widgets/" as Widgets
 import "qrc:///util/KeyHelper.js" as KeyHelper
+import "qrc:///util/Helpers.js" as Helpers
 import "qrc:///playlist/" as PL
 import "qrc:///player/" as Player
 
@@ -253,9 +254,9 @@ Widgets.NavigableFocusScope {
                                 name: "expanded"
                                 PropertyChanges {
                                     target: playlistColumn
-                                    width: resizeHandle.clamp(root.width / resizeHandle.widthFactor,
-                                                              playlist.minimumWidth,
-                                                              root.width / 2)
+                                    width: Helpers.clamp(root.width / resizeHandle.widthFactor,
+                                                         playlist.minimumWidth,
+                                                         root.width / 2)
                                     visible: true
                                 }
                             },
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml
index 2f72223fae..33b3b141d4 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml
@@ -23,6 +23,7 @@ import QtQuick.Layouts 1.3
 import org.videolan.medialib 0.1
 
 import "qrc:///util/" as Util
+import "qrc:///util/Helpers.js" as Helpers
 import "qrc:///widgets/" as Widgets
 import "qrc:///main/" as MainInterface
 import "qrc:///style/"
@@ -107,14 +108,14 @@ Widgets.NavigableFocusScope {
         Widgets.KeyNavigableListView {
             id: artistList
 
-            z: 1
-            width: resizeHandle.clamp(root.width / resizeHandle.widthFactor,
-                                      VLCStyle.colWidth(1) + VLCStyle.column_margin_width,
-                                      root.width * .5)
-            height: parent.height
             spacing: 4
             model: artistModel
             currentIndex: -1
+            z: 1
+            height: parent.height
+            width: Helpers.clamp(root.width / resizeHandle.widthFactor,
+                                 VLCStyle.colWidth(1) + VLCStyle.column_margin_width,
+                                 root.width * .5)
 
             focus: true
             footer: MainInterface.MiniPlayerBottomMargin {
diff --git a/modules/gui/qt/util/qml/Helpers.js b/modules/gui/qt/util/qml/Helpers.js
index 761d13a4c6..80768d1c7e 100644
--- a/modules/gui/qt/util/qml/Helpers.js
+++ b/modules/gui/qt/util/qml/Helpers.js
@@ -36,3 +36,7 @@ function msToString(time, short) {
         return "%1h%2".arg(hour.toFixed()).arg(prefixZero(min))
     return "%1:%2:%3".arg(prefixZero(hour)).arg(prefixZero(min)).arg(prefixZero(sec))
 }
+
+function clamp(num, min, max) {
+  return num <= min ? min : num >= max ? max : num;
+}
diff --git a/modules/gui/qt/widgets/qml/HorizontalResizeHandle.qml b/modules/gui/qt/widgets/qml/HorizontalResizeHandle.qml
index dc7216cdd7..099530e3da 100644
--- a/modules/gui/qt/widgets/qml/HorizontalResizeHandle.qml
+++ b/modules/gui/qt/widgets/qml/HorizontalResizeHandle.qml
@@ -24,7 +24,7 @@ import "qrc:///style/"
 // HorizontalResizeHandle actually doesn't resizes target
 // you have to assign target's width manually using widthFactor property
 // the idea behind using widthFactor is to maintain scale ratio when source itself resizes
-// e.g target.width: resizeHandle.clamp(sourceWidth / resizeHandle.widthFactor, minimumWidth, maximumWidth)
+// e.g target.width: Helpers.clamp(sourceWidth / resizeHandle.widthFactor, minimumWidth, maximumWidth)
 MouseArea {
     id: root
 
@@ -57,7 +57,4 @@ MouseArea {
         root.widthFactor = root.sourceWidth / (root.targetWidth + (delta * - f))
     }
 
-    function clamp(num, min, max) {
-      return num <= min ? min : num >= max ? max : num;
-    }
 }



More information about the vlc-commits mailing list