From 6ffbb575e694820af480f70e51a87a4d505f09f4 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 28 Sep 2025 10:06:00 +0000 Subject: [PATCH] give widgets a name git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@22 b9cfdab3-6d41-4d17-bbe4-086880011989 --- example.c | 2 +- include/Milsko/Core.h | 2 +- include/Milsko/TypeDefs.h | 2 ++ src/core.c | 7 ++++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/example.c b/example.c index 033fab0..93c747e 100644 --- a/example.c +++ b/example.c @@ -3,7 +3,7 @@ #include int main(){ - MilskoWidget window = MilskoCreateWidget(MilskoWindowClass, NULL, 0, 0, 640, 480); + MilskoWidget window = MilskoCreateWidget(MilskoWindowClass, "main", NULL, 0, 0, 640, 480); MilskoApply(window, MilskoNwidth, 480 * 2, diff --git a/include/Milsko/Core.h b/include/Milsko/Core.h index 6001a97..3d009ed 100644 --- a/include/Milsko/Core.h +++ b/include/Milsko/Core.h @@ -5,7 +5,7 @@ #include #include -MILSKODECL MilskoWidget MilskoCreateWidget(MilskoClass class, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height); +MILSKODECL MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height); MILSKODECL void MilskoDestroyWidget(MilskoWidget handle); MILSKODECL void MilskoLoop(MilskoWidget handle); diff --git a/include/Milsko/TypeDefs.h b/include/Milsko/TypeDefs.h index 965b8ad..afb0ecb 100644 --- a/include/Milsko/TypeDefs.h +++ b/include/Milsko/TypeDefs.h @@ -34,6 +34,8 @@ typedef struct _MilskoClass* MilskoClass; typedef struct _Milsko* MilskoWidget; typedef struct _Milsko { + char* name; + MilskoLL lowlevel; MilskoWidget parent; MilskoWidget* children; diff --git a/src/core.c b/src/core.c index a8a35ca..b2d2635 100644 --- a/src/core.c +++ b/src/core.c @@ -11,9 +11,12 @@ static void llhandler(MilskoLL handle) { Dispatch(h, draw); } -MilskoWidget MilskoCreateWidget(MilskoClass class, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height) { +MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height) { MilskoWidget h = malloc(sizeof(*h)); + h->name = malloc(strlen(name) + 1); + strcpy(h->name, name); + h->parent = parent; h->children = NULL; h->lowlevel = MilskoLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height); @@ -40,6 +43,8 @@ void MilskoDestroyWidget(MilskoWidget handle) { Dispatch(handle, destroy); + free(handle->name); + if(handle->children != NULL) { for(i = 0; i < arrlen(handle->children); i++) { if(handle->children[i] == handle) {