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

View File

@@ -3,6 +3,9 @@
#include "stb_ds.h"
#define Dispatch(x, y) \
if(x->class != NULL && x->class->y != NULL) x->class->y(x)
HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsigned int width, unsigned int height) {
HMILSKO h = malloc(sizeof(*h));
@@ -19,12 +22,16 @@ HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsi
shdefault(h->text, NULL);
shdefault(h->integer, -1);
Dispatch(h, create);
return h;
}
void MilskoDestroyWidget(HMILSKO handle) {
int i;
Dispatch(handle, destroy);
if(handle->children != NULL) {
for(i = 0; i < arrlen(handle->children); i++) {
if(handle->children[i] == handle) {
@@ -105,6 +112,27 @@ void MilskoSetText(HMILSKO handle, const char* key, const char* value) {
}
}
int MilskoGetInteger(HMILSKO handle, const char* key) {
if(strcmp(key, MilskoNx) == 0 || strcmp(key, MilskoNy) == 0 || strcmp(key, MilskoNwidth) == 0 || strcmp(key, MilskoNheight) == 0) {
int x, y;
unsigned int w, h;
MilskoLLGetXYWH(handle->lowlevel, &x, &y, &w, &h);
if(strcmp(key, MilskoNx) == 0) return x;
if(strcmp(key, MilskoNy) == 0) return y;
if(strcmp(key, MilskoNwidth) == 0) return w;
if(strcmp(key, MilskoNheight) == 0) return h;
return -1;
} else {
return shget(handle->integer, key);
}
}
const char* MilskoGetText(HMILSKO handle, const char* key) {
return shget(handle->text, key);
}
void MilskoApply(HMILSKO handle, ...) {
va_list va;
char* key;

View File

@@ -1,5 +1,11 @@
/* $Id$ */
#include <Milsko/Milsko.h>
MilskoClassRec MilskoWindowClassRec = {};
MilskoClass MilskoWindowClass = &MilskoWindowClassRec;
MilskoClassRec MilskoWindowClassRec = {
NULL, /* opaque */
NULL, /* create */
NULL, /* destroy */
NULL, /* draw */
NULL /* click */
};
MilskoClass MilskoWindowClass = &MilskoWindowClassRec;