git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@17 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-09-28 09:14:57 +00:00
parent 5170d6c0db
commit edfa67e964
3 changed files with 39 additions and 4 deletions

View File

@@ -9,6 +9,16 @@ typedef struct _MilskoPoint {
int y;
} MilskoPoint;
typedef struct _MilskoTextKeyValue {
char* key;
char* value;
} MilskoTextKeyValue;
typedef struct _MilskoIntegerKeyValue {
char* key;
int value;
} MilskoIntegerKeyValue;
typedef struct _MilskoClass* MilskoClass;
#ifdef _MILSKO
@@ -21,6 +31,9 @@ typedef struct _Milsko {
HMILSKO parent;
HMILSKO* children;
MilskoClass class;
MilskoTextKeyValue* text;
MilskoIntegerKeyValue* integer;
}* HMILSKO;
#else
typedef void* HMILSKO;

View File

@@ -13,6 +13,12 @@ HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsi
if(parent != NULL) arrput(parent->children, h);
sh_new_strdup(h->text);
sh_new_strdup(h->integer);
shdefault(h->text, NULL);
shdefault(h->integer, -1);
return h;
}
@@ -38,14 +44,23 @@ void MilskoDestroyWidget(HMILSKO handle) {
}
}
MilskoLLDestroy(handle->lowlevel);
shfree(handle->integer);
for(i = 0; i < shlen(handle->text); i++) {
free(handle->text[i].value);
handle->text[i].value = NULL;
}
shfree(handle->text);
free(handle);
}
MILSKODECL void MilskoStep(HMILSKO handle) {
void MilskoStep(HMILSKO handle) {
MilskoLLNextEvent(handle->lowlevel);
}
MILSKODECL int MilskoPending(HMILSKO handle) {
int MilskoPending(HMILSKO handle) {
int i;
for(i = 0; i < arrlen(handle->children); i++) {
if(MilskoPending(handle->children[i])) return 1;
@@ -53,7 +68,7 @@ MILSKODECL int MilskoPending(HMILSKO handle) {
return MilskoLLPending(handle->lowlevel);
}
MILSKODECL void MilskoLoop(HMILSKO handle) {
void MilskoLoop(HMILSKO handle) {
while(1) {
MilskoStep(handle);
MilskoLLSleep(10);
@@ -74,12 +89,19 @@ void MilskoSetInteger(HMILSKO handle, const char* key, int n) {
if(strcmp(key, MilskoNheight) == 0) h = n;
if(xy) MilskoLLSetXY(handle->lowlevel, x, y);
if(wh) MilskoLLSetWH(handle->lowlevel, w, h);
} else {
shput(handle->integer, key, n);
}
}
void MilskoSetText(HMILSKO handle, const char* key, const char* value) {
if(strcmp(key, MilskoNtitle) == 0) {
MilskoLLSetTitle(handle->lowlevel, value);
} else {
char* v = malloc(strlen(value) + 1);
strcpy(v, value);
shput(handle->text, key, v);
}
}

View File

@@ -109,6 +109,6 @@ void MilskoLLSleep(int ms) {
usleep(ms * 1000);
}
MILSKODECL void MilskoLLSetTitle(HMILSKOLL handle, const char* title) {
void MilskoLLSetTitle(HMILSKOLL handle, const char* title) {
XSetStandardProperties(handle->display, handle->window, title, "Milsko Widget Toolkit", None, (char**)NULL, 0, NULL);
}