|
|
|
@ -2,17 +2,22 @@ import { api } from "./api.js"
|
|
|
|
|
|
|
|
|
|
function getNumberDefaults(inputData, defaultStep) { |
|
|
|
|
let defaultVal = inputData[1]["default"]; |
|
|
|
|
let { min, max, step } = inputData[1]; |
|
|
|
|
let { min, max, step, round} = inputData[1]; |
|
|
|
|
|
|
|
|
|
if (defaultVal == undefined) defaultVal = 0; |
|
|
|
|
if (min == undefined) min = 0; |
|
|
|
|
if (max == undefined) max = 2048; |
|
|
|
|
if (step == undefined) step = defaultStep; |
|
|
|
|
// precision is the number of decimal places to show.
|
|
|
|
|
// by default, display the the smallest number of decimal places such that changes of size step are visible.
|
|
|
|
|
let precision = Math.max(-Math.floor(Math.log10(step)),0) |
|
|
|
|
// by default, round the value to those decimal places shown.
|
|
|
|
|
let round = Math.round(1000000*Math.pow(0.1,precision))/1000000; |
|
|
|
|
|
|
|
|
|
// precision is the number of decimal places to show.
|
|
|
|
|
// by default, display the the smallest number of decimal places such that changes of size step are visible.
|
|
|
|
|
let precision = Math.max(-Math.floor(Math.log10(step)),0); |
|
|
|
|
|
|
|
|
|
if (round == undefined || round === true) { |
|
|
|
|
// by default, round the value to those decimal places shown.
|
|
|
|
|
round = Math.round(1000000*Math.pow(0.1,precision))/1000000; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { val: defaultVal, config: { min, max, step: 10.0 * step, round, precision } }; |
|
|
|
|
} |
|
|
|
@ -271,7 +276,11 @@ export const ComfyWidgets = {
|
|
|
|
|
const { val, config } = getNumberDefaults(inputData, 0.5); |
|
|
|
|
return { widget: node.addWidget(widgetType, inputName, val,
|
|
|
|
|
function (v) { |
|
|
|
|
this.value = Math.round(v/config.round)*config.round; |
|
|
|
|
if (config.round) { |
|
|
|
|
this.value = Math.round(v/config.round)*config.round; |
|
|
|
|
} else { |
|
|
|
|
this.value = v; |
|
|
|
|
} |
|
|
|
|
}, config) }; |
|
|
|
|
}, |
|
|
|
|
INT(node, inputName, inputData, app) { |
|
|
|
|