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

This commit is contained in:
Nishi 2026-04-29 11:47:45 +00:00
commit 94c4bcd2cc
4 changed files with 38 additions and 23 deletions

View file

@ -141,6 +141,7 @@ struct _MwLLHaiku {
MwApplication* app; MwApplication* app;
MwView* view; MwView* view;
thread_id app_thread; thread_id app_thread;
int force_render;
MwLLHaikuEvent* events; MwLLHaikuEvent* events;
}; };

View file

@ -108,14 +108,14 @@ void MwView::MessageReceived(BMessage* message) {
} }
case BVIEW_MW_SHOW: case BVIEW_MW_SHOW:
{ {
if(this->Window() == NULL) { if(this->Parent() == NULL) {
this->handle->haiku.parent->haiku.view->AddChild(this); this->handle->haiku.parent->haiku.view->AddChild(this);
} }
break; break;
} }
case BVIEW_MW_HIDE: case BVIEW_MW_HIDE:
{ {
if(this->Window() != NULL) { if(this->Parent() != NULL) {
this->RemoveSelf(); this->RemoveSelf();
} }
break; break;
@ -393,6 +393,8 @@ MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
r->common.copy_buffer = 1; r->common.copy_buffer = 1;
r->common.type = MwLLBackendHaiku; r->common.type = MwLLBackendHaiku;
r->haiku.force_render = 0;
r->haiku.parent = parent; r->haiku.parent = parent;
r->haiku.events = NULL; r->haiku.events = NULL;
@ -556,6 +558,8 @@ int MwLLPendingImpl(MwLL handle) {
} }
void MwLLNextEventImpl(MwLL handle) { void MwLLNextEventImpl(MwLL handle) {
int rendered = 0;
handle->haiku.view->locker->Lock(); handle->haiku.view->locker->Lock();
while(arrlen(handle->haiku.events) > 0) { while(arrlen(handle->haiku.events) > 0) {
MwLLHaikuEvent* ev = &handle->haiku.events[0]; MwLLHaikuEvent* ev = &handle->haiku.events[0];
@ -568,6 +572,8 @@ void MwLLNextEventImpl(MwLL handle) {
if(ev->type == MwLLHAIKU_EVENT_DRAW) { if(ev->type == MwLLHAIKU_EVENT_DRAW) {
MwLLDispatch(handle, draw, NULL); MwLLDispatch(handle, draw, NULL);
rendered = 1;
} else if(ev->type == MwLLHAIKU_EVENT_CLOSE) { } else if(ev->type == MwLLHAIKU_EVENT_CLOSE) {
MwLLDispatch(handle, close, NULL); MwLLDispatch(handle, close, NULL);
} else if(ev->type == MwLLHAIKU_EVENT_FRAMERESIZED) { } else if(ev->type == MwLLHAIKU_EVENT_FRAMERESIZED) {
@ -589,6 +595,8 @@ void MwLLNextEventImpl(MwLL handle) {
arrdel(handle->haiku.events, 0); arrdel(handle->haiku.events, 0);
} }
handle->haiku.view->locker->Unlock(); handle->haiku.view->locker->Unlock();
if(rendered) handle->haiku.force_render = 0;
} }
MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) { MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
@ -647,6 +655,9 @@ void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {} void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {}
void MwLLForceRenderImpl(MwLL handle) { void MwLLForceRenderImpl(MwLL handle) {
if(handle->haiku.force_render) return;
handle->haiku.force_render = 1;
handle->haiku.view->PostMessage(BVIEW_MW_RENDER); handle->haiku.view->PostMessage(BVIEW_MW_RENDER);
} }

View file

@ -299,7 +299,7 @@ static void resize(MwWidget handle, int no_resize) {
MwAddUserHandler(lb->frame, MwNmouseDownHandler, frame_mouse_down, NULL); MwAddUserHandler(lb->frame, MwNmouseDownHandler, frame_mouse_down, NULL);
MwAddUserHandler(lb->frame, MwNmouseUpHandler, frame_mouse_up, NULL); MwAddUserHandler(lb->frame, MwNmouseUpHandler, frame_mouse_up, NULL);
MwAddUserHandler(lb->frame, MwNmouseMoveHandler, frame_mouse_move, NULL); MwAddUserHandler(lb->frame, MwNmouseMoveHandler, frame_mouse_move, NULL);
} else if(!no_resize) { } else if(!no_resize || MwGetInteger(lb->frame, MwNwidth) != (w - m)) {
MwVaApply(lb->frame, MwVaApply(lb->frame,
MwNx, 0, MwNx, 0,
MwNy, y, MwNy, y,

View file

@ -6,6 +6,8 @@
#define LineSpace 16 #define LineSpace 16
#define LinePadding 4 #define LinePadding 4
#define Font MwFLBuildFont(MwFLFlagMonospace)
static void MWAPI vscroll_changed(MwWidget handle, void* user, void* call) { static void MWAPI vscroll_changed(MwWidget handle, void* user, void* call) {
MwTreeView tv = handle->parent->internal; MwTreeView tv = handle->parent->internal;
@ -30,11 +32,11 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
if((*skip) > 0) { if((*skip) > 0) {
(*skip)--; (*skip)--;
skipped = 1; skipped = 1;
if(p->y == MwDefaultBorderWidth(handle)) p->y -= MwTextHeight(handle, NULL, "M"); if(p->y == MwDefaultBorderWidth(handle)) p->y -= MwTextHeight(handle, Font, "M");
} else if((*shared) < (MwGetInteger(handle, MwNheight) / MwTextHeight(handle, NULL, "M") + 2)) { } else if((*shared) < (MwGetInteger(handle, MwNheight) / MwTextHeight(handle, Font, "M") + 2)) {
MwRect r; MwRect r;
p->x += shift; p->x += shift;
p->y += MwTextHeight(handle, NULL, "M") / 2 + LinePadding; p->y += MwTextHeight(handle, Font, "M") / 2 + LinePadding;
if(tree->tree != NULL || shift > LineSpace) { if(tree->tree != NULL || shift > LineSpace) {
l[0] = *p; l[0] = *p;
@ -47,9 +49,9 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
l[0] = *p; l[0] = *p;
l[0].x -= LineSpace / 2; l[0].x -= LineSpace / 2;
l[1] = l[0]; l[1] = l[0];
l[0].y -= MwTextHeight(handle, NULL, "M") / 2 + LinePadding; l[0].y -= MwTextHeight(handle, Font, "M") / 2 + LinePadding;
if(next) { if(next) {
l[1].y += MwTextHeight(handle, NULL, "M") / 2; l[1].y += MwTextHeight(handle, Font, "M") / 2;
} }
if(draw) MwLLLine(handle->lowlevel, &l[0], text2); if(draw) MwLLLine(handle->lowlevel, &l[0], text2);
} }
@ -57,7 +59,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
r.width = OpenerSize; r.width = OpenerSize;
r.height = OpenerSize; r.height = OpenerSize;
r.x = p->x - LineSpace + (LineSpace - r.width) / 2; r.x = p->x - LineSpace + (LineSpace - r.width) / 2;
r.y = p->y - MwTextHeight(handle, NULL, "M") / 2 + (MwTextHeight(handle, NULL, "M") - r.height) / 2; r.y = p->y - MwTextHeight(handle, Font, "M") / 2 + (MwTextHeight(handle, Font, "M") - r.height) / 2;
if(draw) { if(draw) {
MwLLColor col = tree->opened ? MwLightenColor(handle, base, -8, -8, -8) : base; MwLLColor col = tree->opened ? MwLightenColor(handle, base, -8, -8, -8) : base;
MwRect r2 = r; MwRect r2 = r;
@ -101,11 +103,11 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
} }
} }
if(tree->pixmap != NULL) { if(tree->pixmap != NULL) {
r.height = MwTextHeight(handle, NULL, "M"); r.height = MwTextHeight(handle, Font, "M");
r.width = r.height * tree->pixmap->common.width / tree->pixmap->common.height; r.width = r.height * tree->pixmap->common.width / tree->pixmap->common.height;
r.x = p->x; r.x = p->x;
r.y = p->y - MwTextHeight(handle, NULL, "M") / 2; r.y = p->y - MwTextHeight(handle, Font, "M") / 2;
if(draw) MwLLDrawPixmap(handle->lowlevel, &r, tree->pixmap); if(draw) MwLLDrawPixmap(handle->lowlevel, &r, tree->pixmap);
} }
@ -113,16 +115,16 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
if(draw) { if(draw) {
if(tree->selected) { if(tree->selected) {
r.x = p->x; r.x = p->x;
r.y = p->y - MwTextHeight(handle, NULL, "M") / 2; r.y = p->y - MwTextHeight(handle, Font, "M") / 2;
r.width = MwGetInteger(handle, MwNwidth) - MwGetInteger(handle, MwNleftPadding) - shift; r.width = MwGetInteger(handle, MwNwidth) - MwGetInteger(handle->parent, MwNleftPadding) - shift;
r.height = MwTextHeight(handle, NULL, "M"); r.height = MwTextHeight(handle, Font, "M");
MwDrawRect(handle, &r, text2); MwDrawRect(handle, &r, text2);
} }
handle->bgcolor = tree->selected ? text2 : base2; handle->bgcolor = tree->selected ? text2 : base2;
MwDrawText(handle, NULL, p, tree->label, MwALIGNMENT_BEGINNING, tree->selected ? base2 : text2); MwDrawText(handle, Font, p, tree->label, MwALIGNMENT_BEGINNING, tree->selected ? base2 : text2);
handle->bgcolor = NULL; handle->bgcolor = NULL;
} else { } else {
if(p->x <= mouse->x && mouse->x <= (p->x + MwTextWidth(handle, NULL, tree->label)) && (p->y - MwTextHeight(handle, NULL, "M") / 2) <= mouse->y && mouse->y <= (p->y + MwTextHeight(handle, NULL, "M") / 2)) { if(p->x <= mouse->x && mouse->x <= (p->x + MwTextWidth(handle, Font, tree->label)) && (p->y - MwTextHeight(handle, Font, "M") / 2) <= mouse->y && mouse->y <= (p->y + MwTextHeight(handle, Font, "M") / 2)) {
unsigned long t; unsigned long t;
set_all(root, 0); set_all(root, 0);
@ -136,7 +138,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
} }
p->x -= MwGetInteger(handle->parent, MwNleftPadding); p->x -= MwGetInteger(handle->parent, MwNleftPadding);
p->y += MwTextHeight(handle, NULL, "M") / 2; p->y += MwTextHeight(handle, Font, "M") / 2;
p->x -= shift; p->x -= shift;
(*shared)++; (*shared)++;
@ -145,7 +147,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
for(i = 0; i < arrlen(tree->tree); i++) { for(i = 0; i < arrlen(tree->tree); i++) {
l[0] = *p; l[0] = *p;
l[0].x += shift + LineSpace / 2; l[0].x += shift + LineSpace / 2;
l[0].y += MwTextHeight(handle, NULL, "M") - (MwTextHeight(handle, NULL, "M") - OpenerSize) / 2; l[0].y += MwTextHeight(handle, Font, "M") - (MwTextHeight(handle, Font, "M") - OpenerSize) / 2;
if(tree->tree[i]->tree != NULL) { if(tree->tree[i]->tree != NULL) {
l[0].y += OpenerSize / 2; l[0].y += OpenerSize / 2;
} }
@ -189,7 +191,7 @@ static void frame_draw(MwWidget handle) {
r = r2; r = r2;
for(i = 0; i < arrlen(tv->tree); i++) { for(i = 0; i < arrlen(tv->tree); i++) {
if(shared > (r.height / MwTextHeight(handle, NULL, "M"))) break; if(shared > (r.height / MwTextHeight(handle, Font, "M"))) break;
recursion(handle, tv->tree[i], tv->tree, base, text, base2, text2, &p, 0, LineSpace, &skip, &shared, 1, NULL); recursion(handle, tv->tree[i], tv->tree, base, text, base2, text2, &p, 0, LineSpace, &skip, &shared, 1, NULL);
} }
@ -236,7 +238,7 @@ static void MWAPI frame_mouse_up(MwWidget handle, void* user, void* call) {
p.x = MwDefaultBorderWidth(tv->frame); p.x = MwDefaultBorderWidth(tv->frame);
p.y = MwDefaultBorderWidth(tv->frame); p.y = MwDefaultBorderWidth(tv->frame);
for(i = 0; i < arrlen(tv->tree); i++) { for(i = 0; i < arrlen(tv->tree); i++) {
if(shared > (MwGetInteger(tv->frame, MwNheight) / MwTextHeight(tv->frame, NULL, "M"))) break; if(shared > (MwGetInteger(tv->frame, MwNheight) / MwTextHeight(tv->frame, Font, "M"))) break;
recursion(tv->frame, tv->tree[i], tv->tree, NULL, NULL, NULL, NULL, &p, 0, LineSpace, &skip, &shared, 0, &tv->pressed); recursion(tv->frame, tv->tree[i], tv->tree, NULL, NULL, NULL, NULL, &p, 0, LineSpace, &skip, &shared, 0, &tv->pressed);
} }
resize(handle->parent, 1); resize(handle->parent, 1);
@ -267,7 +269,7 @@ static void resize(MwWidget handle, int no_resize) {
ih = recursive_length(tv->tree); ih = recursive_length(tv->tree);
if(ih == 0) ih = 1; if(ih == 0) ih = 1;
if(ih <= (h / (LinePadding + MwTextHeight(handle, NULL, "M")))) { if(ih <= (h / (LinePadding + MwTextHeight(handle, Font, "M")))) {
MwLLShow(tv->vscroll->lowlevel, 0); MwLLShow(tv->vscroll->lowlevel, 0);
} else { } else {
MwLLShow(tv->vscroll->lowlevel, 1); MwLLShow(tv->vscroll->lowlevel, 1);
@ -282,7 +284,7 @@ static void resize(MwWidget handle, int no_resize) {
tv->frame->draw_inject = frame_draw; tv->frame->draw_inject = frame_draw;
MwAddUserHandler(tv->frame, MwNmouseDownHandler, frame_mouse_down, NULL); MwAddUserHandler(tv->frame, MwNmouseDownHandler, frame_mouse_down, NULL);
MwAddUserHandler(tv->frame, MwNmouseUpHandler, frame_mouse_up, NULL); MwAddUserHandler(tv->frame, MwNmouseUpHandler, frame_mouse_up, NULL);
} else if(!no_resize) { } else if(!no_resize || MwGetInteger(tv->frame, MwNwidth) != (w - m)) {
MwVaApply(tv->frame, MwVaApply(tv->frame,
MwNx, 0, MwNx, 0,
MwNy, 0, MwNy, 0,
@ -292,7 +294,7 @@ static void resize(MwWidget handle, int no_resize) {
} }
MwVaApply(tv->vscroll, MwVaApply(tv->vscroll,
MwNareaShown, h / (LinePadding + MwTextHeight(handle, NULL, "M")), MwNareaShown, h / (LinePadding + MwTextHeight(handle, Font, "M")),
MwNmaxValue, ih, MwNmaxValue, ih,
NULL); NULL);
} }
@ -375,6 +377,7 @@ static void mwTreeViewDeleteImpl(MwWidget handle, void* item) {
free_all(p->tree); free_all(p->tree);
p->tree = NULL; p->tree = NULL;
resize(handle, 1);
MwForceRender(tv->frame); MwForceRender(tv->frame);
} }