From 8caa8feb9dce1d2551725bdd5d8ebf6a24c7185e Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Tue, 5 Oct 2021 10:51:26 -0700 Subject: [PATCH 1/2] Adjust pose decimals based on element width Signed-off-by: Nate Koenig --- src/gui/plugins/component_inspector/Pose3d.qml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/gui/plugins/component_inspector/Pose3d.qml b/src/gui/plugins/component_inspector/Pose3d.qml index 1a198f5402..27b468408b 100644 --- a/src/gui/plugins/component_inspector/Pose3d.qml +++ b/src/gui/plugins/component_inspector/Pose3d.qml @@ -75,6 +75,15 @@ Rectangle { ); } + // Get decimals based on a width + function getDecimals(width) { + if (width<= 80) + return 2; + else if (width <= 100) + return 4; + return 6; + } + FontMetrics { id: fontMetrics font.family: "Roboto" @@ -90,7 +99,7 @@ Rectangle { value: writableSpin.activeFocus ? writableSpin.value : numberValue minimumValue: -spinMax maximumValue: spinMax - decimals: 6 + decimals: getDecimals(writableSpin.width) onEditingFinished: { sendPose() } @@ -108,7 +117,7 @@ Rectangle { horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignVCenter text: { - var decimals = numberText.width < 100 ? 2 : 6 + var decimals = getDecimals(numberText.width) return numberValue.toFixed(decimals) } } From 0ce4e5c84efd1d97f18269cfadae79b89906e406 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 12 Oct 2021 10:39:52 -0700 Subject: [PATCH 2/2] Do the same for Vector3d Signed-off-by: Louise Poubel --- .../plugins/component_inspector/ComponentInspector.qml | 9 +++++++++ src/gui/plugins/component_inspector/Pose3d.qml | 9 --------- src/gui/plugins/component_inspector/Vector3d.qml | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/gui/plugins/component_inspector/ComponentInspector.qml b/src/gui/plugins/component_inspector/ComponentInspector.qml index e48bc4b393..dd688aafaa 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.qml +++ b/src/gui/plugins/component_inspector/ComponentInspector.qml @@ -78,6 +78,15 @@ Rectangle { return _model.dataType + '.qml' } + // Get number of decimal digits based on a widget's width + function getDecimals(_width) { + if (_width <= 80) + return 2; + else if (_width <= 100) + return 4; + return 6; + } + /** * Forward pose changes to C++ */ diff --git a/src/gui/plugins/component_inspector/Pose3d.qml b/src/gui/plugins/component_inspector/Pose3d.qml index 27b468408b..962acb770e 100644 --- a/src/gui/plugins/component_inspector/Pose3d.qml +++ b/src/gui/plugins/component_inspector/Pose3d.qml @@ -75,15 +75,6 @@ Rectangle { ); } - // Get decimals based on a width - function getDecimals(width) { - if (width<= 80) - return 2; - else if (width <= 100) - return 4; - return 6; - } - FontMetrics { id: fontMetrics font.family: "Roboto" diff --git a/src/gui/plugins/component_inspector/Vector3d.qml b/src/gui/plugins/component_inspector/Vector3d.qml index 900543701c..c6da529c8f 100644 --- a/src/gui/plugins/component_inspector/Vector3d.qml +++ b/src/gui/plugins/component_inspector/Vector3d.qml @@ -54,7 +54,7 @@ Rectangle { value: numberValue minimumValue: -spinMax maximumValue: spinMax - decimals: writableSpin.width < 100 ? 2 : 6 + decimals: getDecimals(writableSpin.width) } } @@ -69,7 +69,7 @@ Rectangle { horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignVCenter text: { - var decimals = numberText.width < 100 ? 2 : 6 + var decimals = getDecimals(numberText.width) return numberValue.toFixed(decimals) } }