summaryrefslogtreecommitdiffstats
path: root/src/tk
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-06 01:55:22 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-06 01:55:22 (EDT)
commitff4f77ec223c5a0b1a015789d34177d8ddb4a4b2 (patch)
tree8917dd93a0270ea037cd83427d5a1e9af39930c7 /src/tk
parent592ee2f218f1886decc478c3353810c7c11b51d3 (diff)
downloadmazefight-ff4f77ec223c5a0b1a015789d34177d8ddb4a4b2.zip
mazefight-ff4f77ec223c5a0b1a015789d34177d8ddb4a4b2.tar.gz
mazefight-ff4f77ec223c5a0b1a015789d34177d8ddb4a4b2.tar.bz2
tk: Add container pointer to widget
Diffstat (limited to 'src/tk')
-rw-r--r--src/tk/box.c2
-rw-r--r--src/tk/grid.c5
-rw-r--r--src/tk/widget.h19
3 files changed, 18 insertions, 8 deletions
diff --git a/src/tk/box.c b/src/tk/box.c
index ced5b3c..10a4ec3 100644
--- a/src/tk/box.c
+++ b/src/tk/box.c
@@ -132,5 +132,7 @@ mftk_box_new(int container_w, int container_h, int own_w, int own_h,
b->bg_color = bg_color;
b->child = child;
+ child->container = w;
+
return w;
}
diff --git a/src/tk/grid.c b/src/tk/grid.c
index 62c5612..9d12b3c 100644
--- a/src/tk/grid.c
+++ b/src/tk/grid.c
@@ -229,6 +229,7 @@ mftk_grid_new_a(int rows, int cols, int row_spacing, int col_spacing,
{
struct mftk_widget *w;
struct mftk_grid *g;
+ int i;
mftk_widget_init(w, g, grid);
@@ -259,6 +260,10 @@ mftk_grid_new_a(int rows, int cols, int row_spacing, int col_spacing,
g->children = children;
g->alignments = alignments;
+ for (i = 0; i < rows * cols; ++i) {
+ children[i]->container = w;
+ }
+
return w;
}
diff --git a/src/tk/widget.h b/src/tk/widget.h
index 310dc56..64b8b58 100644
--- a/src/tk/widget.h
+++ b/src/tk/widget.h
@@ -24,14 +24,17 @@
#include <stdarg.h>
struct mftk_widget {
- int w;
- int h;
- int vis;
- int can_focus;
- void (*layout)(struct mftk_widget *);
- int (*event)(struct mftk_widget *, SDL_Event *, int, int);
- int (*render)(struct mftk_widget *, SDL_Renderer *, int, int);
- void (*destroy)(struct mftk_widget *);
+ int w;
+ int h;
+ struct mftk_widget *container;
+ int vis;
+ int can_focus;
+ void (*layout)(struct mftk_widget *);
+ int (*event)(struct mftk_widget *, SDL_Event *,
+ int, int);
+ int (*render)(struct mftk_widget *, SDL_Renderer *,
+ int, int);
+ void (*destroy)(struct mftk_widget *);
};
struct mftk_widget *