mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-10 05:22:34 +08:00
Add toggle for float rounding
This commit is contained in:
parent
321c5fa295
commit
80dfeb089b
@ -577,6 +577,13 @@ export class ComfyUI {
|
||||
defaultValue: false,
|
||||
});
|
||||
|
||||
this.settings.addSetting({
|
||||
id: "Comfy.DisableFloatRounding",
|
||||
name: "Disable rounding floats (requires page reload).",
|
||||
type: "boolean",
|
||||
defaultValue: false,
|
||||
});
|
||||
|
||||
const fileInput = $el("input", {
|
||||
id: "comfy-file-input",
|
||||
type: "file",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { api } from "./api.js"
|
||||
|
||||
function getNumberDefaults(inputData, defaultStep) {
|
||||
function getNumberDefaults(inputData, defaultStep, app) {
|
||||
let defaultVal = inputData[1]["default"];
|
||||
let { min, max, step } = inputData[1];
|
||||
|
||||
@ -8,11 +8,16 @@ function getNumberDefaults(inputData, defaultStep) {
|
||||
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.
|
||||
// when using the old behavior, it defaults to 3 decimal places
|
||||
let precision = 3;
|
||||
let round = 0.001;
|
||||
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.
|
||||
round = Math.round(1000000*Math.pow(0.1,precision))/1000000;
|
||||
}
|
||||
|
||||
return { val: defaultVal, config: { min, max, step: 10.0 * step, round, precision } };
|
||||
}
|
||||
@ -268,15 +273,19 @@ export const ComfyWidgets = {
|
||||
"INT:noise_seed": seedWidget,
|
||||
FLOAT(node, inputName, inputData, app) {
|
||||
let widgetType = isSlider(inputData[1]["display"], app);
|
||||
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;
|
||||
}, config) };
|
||||
const { val, config } = getNumberDefaults(inputData, 0.5, app);
|
||||
if (!app.ui.settings.getSettingValue("Comfy.DisableFloatRounding")) {
|
||||
return { widget: node.addWidget(widgetType, inputName, val,
|
||||
function (v) {
|
||||
this.value = Math.round(v/config.round)*config.round;
|
||||
}, config) };
|
||||
} else {
|
||||
return { widget: node.addWidget(widgetType, inputName, val, () => {}, config) };
|
||||
}
|
||||
},
|
||||
INT(node, inputName, inputData, app) {
|
||||
let widgetType = isSlider(inputData[1]["display"], app);
|
||||
const { val, config } = getNumberDefaults(inputData, 1);
|
||||
const { val, config } = getNumberDefaults(inputData, 1, app);
|
||||
Object.assign(config, { precision: 0 });
|
||||
return {
|
||||
widget: node.addWidget(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user