1
0
Fork 0

Added canvas checkbox subclass whose check state is always the bool value of a node and vice versa

This commit is contained in:
TheFGFSEagle 2022-12-21 10:14:19 +01:00 committed by James Turner
parent 8d5e4aaf1c
commit 09e15ddf16
2 changed files with 35 additions and 0 deletions

View file

@ -37,6 +37,7 @@ loadWidget("Button");
loadWidget("CheckBox");
loadWidget("Label");
loadWidget("LineEdit");
loadWidget("PropertyWidgets");
loadWidget("ScrollArea");
loadWidget("Rule");
loadWidget("Slider");
@ -308,6 +309,7 @@ var Window = {
{
me._ghost.show();
me.raise();
me._canvas.update();
},
# Hide / show the window based on whether it's currently visible
toggle: func()

View file

@ -0,0 +1,33 @@
# PropertyWidgets.nas - subclassed canvas widgets that are synced with a property node
# SPDX-FileCopyrightText: (C) 2022 Frederic Croix <thefgfseagle@gmail.com>
# SPDX-License-Identifier: GPL-2.0-or-later
gui.widgets.PropertyCheckBox = {
new: func(node, parent, style, cfg) {
if (!isa(node, props.Node)) {
node = props.globals.getNode(node, 1);
}
var m = gui.widgets.CheckBox.new(parent, style, cfg);
m._checkable = 1;
m._node = node;
append(m.parents, gui.widgets.PropertyCheckBox);
m.setChecked(m._node.getBoolValue());
m.listen("toggled", func(e) {
m._node.setBoolValue(int(e.detail.checked));
});
m._listener = setlistener(m._node, func(n) {
m.setChecked(n.getBoolValue());
}, 1, 0);
return m;
},
del: func {
removelistener(me._listener);
},
};