Skip to content

Commit 0465d3d

Browse files
committed
give window app property, some fiddling
1 parent e573361 commit 0465d3d

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

classes/window.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ zend_object* php_ui_window_create(zend_class_entry *ce) {
6969
int php_ui_window_closing_handler(uiWindow *w, void *arg) {
7070
php_ui_window_t *window = (php_ui_window_t *) arg;
7171
zval rv;
72-
int result = 1;
72+
int result = 0;
7373

7474
if (!window->closing.fci.size) {
7575
uiControlDestroy(uiControl(window->w));
@@ -83,7 +83,10 @@ int php_ui_window_closing_handler(uiWindow *w, void *arg) {
8383
window->closing.fci.retval = &rv;
8484

8585
if (zend_call_function(&window->closing.fci, &window->closing.fcc) != SUCCESS) {
86-
return 1;
86+
uiControlDestroy(uiControl(window->w));
87+
uiQuit();
88+
89+
return 0;
8790
}
8891

8992
if (Z_TYPE(rv) != IS_UNDEF) {
@@ -123,6 +126,8 @@ PHP_METHOD(Window, __construct)
123126
uiWindowOnClosing(win->w, php_ui_window_closing_handler, win);
124127

125128
php_ui_app_window(app, getThis());
129+
130+
zend_update_property(win->std.ce, getThis(), ZEND_STRL("app"), app);
126131
} /* }}} */
127132

128133
ZEND_BEGIN_ARG_INFO_EX(php_ui_window_set_title_info, 0, 0, 1)
@@ -443,6 +448,7 @@ PHP_MINIT_FUNCTION(UI_Window)
443448
uiWindow_ce = zend_register_internal_class_ex(&ce, uiControl_ce);
444449
uiWindow_ce->create_object = php_ui_window_create;
445450
zend_declare_property_null(uiWindow_ce, ZEND_STRL("controls"), ZEND_ACC_PROTECTED);
451+
zend_declare_property_null(uiWindow_ce, ZEND_STRL("app"), ZEND_ACC_PROTECTED);
446452

447453
memcpy(&php_ui_window_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
448454

examples/starfield.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,25 @@
1616
use UI\Executor;
1717

1818
$app = new App;
19-
$win = new Window($app, "Starfield", new Size(640, 480), false);
19+
20+
$win = new class($app, "Starfield", new Size(640, 480), false) extends Window {
21+
22+
public function addExecutor(Executor $executor) {
23+
$this->executors[] = $executor;
24+
}
25+
26+
protected function onClosing() {
27+
foreach ($this->executors as $executor) {
28+
$executor->kill();
29+
}
30+
31+
$this->destroy();
32+
$this->app->quit();
33+
34+
unset($this->app); # not sure why, yet
35+
}
36+
};
37+
2038
$box = new Box(Box::Vertical);
2139
$win->add($box);
2240

@@ -136,6 +154,8 @@ public function __construct(int $microseconds, Area $area) {
136154
}
137155
};
138156

157+
$win->addExecutor($animator);
158+
139159
$win->show();
140160

141161
$app->run();

0 commit comments

Comments
 (0)