From 90128dc6b28d361dd924e9eaea8ffd22f5f78022 Mon Sep 17 00:00:00 2001 From: Nishi Date: Wed, 13 May 2026 14:23:02 +0900 Subject: [PATCH] fix some stuff --- include/Mw/TypeDefs.h | 1 + src/widget/menu.c | 38 ++++++++++++++++++++++---------------- src/widget/treeview.c | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index ef06106..1e06371 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -125,6 +125,7 @@ struct _MwMenu { MwWidget wsub; MwMenu* sub; void* opaque; + int cleaned; }; struct _MwEntry { diff --git a/src/widget/menu.c b/src/widget/menu.c index b7cd471..7df61f2 100644 --- a/src/widget/menu.c +++ b/src/widget/menu.c @@ -98,7 +98,8 @@ static void destroy(MwWidget handle) { p2.y = p.y + th / 2 + 5; \ \ m->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, MwGetInteger(handle, MwNheight), 0, 0); \ - MwSubMenuAppear(m->sub[i]->wsub, m->sub[i], &p2, 0); + MwSubMenuAppear(m->sub[i]->wsub, m->sub[i], &p2, 0); \ + m->sub[i]->cleaned = 0; static void draw(MwWidget handle) { MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); @@ -139,13 +140,15 @@ static void mouse_down(MwWidget handle, void* ptr) { NEW_SUBMENU; } else if(m->sub[i]->wsub != NULL && m->sub[i]->keep) { MwDestroyWidget(m->sub[i]->wsub); - m->sub[i]->wsub = NULL; - m->sub[i]->keep = 0; + m->sub[i]->wsub = NULL; + m->sub[i]->keep = 0; + m->sub[i]->cleaned = 1; } } else if(m->sub[i]->keep && m->sub[i]->wsub != NULL) { MwDestroyWidget(m->sub[i]->wsub); - m->sub[i]->wsub = NULL; - m->sub[i]->keep = 0; + m->sub[i]->wsub = NULL; + m->sub[i]->keep = 0; + m->sub[i]->cleaned = 1; } END_MENU_LOOP; @@ -170,15 +173,16 @@ static void mouse_move(MwWidget handle) { BEGIN_MENU_LOOP; if(matched && m->sub[i]->wsub != NULL) { MwDestroyWidget(m->sub[i]->wsub); - m->sub[i]->wsub = NULL; - m->sub[i]->keep = 0; + m->sub[i]->wsub = NULL; + m->sub[i]->keep = 0; + m->sub[i]->cleaned = 0; } END_MENU_LOOP; MENU_LOOP_INIT; BEGIN_MENU_LOOP; if(matched && in_area) { - if(m->sub[i]->wsub == NULL && arrlen(m->sub[i]->sub) > 0) { + if(m->sub[i]->wsub == NULL && arrlen(m->sub[i]->sub) > 0 && !m->sub[i]->cleaned) { NEW_SUBMENU; } } @@ -203,8 +207,9 @@ static void mouse_up(MwWidget handle, void* ptr) { } } else if(m->sub[i]->wsub != NULL) { MwDestroyWidget(m->sub[i]->wsub); - m->sub[i]->wsub = NULL; - m->sub[i]->keep = 0; + m->sub[i]->wsub = NULL; + m->sub[i]->keep = 0; + m->sub[i]->cleaned = 0; } END_MENU_LOOP; @@ -212,12 +217,13 @@ static void mouse_up(MwWidget handle, void* ptr) { } static MwMenu mwMenuAddImpl(MwWidget handle, MwMenu menu, const char* name) { - MwMenu m = menu == NULL ? handle->internal : menu; - MwMenu new = malloc(sizeof(*new)); - new->name = MwStringDuplicate(name); - new->sub = NULL; - new->wsub = NULL; - new->keep = 0; + MwMenu m = menu == NULL ? handle->internal : menu; + MwMenu new = malloc(sizeof(*new)); + new->name = MwStringDuplicate(name); + new->sub = NULL; + new->wsub = NULL; + new->keep = 0; + new->cleaned = 0; arrput(m->sub, new); diff --git a/src/widget/treeview.c b/src/widget/treeview.c index f74c2b2..3fba309 100644 --- a/src/widget/treeview.c +++ b/src/widget/treeview.c @@ -106,7 +106,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry** r.height = MwTextHeight(handle, Font, "M"); r.width = r.height * tree->pixmap->common.width / tree->pixmap->common.height; - r.x = p->x; + r.x = p->x + (MwGetInteger(handle->parent, MwNleftPadding) - r.width) / 2; r.y = p->y - MwTextHeight(handle, Font, "M") / 2; if(draw) MwLLDrawPixmap(handle->lowlevel, &r, tree->pixmap);