mirror of
https://github.com/Ultimaker/Cura.git
synced 2026-02-26 22:35:46 -07:00
SpinBox fixed for values above the max value
Spinbox now doesn't take values above the designated maximum Fixes CURA-10096
This commit is contained in:
parent
f0186ff9e3
commit
fe5893feb6
1 changed files with 21 additions and 1 deletions
|
|
@ -54,9 +54,20 @@ Item
|
|||
from: Math.floor(base.from / base.stepSize)
|
||||
to: Math.floor(base.to / base.stepSize)
|
||||
|
||||
function clamp(value, min, max)
|
||||
{
|
||||
return Math.max((Math.min(value, max)), min);
|
||||
}
|
||||
|
||||
valueFromText: function(text)
|
||||
{
|
||||
return parseFloat(text.substring(prefix.length, text.length - suffix.length).replace(",", ".")) / base.stepSize;
|
||||
|
||||
var value = parseFloat(text.substring(prefix.length, text.length - suffix.length).replace(",", ".")) / base.stepSize ;
|
||||
if (Number.isNaN(value))
|
||||
{
|
||||
value = from
|
||||
}
|
||||
return clamp(value, from, to);
|
||||
}
|
||||
|
||||
textFromValue: function(value)
|
||||
|
|
@ -69,6 +80,7 @@ Item
|
|||
onValueModified:
|
||||
{
|
||||
base.value = value * base.stepSize;
|
||||
spinBoxText.text = spinBox.textFromValue(value);
|
||||
}
|
||||
|
||||
// This forces TextField to commit typed values before incrementing with buttons.
|
||||
|
|
@ -87,6 +99,7 @@ Item
|
|||
|
||||
contentItem: Cura.TextField
|
||||
{
|
||||
id: spinBoxText
|
||||
text: spinBox.textFromValue(spinBox.value, spinBox.locale)
|
||||
validator: base.validator
|
||||
|
||||
|
|
@ -97,6 +110,13 @@ Item
|
|||
base.editingFinished();
|
||||
}
|
||||
}
|
||||
|
||||
onTextChanged:
|
||||
{
|
||||
var value = spinBox.valueFromText(spinBoxText.text);
|
||||
spinBoxText.text = spinBox.textFromValue(value);
|
||||
spinBox.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
down.indicator: Rectangle
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue