|
@@ -1,5 +1,8 @@
|
|
|
|
|
|
#include "zori.h"
|
|
|
+#include "zori_registry.h"
|
|
|
+#include "zori_style.h"
|
|
|
+#include "zori_widget.h"
|
|
|
#include "zori_console.h"
|
|
|
#include "zori_screen.h"
|
|
|
#include "miao.h"
|
|
@@ -13,65 +16,6 @@
|
|
|
* interface and the menus.
|
|
|
*/
|
|
|
|
|
|
-/* registry functionality */
|
|
|
-
|
|
|
-/** Compare registry entries. */
|
|
|
-int zori_registry_entry_compare(const void * v1, const void * v2) {
|
|
|
- const struct zori_registry_entry * entry1 = v1;
|
|
|
- const struct zori_registry_entry * entry2 = v2;
|
|
|
- return (entry2->id - entry1->id);
|
|
|
-}
|
|
|
-
|
|
|
-/** Initialize the registry. */
|
|
|
-zori_id zori_registry_init(struct zori_registry * registry) {
|
|
|
- miao_init(registry);
|
|
|
- return ZORI_ID_OK;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/** Add an entry to the registry. */
|
|
|
-zori_id
|
|
|
-zori_registry_add(struct zori_registry * registry, zori_id id,
|
|
|
-struct zori_widget * widget) {
|
|
|
- struct zori_registry_entry entry = { id, widget };
|
|
|
- if (miao_push(registry, entry)) {
|
|
|
- miao_qsort(registry, zori_registry_entry_compare);
|
|
|
- return ZORI_ID_OK;
|
|
|
- }
|
|
|
- return ZORI_ID_ENOMEM;
|
|
|
-}
|
|
|
-
|
|
|
-/** Look up an entry in the registry. */
|
|
|
-struct zori_registry_entry *
|
|
|
-zori_registry_lookup_entry(struct zori_registry * registry, zori_id id) {
|
|
|
- struct zori_registry_entry key = { id, NULL };
|
|
|
- return miao_bsearch(registry, zori_registry_entry_compare, &key);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/** Look up a widget in the registry. */
|
|
|
-struct zori_widget *
|
|
|
-zori_registry_lookup(struct zori_registry * registry, zori_id id) {
|
|
|
- struct zori_widget * result = NULL;
|
|
|
- struct zori_registry_entry * entry = NULL;
|
|
|
-
|
|
|
- entry = zori_registry_lookup_entry(registry, id);
|
|
|
- if (entry) {
|
|
|
- result = entry->widget;
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-/** Remove an entry from the registry. */
|
|
|
-zori_id
|
|
|
-zori_registry_remove(struct zori_registry * registry, zori_id id) {
|
|
|
- struct zori_registry_entry * entry = NULL;
|
|
|
- entry = zori_registry_lookup_entry(registry, id);
|
|
|
- if (entry) {
|
|
|
- miao_delete_entry(registry, entry);
|
|
|
- }
|
|
|
- return ZORI_ID_OK;
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
|
@@ -129,143 +73,16 @@ int zori_handlers_handle(struct zori_handlers * me, union zori_event * event) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-/** Returns whether or not a widget will even handle an event in the first place.
|
|
|
- * For example, a hidden widget won't draw, and a disabled widget won't
|
|
|
- * accept any system events, and a NULL event doesn't accept events at all.. */
|
|
|
-int zori_widget_accepts_event(struct zori_widget * widget, union zori_event * event) {
|
|
|
- if (!widget) return 0;
|
|
|
- switch(event->any.type) {
|
|
|
- case ZORI_EVENT_DRAW:
|
|
|
- return zori_widget_visible(widget);
|
|
|
- default:
|
|
|
- return zori_widget_active(widget);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/** Raises an event on the widget itself only. */
|
|
|
-int zori_widget_self_raise_event(struct zori_widget * widget,
|
|
|
-union zori_event * event) {
|
|
|
- enum zori_handle_result result;
|
|
|
- if (zori_widget_accepts_event(widget, event)) {
|
|
|
- event->any.widget = widget;
|
|
|
- return zori_handlers_handle(&widget->handlers, event);
|
|
|
- }
|
|
|
- /* If the event is not accepted, it is passed on to the child widgets. */
|
|
|
- return ZORI_HANDLE_PASS;
|
|
|
-}
|
|
|
-
|
|
|
-/* Raises an event on the widget, and if necessary, propagates it on to it's
|
|
|
- * children automatically and recursively. */
|
|
|
-int
|
|
|
-zori_widget_raise_event(struct zori_widget * widget, union zori_event * event) {
|
|
|
- enum zori_handle_result result =
|
|
|
- zori_widget_self_raise_event(widget, event);
|
|
|
-
|
|
|
- if (zori_propagate_event_p(result)) {
|
|
|
- enum zori_handle_result sub;
|
|
|
- size_t index;
|
|
|
- for (index = 0; index < miao_size(&widget->children); index++) {
|
|
|
- struct zori_widget * child = miao_unsafe_get(&widget->children, index);
|
|
|
- event->any.widget = child;
|
|
|
- sub = zori_widget_raise_event(child, event);
|
|
|
- if (sub == ZORI_HANDLE_DONE) {
|
|
|
- result = ZORI_HANDLE_DONE;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-int zori_widget_raise_system_event
|
|
|
-(struct zori_widget * widget, zori_system_event * sysev) {
|
|
|
- union zori_event event;
|
|
|
- event.sys.any.type = sysev->type;
|
|
|
- event.sys.any.widget = widget;
|
|
|
- event.sys.ev = sysev;
|
|
|
- return zori_widget_raise_event(widget, &event);
|
|
|
-}
|
|
|
-
|
|
|
-int zori_widget_raise_draw_event(struct zori_widget * widget) {
|
|
|
- union zori_event event;
|
|
|
- event.draw.any.type = ZORI_EVENT_DRAW;
|
|
|
- event.draw.any.widget = widget;
|
|
|
- return zori_widget_raise_event(widget, &event);
|
|
|
-}
|
|
|
-
|
|
|
-int zori_widget_raise_overdraw_event(struct zori_widget * widget) {
|
|
|
- union zori_event event;
|
|
|
- event.draw.any.type = ZORI_EVENT_OVERDRAW;
|
|
|
- event.draw.any.widget = widget;
|
|
|
- return zori_widget_raise_event(widget, &event);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-int zori_widget_raise_done_event(struct zori_widget * widget) {
|
|
|
- union zori_event event;
|
|
|
- event.done.any.type = ZORI_EVENT_DONE;
|
|
|
- event.done.any.widget = widget;
|
|
|
- return zori_widget_raise_event(widget, &event);
|
|
|
-}
|
|
|
-
|
|
|
-int zori_widget_raise_free_event(struct zori_widget * widget) {
|
|
|
- union zori_event event;
|
|
|
- event.free.any.type = ZORI_EVENT_FREE;
|
|
|
- event.free.any.widget = widget;
|
|
|
- return zori_widget_raise_event(widget, &event);
|
|
|
-}
|
|
|
-
|
|
|
-int zori_widget_raise_update_event
|
|
|
-(struct zori_widget * widget, double dt) {
|
|
|
- union zori_event event;
|
|
|
- event.update.any.type = ZORI_EVENT_DONE;
|
|
|
- event.update.any.widget = widget;
|
|
|
- event.update.dt = dt;
|
|
|
- return zori_widget_raise_event(widget, &event);
|
|
|
-}
|
|
|
-
|
|
|
-int zori_widget_raise_action_event
|
|
|
-(struct zori_widget * widget) {
|
|
|
- union zori_event event;
|
|
|
- event.action.any.type = ZORI_EVENT_ACTION;
|
|
|
- event.action.any.widget = widget;
|
|
|
- return zori_widget_raise_event(widget, &event);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-int zori_widget_raise_close_event
|
|
|
-(struct zori_widget * widget, struct zori_widget * from) {
|
|
|
- union zori_event event;
|
|
|
- event.close.any.type = ZORI_EVENT_CLOSE;
|
|
|
- event.close.any.widget = widget;
|
|
|
- event.close.from = from;
|
|
|
- return zori_widget_raise_event(widget, &event);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
static struct zori_root * the_zori_root = NULL;
|
|
|
|
|
|
-static struct zori_style * the_default_style = NULL;
|
|
|
-
|
|
|
-static struct zori_registry * the_zori_registry = NULL;
|
|
|
-
|
|
|
struct zori_root * zori_get_root(void) {
|
|
|
return the_zori_root;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-int zori_widget_compare(const void * v1, const void * v2) {
|
|
|
- const struct zori_widget * w1 = v1, * w2 = v2;
|
|
|
- return (w2->id - w1->id);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
struct zori_widget * zori_get_widget(zori_id id) {
|
|
|
- if (!the_zori_registry) return NULL;
|
|
|
- return zori_registry_lookup(the_zori_registry, id);
|
|
|
+ struct zori_registry * registry = zori_get_registry();
|
|
|
+ if (!registry) return NULL;
|
|
|
+ return zori_registry_lookup(registry, id);
|
|
|
}
|
|
|
|
|
|
zori_id zori_get_unused_id(void) {
|
|
@@ -279,108 +96,41 @@ zori_id zori_get_unused_id(void) {
|
|
|
return id;
|
|
|
}
|
|
|
|
|
|
-struct zori_handler * zori_widget_add_handler
|
|
|
-(struct zori_widget * widget, zori_event_type type, zori_handler_func * handler, void * data) {
|
|
|
- if ((!widget) || (!handler)) return NULL;
|
|
|
-
|
|
|
- return zori_handlers_add(&widget->handlers, type, handler, data);
|
|
|
-}
|
|
|
-
|
|
|
-struct zori_handler * zori_widget_add_handlers
|
|
|
-(struct zori_widget * widget, struct zori_handler * handlers, size_t amount) {
|
|
|
- size_t i;
|
|
|
- for (i = 0; i < amount; i++) {
|
|
|
- struct zori_handler * handler = handlers + i;
|
|
|
- if (!zori_widget_add_handler(widget, handler->type, handler->handler, handler->data)) return NULL;
|
|
|
- }
|
|
|
- return handlers + amount - 1;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-zori_id zori_start(struct zori_style * default_style) {
|
|
|
+zori_id zori_initialize_root(void) {
|
|
|
if (the_zori_root) return ZORI_ID_OK;
|
|
|
the_zori_root = calloc(1, sizeof(*the_zori_root));
|
|
|
if (!the_zori_root) return ZORI_ID_ENOMEM;
|
|
|
- the_default_style = calloc(1, sizeof(*the_default_style));
|
|
|
- if (!the_default_style) return ZORI_ID_ENOMEM;
|
|
|
- the_zori_registry = calloc(1, sizeof(*the_zori_registry));
|
|
|
- if (!the_zori_registry) return ZORI_ID_ENOMEM;
|
|
|
-
|
|
|
-
|
|
|
- the_default_style->text.font = al_create_builtin_font();
|
|
|
- the_default_style->text.color = al_color_name("white");
|
|
|
- the_default_style->text.font_flags= ALLEGRO_ALIGN_LEFT;
|
|
|
- the_default_style->border.color = al_color_name("white");
|
|
|
- the_default_style->back.color = al_color_name("green");
|
|
|
- the_default_style->fore.color = al_color_name("white");
|
|
|
- the_default_style->mark.color = al_color_name("lightgreen");
|
|
|
- the_default_style->hover.color = al_color_name("yellowgreen");
|
|
|
+ return ZORI_ID_OK;
|
|
|
+}
|
|
|
|
|
|
+zori_id zori_start(struct zori_style * default_style) {
|
|
|
+ zori_id res;
|
|
|
+ struct zori_root * root = NULL;
|
|
|
+ root = zori_get_root();
|
|
|
+
|
|
|
+ if (root) return ZORI_ID_OK;
|
|
|
+
|
|
|
+ res = zori_initialize_default_style();
|
|
|
+ if (!ZORI_ID_OK_P(res)) return res;
|
|
|
+ res = zori_initialize_registry();
|
|
|
+ if (!ZORI_ID_OK_P(res)) return res;
|
|
|
+
|
|
|
+ res = zori_initialize_root();
|
|
|
+ if (!ZORI_ID_OK_P(res)) return res;
|
|
|
|
|
|
+ root = zori_get_root();
|
|
|
+
|
|
|
if (default_style) {
|
|
|
- the_zori_root->widget.style = *default_style;
|
|
|
+ root->widget.style = *default_style;
|
|
|
} else {
|
|
|
- the_zori_root->widget.style = *the_default_style;
|
|
|
+ root->widget.style = *zori_get_default_style();
|
|
|
}
|
|
|
|
|
|
- the_zori_root->widget.id = 0;
|
|
|
- zori_registry_add(the_zori_registry, the_zori_root->widget.id, &the_zori_root->widget);
|
|
|
+ root->widget.id = 0;
|
|
|
+ zori_registry_add(zori_get_registry(), the_zori_root->widget.id, &the_zori_root->widget);
|
|
|
return the_zori_root->widget.id;
|
|
|
}
|
|
|
|
|
|
-void zori_widget_free(struct zori_widget * widget);
|
|
|
-
|
|
|
-struct zori_widget * zori_widget_done(struct zori_widget * widget) {
|
|
|
- size_t index;
|
|
|
- struct zori_widget * aid, * next;
|
|
|
- if (!widget) return widget;
|
|
|
-
|
|
|
- for (index = 0; index < miao_size(&widget->children); index ++) {
|
|
|
- struct zori_widget * child = miao_unsafe_get(&widget->children, index);
|
|
|
- zori_widget_free(child);
|
|
|
- }
|
|
|
-
|
|
|
- miao_done(&widget->handlers);
|
|
|
- miao_done(&widget->children);
|
|
|
-
|
|
|
- return widget;
|
|
|
-}
|
|
|
-
|
|
|
-void zori_widget_free(struct zori_widget * widget) {
|
|
|
- if (widget) {
|
|
|
- zori_registry_remove(the_zori_registry, widget->id);
|
|
|
- }
|
|
|
- zori_widget_done(widget);
|
|
|
- free(widget);
|
|
|
-}
|
|
|
-
|
|
|
-struct zori_widget *
|
|
|
-zori_widget_add_child(struct zori_widget * parent, struct zori_widget * child) {
|
|
|
- if (parent) {
|
|
|
- miao_push((&parent->children), child);
|
|
|
- child->parent = parent;
|
|
|
- }
|
|
|
- return child;
|
|
|
-}
|
|
|
-
|
|
|
-zori_id
|
|
|
-zori_widget_margins_(struct zori_widget * widget, int left, int top, int right, int bottom) {
|
|
|
- if (!widget) return ZORI_ID_EINVAL;
|
|
|
- widget->outer = widget->box;
|
|
|
- widget->outer.at.x -= left;
|
|
|
- widget->outer.at.y -= top;
|
|
|
- widget->outer.size.x += (left + right);
|
|
|
- widget->outer.size.y += (top + bottom);
|
|
|
- return widget->id;
|
|
|
-}
|
|
|
-
|
|
|
-zori_id
|
|
|
-zori_widget_margin_(struct zori_widget * widget, int size) {
|
|
|
- return zori_widget_margins_(widget, size, size, size, size);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
zori_id zori_set_margins(zori_id id, int left, int top, int right, int bottom) {
|
|
|
struct zori_widget * widget = zori_get_widget(id);
|
|
|
return zori_widget_margins_(widget, left, top, right, bottom);
|
|
@@ -393,23 +143,6 @@ zori_id zori_set_margin(zori_id id, int size) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-zori_id
|
|
|
-zori_widget_paddings_(struct zori_widget * widget, int left, int top, int right, int bottom) {
|
|
|
- if (!widget) return ZORI_ID_EINVAL;
|
|
|
- widget->inner = widget->box;
|
|
|
- widget->inner.at.x += left;
|
|
|
- widget->inner.at.y += top;
|
|
|
- widget->inner.size.x -= (left + right);
|
|
|
- widget->inner.size.y -= (top + bottom);
|
|
|
- return widget->id;
|
|
|
-}
|
|
|
-
|
|
|
-zori_id
|
|
|
-zori_widget_padding_(struct zori_widget * widget, int size) {
|
|
|
- return zori_widget_paddings_(widget, size, size, size, size);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
zori_id zori_set_paddings(zori_id id, int left, int top, int right, int bottom) {
|
|
|
struct zori_widget * widget = zori_get_widget(id);
|
|
|
return zori_widget_paddings_(widget, left, top, right, bottom);
|
|
@@ -421,14 +154,6 @@ zori_id zori_set_padding(zori_id id, int size) {
|
|
|
return zori_widget_padding_(widget, size);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-zori_font * zori_widget_text_font(struct zori_widget * widget) {
|
|
|
- if ((!widget)) {
|
|
|
- return the_default_style->text.font;
|
|
|
- }
|
|
|
- return widget->style.text.font;
|
|
|
-}
|
|
|
-
|
|
|
zori_font * zori_text_font(zori_id id) {
|
|
|
struct zori_widget * widget = zori_get_widget(id);
|
|
|
return zori_widget_text_font(widget);
|
|
@@ -436,54 +161,14 @@ zori_font * zori_text_font(zori_id id) {
|
|
|
|
|
|
|
|
|
|
|
|
-struct zori_widget * zori_widget_init
|
|
|
- ( struct zori_widget * widget,
|
|
|
- zori_widget_type type,
|
|
|
- zori_id id,
|
|
|
- struct zori_widget * parent,
|
|
|
- zori_rebox * box, struct zori_style * style) {
|
|
|
- if (!widget) return NULL;
|
|
|
-
|
|
|
- miao_init(&widget->children);
|
|
|
- miao_init(&widget->handlers);
|
|
|
- widget->z = 0;
|
|
|
- widget->flags = 0;
|
|
|
- widget->type = type;
|
|
|
- widget->id = ( (id < 0) ? zori_get_unused_id() : id);
|
|
|
-
|
|
|
- if (style) {
|
|
|
- widget->style = *style;
|
|
|
- if (!widget->style.text.font) {
|
|
|
- widget->style.text.font = the_default_style->text.font;
|
|
|
- }
|
|
|
- } else {
|
|
|
- widget->style = *the_default_style;
|
|
|
- }
|
|
|
- if (box) {
|
|
|
- widget->box = *box;
|
|
|
- } else if (parent) {
|
|
|
- widget->box = parent->box;
|
|
|
- } else {
|
|
|
- widget->box = rebox_make(0, 0, ZORI_WIDGET_DEFAULT_W, ZORI_WIDGET_DEFAULT_H);
|
|
|
- }
|
|
|
-
|
|
|
- zori_widget_margin_(widget, ZORI_MARGIN_DEFAULT);
|
|
|
- zori_widget_padding_(widget, ZORI_PADDING_DEFAULT);
|
|
|
-
|
|
|
- zori_widget_add_child(parent, widget);
|
|
|
- zori_registry_add(the_zori_registry, widget->id, widget);
|
|
|
- return widget;
|
|
|
-}
|
|
|
-
|
|
|
-struct zori_widget *
|
|
|
-zori_widget_initall(struct zori_widget * widget, zori_widget_type type, int id,
|
|
|
-struct zori_widget * parent, zori_rebox * box, struct zori_style * style,
|
|
|
-struct zori_handler * handlers, size_t amount) {
|
|
|
- if (zori_widget_init(widget, type, id, parent, box, style)) {
|
|
|
- zori_widget_add_handlers(widget, handlers, amount);
|
|
|
+/** Destroy the Zori root widget */
|
|
|
+void zori_destroy_root(void) {
|
|
|
+ if (the_zori_root) {
|
|
|
+ zori_widget_free(&the_zori_root->widget);
|
|
|
}
|
|
|
- return widget;
|
|
|
-}
|
|
|
+ /* free(the_zori_root); is not needed, as it is cleaned up a sa widget */
|
|
|
+ the_zori_root = NULL;
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
@@ -491,23 +176,14 @@ struct zori_handler * handlers, size_t amount) {
|
|
|
* negative on error.
|
|
|
*/
|
|
|
zori_id zori_shutdown() {
|
|
|
- assert((void *)(&the_zori_root->widget) == (void *)the_zori_root);
|
|
|
- zori_widget_free(&the_zori_root->widget);
|
|
|
- the_zori_root = NULL;
|
|
|
- free(the_default_style);
|
|
|
- the_default_style = NULL;
|
|
|
- /* clean up registry last so zori_widget fre can unregister it's widgets.*/
|
|
|
- miao_done(the_zori_registry);
|
|
|
- free(the_zori_registry);
|
|
|
- the_zori_registry = NULL;
|
|
|
-
|
|
|
-
|
|
|
+ zori_destroy_root();
|
|
|
+ zori_destroy_default_style();
|
|
|
+ zori_destroy_registry();
|
|
|
return ZORI_ID_OK;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
/* Creates a new screen widget. Normally this should be the first widget
|
|
|
* you create after zori_start. */
|
|
|
zori_id zori_new_screen(zori_id id, zori_display * display);
|
|
@@ -550,12 +226,6 @@ zori_id zori_new_button_widget(zori_id parent, zori_rebox box, char * text);
|
|
|
zori_id zori_new_conversation_widget(zori_id parent, zori_rebox box, char * text);
|
|
|
|
|
|
|
|
|
-/* Lets the widget handle an event and bubbles it on to it's children
|
|
|
- * recursively depending on the need to do that. */
|
|
|
-void zori_widget_handle_event(struct zori_widget * widget, union zori_event * event) {
|
|
|
- zori_widget_raise_event(widget, event);
|
|
|
-}
|
|
|
-
|
|
|
/* Draws the whole UI and all visible parts. */
|
|
|
void zori_draw_all(void) {
|
|
|
zori_widget_raise_draw_event(&the_zori_root->widget);
|
|
@@ -566,7 +236,10 @@ void zori_draw_all(void) {
|
|
|
int zori_handle_system_event(zori_system_event * sysev) {
|
|
|
/* All events are passed on to the console regardless if it is active.
|
|
|
* Otherwise, the events go into the system. */
|
|
|
- if (the_zori_root->console ) {
|
|
|
+ if (!the_zori_root) {
|
|
|
+ return ZORI_ID_EINVAL;
|
|
|
+ }
|
|
|
+ if (the_zori_root && the_zori_root->console) {
|
|
|
if (zori_console_active(the_zori_root->console)) {
|
|
|
int res = zori_widget_raise_system_event(&the_zori_root->console->widget, sysev);
|
|
|
if (!zori_propagate_event_p(res)) return res;
|
|
@@ -594,54 +267,4 @@ int zori_result(zori_id id) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-/* Returns the first parent or super-parent of this widget for which
|
|
|
- * predicate() returns true.
|
|
|
- */
|
|
|
-struct zori_widget *
|
|
|
-zori_widget_find_parent(struct zori_widget * widget,
|
|
|
- bool (*predicate)(struct zori_widget * parent, void * extra),
|
|
|
- void * extra
|
|
|
- ) {
|
|
|
- struct zori_widget * parent;
|
|
|
-
|
|
|
- if (!widget) return NULL;
|
|
|
- parent = widget->parent;
|
|
|
- while (parent) {
|
|
|
- if (predicate(parent, extra)) return parent;
|
|
|
- if (parent == parent->parent) {
|
|
|
- LOG_ERROR("GUI setup not correct. Parent/child loop in widget %p.", widget);
|
|
|
- return NULL;
|
|
|
- }
|
|
|
- parent = parent->parent;
|
|
|
- }
|
|
|
- return NULL;
|
|
|
-}
|
|
|
-
|
|
|
-bool zori_widget_is_type_predicate(struct zori_widget * widget, void * extra) {
|
|
|
- zori_widget_type * type_ptr = extra;
|
|
|
- if(!type_ptr) return false;
|
|
|
- return (*type_ptr) == widget->type;
|
|
|
-}
|
|
|
-
|
|
|
-struct zori_widget *
|
|
|
- zori_widget_get_parent_of_type(struct zori_widget * widget,
|
|
|
- zori_widget_type type) {
|
|
|
- return zori_widget_find_parent(widget, zori_widget_is_type_predicate, &type);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-struct zori_screen * zori_widget_get_screen(struct zori_widget * widget) {
|
|
|
- struct zori_widget * screen_widget = zori_widget_get_parent_of_type(widget, ZORI_WIDGET_TYPE_SCREEN);
|
|
|
- return zori_widget_to_screen(screen_widget);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-int zori_mark_widget(struct zori_widget * widget) {
|
|
|
- struct zori_screen * screen = zori_widget_get_screen(widget);
|
|
|
- if (screen) {
|
|
|
- screen->cursors.keyjoy.p = widget->box.at;
|
|
|
- }
|
|
|
- return ZORI_HANDLE_DONE;
|
|
|
-}
|
|
|
-
|
|
|
|