Skip to content

Commit

Permalink
✨ slider support steps/precision
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed May 28, 2024
1 parent c616605 commit 2cf6baa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/editor/src/dom_widget_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class DomDemoNode extends LGraphNode {
this.addWidget("slider", "s1", 1.1, "s1", {
min: 0,
max: 2,
steps: 0.2,
step: 0.2,
precision: 1,
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@litegraph-ts/core",
"version": "0.2.21",
"version": "0.2.22",
"description": "A graph node editor similar to PD or UDK Blueprints. It works in an HTML5 Canvas and allows to export graphs to be included in applications.",
"source": "src/index.ts",
"types": "src/index.ts",
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/LGraphCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2068,15 +2068,14 @@ export default class LGraphCanvas
}
break;
case "slider": {
const { max, min, steps, precision } = w.options;
const { max, min, step, precision } = w.options;
var range = max - min;

// 这个函数计算步数,根据steps和precision调整取值
const calculateValue = (rawValue) => {
if (typeof steps === "number" && steps > 0) {
if (typeof step === "number" && step > 0) {
let stepValue =
min +
Math.round((rawValue - min) / steps) * steps;
Math.round((rawValue - min) / step) * step;
return parseFloat(stepValue.toFixed(precision));
}
return parseFloat(rawValue.toFixed(precision));
Expand Down

0 comments on commit 2cf6baa

Please sign in to comment.