Browse Source

Improvement to widget lifetime handling

Josh Engebretson 10 years ago
parent
commit
7a3644abfa

+ 2 - 0
Source/Atomic/UI/UIButton.cpp

@@ -2,6 +2,8 @@
 #include <TurboBadger/tb_widgets.h>
 #include <TurboBadger/tb_widgets.h>
 #include <TurboBadger/tb_widgets_common.h>
 #include <TurboBadger/tb_widgets_common.h>
 
 
+#include <Atomic/IO/Log.h>
+
 #include "UIEvents.h"
 #include "UIEvents.h"
 #include "UI.h"
 #include "UI.h"
 #include "UIButton.h"
 #include "UIButton.h"

+ 0 - 1
Source/Atomic/UI/UIWindow.cpp

@@ -33,7 +33,6 @@ void UIWindow::ResizeToFitContent()
 
 
 UIWindow::~UIWindow()
 UIWindow::~UIWindow()
 {
 {
-
 }
 }
 
 
 bool UIWindow::OnEvent(const tb::TBWidgetEvent &ev)
 bool UIWindow::OnEvent(const tb::TBWidgetEvent &ev)

+ 4 - 16
Source/AtomicJS/Javascript/JSUI.cpp

@@ -129,25 +129,18 @@ void JSUI::HandleWidgetLoaded(StringHash eventType, VariantMap& eventData)
     if (!heapptr)
     if (!heapptr)
         return;
         return;
 
 
-    // a loaded widget recursively gathers children which have id's and
-    // stashes them in an internal array, so that they don't go out of scope
-    // for instance var button = window.getWidgetByID("reveal");
-    // if we didn't stash, any callback on button wouldn't work if button went out
-    // of scope, which isn't expected behavior (in JS you would think the button is
-    // in some way attached to the window object)
-
     TBWidget* tbwidget = widget->GetInternalWidget();
     TBWidget* tbwidget = widget->GetInternalWidget();
     assert(tbwidget);
     assert(tbwidget);
 
 
+    // all widgets with id's are wrapped, so that event handlers are bubbled up properly
+    // note that all js widget object representations are kept alive in HandleObjectAdded
+    // when pushed into the VM
+
     PODVector<TBWidget*> widgets;
     PODVector<TBWidget*> widgets;
     GatherWidgets(tbwidget, widgets);
     GatherWidgets(tbwidget, widgets);
 
 
     UI* ui = GetSubsystem<UI>();
     UI* ui = GetSubsystem<UI>();
 
 
-    duk_push_heapptr(ctx_, heapptr);
-    duk_push_array(ctx_);
-
-    unsigned arrayCount = 0;
     for (unsigned i = 0; i < widgets.Size(); i++)
     for (unsigned i = 0; i < widgets.Size(); i++)
     {
     {
         UIWidget* o =  ui->WrapWidget(widgets.At(i));
         UIWidget* o =  ui->WrapWidget(widgets.At(i));
@@ -156,13 +149,8 @@ void JSUI::HandleWidgetLoaded(StringHash eventType, VariantMap& eventData)
             continue;
             continue;
 
 
         js_push_class_object_instance(ctx_, o);
         js_push_class_object_instance(ctx_, o);
-
-        duk_put_prop_index(ctx_, -2, arrayCount++);
     }
     }
 
 
-    duk_put_prop_string(ctx_, -2, "__child_widgets");
-    duk_pop(ctx_);
-
 }
 }
 
 
 void JSUI::HandlePopupMenuSelect(StringHash eventType, VariantMap& eventData)
 void JSUI::HandlePopupMenuSelect(StringHash eventType, VariantMap& eventData)