wip
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-04-30 14:28:56 +09:00
commit 6b94ac5db9
8 changed files with 142 additions and 22 deletions

View file

@ -1,19 +1,82 @@
#include <Mw/Milsko.h>
#define TitleHeight 20
#define ButtonSize 18
static void resize(MwWidget handle){
MwSubWindow sw = handle->internal;
int x, y, w, h;
int ww = MwGetInteger(handle, MwNwidth);
int wh = MwGetInteger(handle, MwNheight);
int bw = MwDefaultBorderWidth(handle);
int p;
x = bw * 2;
y = bw * 2 + TitleHeight;
w = ww - bw * 4;
h = wh - bw * 4 - TitleHeight;
if(sw->frame == NULL){
sw->frame = MwCreateWidget(MwFrameClass, "frame", handle, x, y, w, h);
}else{
MwVaApply(sw->frame,
MwNx, x,
MwNy, y,
MwNwidth, w,
MwNheight, h,
NULL);
}
p = (TitleHeight - ButtonSize) / 2;
x = ww - bw - p;
y = bw + p;
w = ButtonSize;
h = ButtonSize;
#define BUTTON(name) \
x -= ButtonSize; \
if(sw->name == NULL){ \
sw->name = MwCreateWidget(MwButtonClass, #name, handle, x, y, w, h); \
}else{ \
MwVaApply(sw->name, \
MwNx, x, \
MwNy, y, \
MwNwidth, w, \
MwNheight, h, \
NULL); \
} \
x -= p;
BUTTON(close);
BUTTON(maximize);
BUTTON(minimize);
MwSetText(sw->frame, MwNbackground, "#f00");
}
static int wcreate(MwWidget handle) {
MwSetDefault(handle);
MwSubWindow sw = malloc(sizeof(*sw));
memset(sw, 0, sizeof(*sw));
MwSetText(handle, MwNtitleBackground, "#008");
handle->internal = sw;
resize(handle);
MwSetDefault(handle);
return 0;
}
static void destroy(MwWidget handle) {
MwSubWindow sw = handle->internal;
free(handle->internal);
}
static void draw(MwWidget handle) {
MwLLColor c = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwLLColor c2 = MwParseColor(handle, MwGetText(handle, MwNtitleBackground));
MwLLColor tb = MwParseColor(handle, MwGetText(handle, MwNtitleBackground));
MwLLColor tf = MwParseColor(handle, MwGetText(handle, MwNtitleForeground));
MwRect r, r2;
const char* title = MwGetText(handle, MwNtitle);
r.x = 0;
r.y = 0;
@ -25,13 +88,23 @@ static void draw(MwWidget handle) {
r2 = r;
r2.height = TitleHeight;
MwDrawRect(handle, &r2, c2);
MwDrawRect(handle, &r2, tb);
if(title != NULL){
MwPoint p;
p.x = r2.x + (TitleHeight - ButtonSize);
p.y = r2.y + TitleHeight / 2;
handle->bgcolor = tb;
MwDrawText(handle, NULL, &p, title, MwALIGNMENT_BEGINNING, tf);
handle->bgcolor = NULL;
}
r.y += TitleHeight;
r.height -= TitleHeight;
MwDrawFrame(handle, &r, c, 1);
MwLLFreeColor(c2);
MwLLFreeColor(tf);
MwLLFreeColor(tb);
MwLLFreeColor(c);
}
@ -45,7 +118,7 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
MwClassRec MwSubWindowClassRec = {
wcreate, /* create */
NULL, /* destroy */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */