diff --git a/custom_nodes/example_node.py.example b/custom_nodes/example_node.py.example index e37808b03..733014f3c 100644 --- a/custom_nodes/example_node.py.example +++ b/custom_nodes/example_node.py.example @@ -54,7 +54,13 @@ class Example: "step": 64, #Slider's step "display": "number" # Cosmetic only: display as "number" or "slider" }), - "float_field": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01, "display": "number"}), + "float_field": ("FLOAT", { + "default": 1.0, + "min": 0.0, + "max": 10.0, + "step": 0.01, + "round": 0.001, #The value represeting the precision to round to, will be set to the step value by default. Can be set to False to disable rounding. + "display": "number"}), "print_to_screen": (["enable", "disable"],), "string_field": ("STRING", { "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node diff --git a/nodes.py b/nodes.py index 77d180526..3bc08663e 100644 --- a/nodes.py +++ b/nodes.py @@ -1217,7 +1217,7 @@ class KSampler: {"model": ("MODEL",), "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), "steps": ("INT", {"default": 20, "min": 1, "max": 10000}), - "cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}), + "cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step":0.5, "round": 0.01}), "sampler_name": (comfy.samplers.KSampler.SAMPLERS, ), "scheduler": (comfy.samplers.KSampler.SCHEDULERS, ), "positive": ("CONDITIONING", ), @@ -1243,7 +1243,7 @@ class KSamplerAdvanced: "add_noise": (["enable", "disable"], ), "noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), "steps": ("INT", {"default": 20, "min": 1, "max": 10000}), - "cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}), + "cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step":0.5, "round": 0.01}), "sampler_name": (comfy.samplers.KSampler.SAMPLERS, ), "scheduler": (comfy.samplers.KSampler.SCHEDULERS, ), "positive": ("CONDITIONING", ), diff --git a/web/scripts/widgets.js b/web/scripts/widgets.js index 790928d14..942be8f36 100644 --- a/web/scripts/widgets.js +++ b/web/scripts/widgets.js @@ -2,26 +2,25 @@ import { api } from "./api.js" function getNumberDefaults(inputData, defaultStep, app) { 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. - // when using the old behavior, it defaults to 3 decimal places - let precision = 3; - let round = 0.001; - if (app.ui.settings.getSettingValue("Comfy.FloatRoundingPrecision") > 0) { + // 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 (app.ui.settings.getSettingValue("Comfy.FloatRoundingPrecision") > 0) { precision = app.ui.settings.getSettingValue("Comfy.FloatRoundingPrecision"); - round = Math.round(1000000*Math.pow(0.1,precision))/1000000; - } else if (!app.ui.settings.getSettingValue("Comfy.DisableFloatRounding")) { - // display the the smallest number of decimal places such that changes of size step are visible. - precision = Math.max(-Math.floor(Math.log10(step)),0); - // round the value to those decimal places shown. + } + + if (!app.ui.settings.getSettingValue("Comfy.DisableFloatRounding") && (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 } }; } @@ -277,14 +276,14 @@ export const ComfyWidgets = { FLOAT(node, inputName, inputData, app) { let widgetType = isSlider(inputData[1]["display"], app); const { val, config } = getNumberDefaults(inputData, 0.5, app); - if (!app.ui.settings.getSettingValue("Comfy.DisableFloatRounding")) { - return { widget: node.addWidget(widgetType, inputName, val, - function (v) { + return { widget: node.addWidget(widgetType, inputName, val, + function (v) { + if (config.round) { this.value = Math.round(v/config.round)*config.round; - }, config) }; - } else { - return { widget: node.addWidget(widgetType, inputName, val, () => {}, config) }; - } + } else { + this.value = v; + } + }, config) }; }, INT(node, inputName, inputData, app) { let widgetType = isSlider(inputData[1]["display"], app);