Skip to content

Commit

Permalink
Adaptive step for number inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelTallet committed Apr 19, 2021
1 parent d47715b commit f7fd8e0
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 45 deletions.
8 changes: 8 additions & 0 deletions source/parametric_modeling/HTML Dialogs/nodes-editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ body {
width: 98px;
}

#pmg-nodes-editor .node input[type="number"]::-webkit-outer-spin-button,
#pmg-nodes-editor .node input[type="number"]::-webkit-inner-spin-button {

-webkit-appearance: none;
margin: 0;

}

#pmg-nodes-editor .node input[type="text"] {
width: 100%;
}
Expand Down
41 changes: 41 additions & 0 deletions source/parametric_modeling/HTML Dialogs/nodes-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,31 @@ PMG.NodesEditor.loadToolbarIcons = () => {

}

PMG.NodesEditor.adaptNumberInputStep = input => {

if ( isNaN(parseFloat(input.step)) ) {
input.step = 1
}

if ( input.value.indexOf('.') !== -1 ) {

var inputParts = input.value.split('.')

if ( inputParts.length === 2 ) {

var inputDecimalPart = inputParts[1]
var inputStepCandidate = 1 / parseFloat('1' + '0'.repeat(inputDecimalPart.length))

if ( inputStepCandidate < input.step ) {
input.step = inputStepCandidate
}

}

}

}

PMG.NodesEditor.schemaIsExportable = false

PMG.NodesEditor.exportModelSchema = redraw => {
Expand Down Expand Up @@ -1761,7 +1786,11 @@ PMG.NodesEditor.addEventListeners = () => {
nodeElement.querySelectorAll('input[type="number"]').forEach(nodeNumberInputElement => {

nodeNumberInputElement.addEventListener('input', _event => {

PMG.NodesEditor.exportModelSchema(true)

PMG.NodesEditor.adaptNumberInputStep(nodeNumberInputElement)

})

})
Expand Down Expand Up @@ -1889,6 +1918,14 @@ PMG.NodesEditor.showOrHideMinimap = () => {

}

PMG.NodesEditor.resetNumberInputsStep = () => {

document.querySelectorAll('input[type="number"]').forEach(numberInputElement => {
numberInputElement.step = 1
})

}

PMG.NodesEditor.setGlobalContextMenu = () => {

var contextMenuOptions = [
Expand All @@ -1908,6 +1945,10 @@ PMG.NodesEditor.setGlobalContextMenu = () => {
name: t('Show or hide minimap'),
fn: () => { PMG.NodesEditor.showOrHideMinimap() }
},
{
name: t('Reset increment values'),
fn: () => { PMG.NodesEditor.resetNumberInputsStep() }
},
{
name: t('Remove all nodes'),
fn: () => { PMG.NodesEditor.editor.clear() }
Expand Down
1 change: 1 addition & 0 deletions source/parametric_modeling/Resources/fr/pmg.translation
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"Export schema to a file"="Exporter le schéma vers un fichier";
"Freeze parametric entities"="Geler les entités paramétriques";
"Show or hide minimap"="Afficher ou masquer la mini-carte";
"Reset increment values"="Réinitialiser les valeurs d'incrément";
"Remove all nodes"="Supprimer tous les nœuds";
"Access online help"="Accéder à l'aide en ligne";
"Error: Nodes Editor schema is incompatible."="Erreur : Le schéma de l'éditeur de nœuds est incompatible.";
Expand Down
Loading

0 comments on commit f7fd8e0

Please sign in to comment.