Compare commits

..

6 Commits

Author SHA1 Message Date
NishiOwO
c80987ffe4 better 2025-12-25 04:18:12 +09:00
NishiOwO
d3a7b0a01d oops 2025-12-25 04:03:05 +09:00
NishiOwO
e77c4f3c38 add MwNleftPadding to SubMenu 2025-12-25 03:56:04 +09:00
NishiOwO
22b4737c33 better separator 2025-12-25 02:27:41 +09:00
NishiOwO
509351a0a0 fix submenu 2025-12-25 00:19:27 +09:00
NishiOwO
86effbdfd7 fix 2025-12-24 22:52:26 +09:00
4 changed files with 64 additions and 31 deletions

View File

@@ -195,7 +195,6 @@ target_compile_definitions(
_MILSKO
)
include(GNUInstallDirs)
install(
TARGETS Mw
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}

View File

@@ -29,6 +29,16 @@ MwInline void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point, int
MwVaWidgetExecute(handle, "mwSubMenuAppear", NULL, menu, point, diff_calc);
}
/*!
* @brief Calculates the size of submenu
* @param handle Handle
* @param menu Menu
* @param rect Size
*/
MwInline void MwSubMenuGetSize(MwWidget handle, MwMenu menu, MwRect* rect) {
MwVaWidgetExecute(handle, "mwSubMenuGetSize", NULL, menu, rect);
}
#ifdef __cplusplus
}
#endif

View File

@@ -640,6 +640,9 @@
</functions>
</widget>
<widget name="SubMenu">
<properties>
<property name="leftPadding" />
</properties>
<functions>
<function name="Appear">
<arguments>

View File

@@ -6,6 +6,7 @@ static int create(MwWidget handle) {
MwLLBeginStateChange(handle->lowlevel);
MwSetDefault(handle);
MwSetInteger(handle, MwNleftPadding, 0);
return 0;
}
@@ -53,12 +54,14 @@ static void draw(MwWidget handle) {
rc.x = MwDefaultBorderWidth(handle) * 2;
rc.y = p.y;
rc.width = r.width - (rc.x * 2);
rc.height = MwDefaultBorderWidth(handle) * 2;
rc.width = r.width - (rc.x * 2) - MwGetInteger(handle, MwNleftPadding);
rc.height = 2;
MwDrawFrame(handle, &rc, base, 1);
rc.x += MwGetInteger(handle, MwNleftPadding);
p.y += MwDefaultBorderWidth(handle) * 2 + 1;
MwDrawFrameEx(handle, &rc, base, 1, 1, 0, 0);
p.y += 2 + 1;
} else {
int tw = MwTextWidth(handle, menu->sub[i]->name);
int th = MwTextHeight(handle, menu->sub[i]->name);
@@ -71,7 +74,7 @@ static void draw(MwWidget handle) {
MwDrawWidgetBack(handle, &r, base, 0, MwTRUE);
}
p.x = 5 + tw / 2;
p.x = 5 + tw / 2 + MwGetInteger(handle, MwNleftPadding);
p.y += th / 2;
MwDrawText(handle, &p, menu->sub[i]->name, menu->sub[i]->wsub != NULL ? 1 : 0, MwALIGNMENT_CENTER, text);
@@ -116,7 +119,11 @@ static void click(MwWidget handle) {
int th = MwTextHeight(handle, menu->sub[i]->name);
rc.height = th;
if(rc.y <= handle->mouse_point.y && handle->mouse_point.y <= (int)(rc.y + rc.height)) {
if(strcmp(menu->sub[i]->name, "----") == 0) {
rc.height = 2 - 1;
}
if(MwGetInteger(handle, MwNleftPadding) <= handle->mouse_point.x && rc.y <= handle->mouse_point.y && handle->mouse_point.y <= (int)(rc.y + rc.height)) {
if(menu->sub[i]->wsub == NULL && arrlen(menu->sub[i]->sub) > 0) {
MwPoint p;
int j;
@@ -160,51 +167,61 @@ static void click(MwWidget handle) {
}
static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point, int diff_calc) {
int i, w = 0, h = 0;
MwRect rc;
MwRect rc, sz;
MwPoint p = *point;
MwSubMenuGetSize(handle, menu, &sz);
MwGetScreenSize(handle, &rc);
handle->internal = menu;
for(i = 0; i < arrlen(menu->sub); i++) {
if(strcmp(menu->sub[i]->name, "----") == 0) {
h += MwDefaultBorderWidth(handle) * 2 + 2;
} else {
int tw = MwTextWidth(handle, menu->sub[i]->name);
h += MwTextHeight(handle, menu->sub[i]->name) + 3;
if(tw > w) {
w = tw;
}
}
}
w += 10 + 15;
h += 3;
w += 32;
if(diff_calc) {
p.y = p.y - h;
p.y = p.y - sz.height;
}
MwLLMakeToolWindow(handle->lowlevel);
MwLLDetach(handle->lowlevel, &p);
if(MwGetInteger(handle, MwNy) + h > rc.height) {
if(MwGetInteger(handle, MwNy) + sz.height > rc.height) {
MwVaApply(handle,
MwNy, rc.height - h,
MwNy, rc.height - sz.height,
NULL);
}
MwLLEndStateChange(handle->lowlevel);
MwVaApply(handle,
MwNwidth, w,
MwNheight, h,
MwNwidth, sz.width,
MwNheight, sz.height,
NULL);
}
static void mwSubMenuGetSizeImpl(MwWidget handle, MwMenu menu, MwRect* rect) {
int i;
rect->width = 0;
rect->height = 0;
for(i = 0; i < arrlen(menu->sub); i++) {
if(strcmp(menu->sub[i]->name, "----") == 0) {
rect->height += 2 + 2;
} else {
int tw = MwTextWidth(handle, menu->sub[i]->name);
rect->height += MwTextHeight(handle, menu->sub[i]->name) + 3;
if(tw > rect->width) {
rect->width = tw;
}
}
}
rect->width += MwGetInteger(handle, MwNleftPadding);
rect->width += 10 + 15;
rect->height += 3;
rect->width += 16;
}
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
(void)out;
@@ -213,6 +230,10 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
MwPoint* point = va_arg(va, MwPoint*);
int diff_calc = va_arg(va, int);
mwSubMenuAppearImpl(handle, menu, point, diff_calc);
} else if(strcmp(name, "mwSubMenuGetSize") == 0) {
MwMenu menu = va_arg(va, MwMenu);
MwRect* rect = va_arg(va, MwRect*);
mwSubMenuGetSizeImpl(handle, menu, rect);
}
}