Update gtk.js

This commit is contained in:
Namhyeon Go 2020-10-26 21:29:55 +09:00
parent eb5f585588
commit a6fc2347a0

View File

@ -34,31 +34,13 @@ var GTKCreateWidget = function(widget) {
break;
case "Table":
// attach sub widgets to table widget
var subWidgets = widget.attachedWidgets;
var countSubWidgets = subWidgets.length;
while (countSubWidgets > 0) {
commands.push([
"gtk_table_attach_defaults",
widget.widgetID,
subWidgets[i].widget.widgetID,
subWidgets[i].left,
subWidgets[i].right,
subWidgets[i].top,
subWidgets[i].bottom
]);
countSubWidgets--;
}
// create table widget
commands.push([
"gtk_table_new",
widget.rows,
widget.columns,
widget.homogeneous
]);
break;
case "Button":
@ -94,12 +76,8 @@ var GTKCreateWidget = function(widget) {
break;
}
// get widgetID from first command
widgetID = GTKExecCommand(commands.pop());
// execute next commands
while (commands.length > 0) {
GTKExecCommand(commands.pop());
widgetID = GTKExecCommand(commands.pop());
}
return widgetID;
@ -113,7 +91,7 @@ var GTKExecCommand = function(command) {
var term = command[i];
if (typeof(term) == "number") {
_command.push(term == 0 ? '0' : command[i]);
_command.push(term == 0 ? '0' : term);
} else if (typeof(term) == "boolean") {
_command.push(!term ? '0' : '1');
} else if (typeof(term) == "string") {
@ -172,13 +150,17 @@ var Table = function() {
this.attachedWidgets = [];
this.attach = function(widget, left, right, top, bottom) {
this.attachedWidgets.push({
"widget": widget,
"left": left,
"right": right,
"top": top,
"bottom": bottom
});
this.attachedWidgets.push(widget);
return GTKExecCommand([
"gtk_table_attach_defaults",
this.widgetID,
widget.widgetID,
left,
right,
top,
bottom
]);
};
};
Table.prototype = new GTKWidget();
@ -271,7 +253,7 @@ TextBox.prototype = new GTKWidget();
TextBox.prototype.constructor = TextBox;
// GTKWait
var GTKWait = function() {
var GTKWait = function(callback) {
var even;
GTKInit();
@ -285,9 +267,19 @@ var GTKWait = function() {
if (even in GTKWidgets) {
GTKWidgets[even].onEventTriggered();
}
if (typeof(callback) == "function") {
callback(even);
}
}
GTKExit();
};
exports.Window = Window;
exports.Table = Table;
exports.Button = Button;
exports.Entry = Entry;
exports.RadioBox = RadioBox;
exports.TextBox = TextBox;
exports.wait = GTKWait;