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 1a198f5402..962acb770e 100644 --- a/src/gui/plugins/component_inspector/Pose3d.qml +++ b/src/gui/plugins/component_inspector/Pose3d.qml @@ -90,7 +90,7 @@ Rectangle { value: writableSpin.activeFocus ? writableSpin.value : numberValue minimumValue: -spinMax maximumValue: spinMax - decimals: 6 + decimals: getDecimals(writableSpin.width) onEditingFinished: { sendPose() } @@ -108,7 +108,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) } } 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) } }