Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/main.min.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,11 +995,15 @@ class Viewer {
}
}

set_control_value(name, value) {
set_control_value(name, value, invoke_callback=true) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Believe it or not, default values are a relatively recent (2015-ish) feature in javascript. I'm glad we don't have to do if (invoke_callback === undefined) anymore...

if (name in this.gui_controllers && this.gui_controllers[name]
instanceof dat.controllers.NumberController) {
this.gui_controllers[name].setValue(value);
this.gui_controllers[name].updateDisplay();
if (invoke_callback) {
this.gui_controllers[name].setValue(value);
} else {
this.gui_controllers[name].object[name] = value;
this.gui_controllers[name].updateDisplay();
}
}
}

Expand Down Expand Up @@ -1031,7 +1035,7 @@ class Viewer {
} else if (cmd.type == "set_control") {
this.set_control(cmd.name, cmd.callback, cmd.value, cmd.min, cmd.max, cmd.step);
} else if (cmd.type == "set_control_value") {
this.set_control_value(cmd.name, cmd.value);
this.set_control_value(cmd.name, cmd.value, cmd.invoke_callback);
} else if (cmd.type == "delete_control") {
this.delete_control(cmd.name);
} else if (cmd.type == "capture_image") {
Expand Down
8 changes: 6 additions & 2 deletions test/controls.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
// Delete the first. Only the second should remain in the gui.
viewer.delete_control("TestButton");

viewer.set_control("TestSlider", () => {
console.log("TestSlider moved");
viewer.set_control("TestSlider", (value) => {
console.log("TestSlider = " + value);
}, .5, 0, 1, 0.01);
viewer.set_control_value("TestSlider", .2);

// Make sure nothing goes wrong here.
viewer.set_control_value("TestButton", .2);
viewer.set_control_value("TestButton2", .2);

// The slider is updated, but the javascript console confirms that
// the callback was not called.
viewer.set_control_value("TestSlider", .4, false);
</script>


Expand Down