Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust pose decimals based on element width #1089

Merged
merged 3 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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++
*/
Expand Down
4 changes: 2 additions & 2 deletions src/gui/plugins/component_inspector/Pose3d.qml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Rectangle {
value: writableSpin.activeFocus ? writableSpin.value : numberValue
minimumValue: -spinMax
maximumValue: spinMax
decimals: 6
decimals: getDecimals(writableSpin.width)
onEditingFinished: {
sendPose()
}
Expand All @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/plugins/component_inspector/Vector3d.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Rectangle {
value: numberValue
minimumValue: -spinMax
maximumValue: spinMax
decimals: writableSpin.width < 100 ? 2 : 6
decimals: getDecimals(writableSpin.width)
}
}

Expand All @@ -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)
}
}
Expand Down