menu widget

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@132 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-02 02:50:28 +00:00
parent 81c47a9733
commit ef4ce2a5f3
6 changed files with 42 additions and 8 deletions

View File

@@ -79,6 +79,7 @@ static void draw(MwWidget handle) {
int tw = MwTextWidth(handle, m->sub[i]->name + incr);
int th = MwTextHeight(handle, m->sub[i]->name + incr);
int oldx = p.x;
int in_area;
if(incr) {
p.x = MwGetInteger(handle, MwNwidth) - tw - 10;
@@ -90,7 +91,8 @@ static void draw(MwWidget handle) {
r.width = tw + 10;
r.height = th + 10;
if(handle->pressed && r.x <= handle->pressed_point.x && r.y <= handle->pressed_point.y && handle->pressed_point.x <= (int)(r.x + r.width) && handle->pressed_point.y <= (int)(r.y + r.height)) {
in_area = (r.x <= handle->mouse_point.x && r.y <= handle->mouse_point.y && handle->mouse_point.x <= (int)(r.x + r.width) && handle->mouse_point.y <= (int)(r.y + r.height)) ? 1 : 0;
if(handle->pressed && in_area) {
MwDrawFrame(handle, &r, base, 0);
if(m->sub[i]->wsub == NULL && arrlen(m->sub[i]->sub) > 0) {
MwPoint p2;
@@ -100,10 +102,24 @@ static void draw(MwWidget handle) {
m->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, 0, 0, 0);
MwSubMenuAppear(m->sub[i]->wsub, m->sub[i], &p2);
} else if(m->sub[i]->keep) {
MwDestroyWidget(m->sub[i]->wsub);
m->sub[i]->wsub = NULL;
m->sub[i]->keep = 0;
}
} else if(!handle->pressed && m->sub[i]->wsub != NULL) {
if(in_area) {
MwDrawFrame(handle, &r, base, 0);
m->sub[i]->keep = 1;
} else {
MwDestroyWidget(m->sub[i]->wsub);
m->sub[i]->wsub = NULL;
m->sub[i]->keep = 0;
}
} 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;
}
MwDrawText(handle, &p, m->sub[i]->name + incr, 1, text);
@@ -135,6 +151,7 @@ MwMenu MwMenuAdd(MwWidget handle, MwMenu menu, const char* name) {
new->name = malloc(strlen(name) + 1);
new->sub = NULL;
new->wsub = NULL;
new->keep = 0;
strcpy(new->name, name);

View File

@@ -101,6 +101,7 @@ void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) {
XChangeProperty(handle->lowlevel->display, handle->lowlevel->window, wndtype, 4, 32, PropModeReplace, (unsigned char*)&wndmenu, 1);
XMapWindow(handle->lowlevel->display, handle->lowlevel->window);
XSetInputFocus(handle->lowlevel->display, handle->lowlevel->window, RevertToNone, CurrentTime);
#endif
handle->internal = menu;