optimize box later
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
This commit is contained in:
parent
f6abf02486
commit
7be0a72fca
2 changed files with 61 additions and 21 deletions
|
|
@ -27,6 +27,7 @@ typedef struct _MwListBoxEntry MwListBoxEntry;
|
||||||
typedef struct _MwTreeViewEntry MwTreeViewEntry;
|
typedef struct _MwTreeViewEntry MwTreeViewEntry;
|
||||||
typedef struct _MwDirectoryEntry MwDirectoryEntry;
|
typedef struct _MwDirectoryEntry MwDirectoryEntry;
|
||||||
typedef struct _MwListBoxPacket MwListBoxPacket;
|
typedef struct _MwListBoxPacket MwListBoxPacket;
|
||||||
|
typedef struct _MwBox* MwBox;
|
||||||
#ifdef _MILSKO
|
#ifdef _MILSKO
|
||||||
typedef struct _MwWidget* MwWidget;
|
typedef struct _MwWidget* MwWidget;
|
||||||
#else
|
#else
|
||||||
|
|
@ -200,6 +201,10 @@ struct _MwListBoxPacket {
|
||||||
char*** names;
|
char*** names;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _MwBox {
|
||||||
|
int layout;
|
||||||
|
};
|
||||||
|
|
||||||
struct _MwClass {
|
struct _MwClass {
|
||||||
MwHandlerWithStatus create;
|
MwHandlerWithStatus create;
|
||||||
MwHandler destroy;
|
MwHandler destroy;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,11 @@
|
||||||
#include "../../external/stb_ds.h"
|
#include "../../external/stb_ds.h"
|
||||||
|
|
||||||
static int create(MwWidget handle) {
|
static int create(MwWidget handle) {
|
||||||
|
MwBox b = malloc(sizeof(*b));
|
||||||
|
memset(b, 0, sizeof(*b));
|
||||||
|
|
||||||
|
handle->internal = b;
|
||||||
|
|
||||||
MwSetDefault(handle);
|
MwSetDefault(handle);
|
||||||
|
|
||||||
MwSetInteger(handle, MwNorientation, MwHORIZONTAL);
|
MwSetInteger(handle, MwNorientation, MwHORIZONTAL);
|
||||||
|
|
@ -11,25 +16,14 @@ static int create(MwWidget handle) {
|
||||||
MwSetInteger(handle, MwNhasBorder, 0);
|
MwSetInteger(handle, MwNhasBorder, 0);
|
||||||
MwSetInteger(handle, MwNinverted, 1);
|
MwSetInteger(handle, MwNinverted, 1);
|
||||||
|
|
||||||
|
b->layout = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw(MwWidget handle) {
|
static void destroy(MwWidget handle){
|
||||||
MwRect r;
|
MwBox b = handle->internal;
|
||||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
free(b);
|
||||||
|
|
||||||
r.x = 0;
|
|
||||||
r.y = 0;
|
|
||||||
r.width = MwGetInteger(handle, MwNwidth);
|
|
||||||
r.height = MwGetInteger(handle, MwNheight);
|
|
||||||
|
|
||||||
if(MwGetInteger(handle, MwNhasBorder)) {
|
|
||||||
MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
MwDrawRect(handle, &r, base);
|
|
||||||
|
|
||||||
MwLLFreeColor(base);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define Margin ((i != (arrlen(handle->children) - 1)) ? MwGetInteger(handle, MwNmargin) : 0)
|
#define Margin ((i != (arrlen(handle->children) - 1)) ? MwGetInteger(handle, MwNmargin) : 0)
|
||||||
|
|
@ -81,27 +75,68 @@ static void layout(MwWidget handle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void draw(MwWidget handle) {
|
||||||
|
MwRect r;
|
||||||
|
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||||
|
MwBox b = handle->internal;
|
||||||
|
|
||||||
|
r.x = 0;
|
||||||
|
r.y = 0;
|
||||||
|
r.width = MwGetInteger(handle, MwNwidth);
|
||||||
|
r.height = MwGetInteger(handle, MwNheight);
|
||||||
|
|
||||||
|
if(MwGetInteger(handle, MwNhasBorder)) {
|
||||||
|
MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
MwDrawRect(handle, &r, base);
|
||||||
|
|
||||||
|
MwLLFreeColor(base);
|
||||||
|
|
||||||
|
if(b->layout){
|
||||||
|
layout(handle);
|
||||||
|
|
||||||
|
b->layout = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void prop_change(MwWidget handle, const char* key) {
|
static void prop_change(MwWidget handle, const char* key) {
|
||||||
if(strcmp(key, MwNorientation) == 0) layout(handle);
|
if(strcmp(key, MwNorientation) == 0){
|
||||||
|
MwBox b = handle->internal;
|
||||||
|
b->layout = 1;
|
||||||
|
|
||||||
|
MwForceRender(handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void children_prop_change(MwWidget handle, MwWidget child, const char* key) {
|
static void children_prop_change(MwWidget handle, MwWidget child, const char* key) {
|
||||||
(void)child;
|
(void)child;
|
||||||
|
|
||||||
if(strcmp(key, MwNratio) == 0 || strcmp(key, MwNfixedSize) == 0) layout(handle);
|
if(strcmp(key, MwNratio) == 0 || strcmp(key, MwNfixedSize) == 0){
|
||||||
|
MwBox b = handle->internal;
|
||||||
|
b->layout = 1;
|
||||||
|
|
||||||
|
MwForceRender(handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resize(MwWidget handle) {
|
static void resize(MwWidget handle) {
|
||||||
layout(handle);
|
MwBox b = handle->internal;
|
||||||
|
b->layout = 1;
|
||||||
|
|
||||||
|
MwForceRender(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void children_update(MwWidget handle) {
|
static void children_update(MwWidget handle) {
|
||||||
layout(handle);
|
MwBox b = handle->internal;
|
||||||
|
b->layout = 1;
|
||||||
|
|
||||||
|
MwForceRender(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
MwClassRec MwBoxClassRec = {
|
MwClassRec MwBoxClassRec = {
|
||||||
create, /* create */
|
create, /* create */
|
||||||
NULL, /* destroy */
|
destroy, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
NULL, /* click */
|
NULL, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue