From a6fc2347a07083865d74326bb2b23527483acba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=A0=EB=82=A8=ED=98=84?= Date: Mon, 26 Oct 2020 21:29:55 +0900 Subject: [PATCH] Update gtk.js --- lib/gtk.js | 58 +++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/lib/gtk.js b/lib/gtk.js index f096042..ac7d538 100644 --- a/lib/gtk.js +++ b/lib/gtk.js @@ -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;