fix look, add actual event

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@764 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-11-21 15:07:12 +00:00
parent 8ed8e51ba7
commit c97f1722fc
9 changed files with 106 additions and 29 deletions

View File

@@ -23,6 +23,16 @@ MWDECL const char* MwDefaultBackground;
*/
MWDECL const char* MwDefaultForeground;
/*!
* @brief Default sub background color
*/
MWDECL const char* MwDefaultSubBackground;
/*!
* @brief Default sub foreground color
*/
MWDECL const char* MwDefaultSubForeground;
/*!
* @brief Default dark theme background color
*/
@@ -33,6 +43,16 @@ MWDECL const char* MwDefaultDarkBackground;
*/
MWDECL const char* MwDefaultDarkForeground;
/*!
* @brief Default dark theme sub background color
*/
MWDECL const char* MwDefaultDarkSubBackground;
/*!
* @brief Default dark theme sub foreground color
*/
MWDECL const char* MwDefaultDarkSubForeground;
/*!
* @brief Gets default border width
* @param handle Widget

View File

@@ -33,7 +33,9 @@
#define MwNtitle "Stitle"
#define MwNtext "Stext"
#define MwNbackground "Sbackground"
#define MwNsubBackground "SsubBackground"
#define MwNforeground "Sforeground"
#define MwNsubForeground "SsubForeground"
#define MwNpixmap "Vpixmap"
#define MwNiconPixmap "ViconPixmap"
@@ -41,7 +43,7 @@
#define MwNfont "Vfont"
#define MwNboldFont "VboldFont"
#define MwNactivateHandler "Cactivate" /* NULL/int* (MwListBox) */
#define MwNactivateHandler "Cactivate" /* NULL/int* (MwListBox)/void* (MwTreeView) */
#define MwNresizeHandler "Cresize" /* NULL */
#define MwNtickHandler "Ctick" /* NULL */
#define MwNmenuHandler "Cmenu" /* MwMenu */

View File

@@ -49,6 +49,18 @@ MwInline void MwTreeViewReset(MwWidget handle) {
MwVaWidgetExecute(handle, "mwTreeViewReset", NULL);
}
/*!
* @brief Gets item from the treeview
* @param handle Widget
* @param item Item
* @return Item
*/
MwInline const char* MwTreeViewGet(MwWidget handle, void* item) {
const char* out;
MwVaWidgetExecute(handle, "mwTreeViewGet", (void*)&out, item);
return out;
}
#ifdef __cplusplus
}
#endif

View File

@@ -92,6 +92,7 @@ new_example("examples/basic/listbox");
new_example("examples/basic/progressbar");
new_example("examples/basic/colorpicker");
new_example("examples/basic/combobox");
new_example("examples/basic/treeview");
if (param_get("opengl")) {
new_example("examples/gldemos/boing", $gl_libs);

View File

@@ -373,7 +373,7 @@ void MwSetText(MwWidget handle, const char* key, const char* value) {
MwLLSetBackground(handle->lowlevel, c);
MwLLFreeColor(c);
}
if(strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0) {
if(strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0 || strcmp(key, MwNsubBackground) == 0 || strcmp(key, MwNsubForeground) == 0) {
MwForceRender(handle);
}
}
@@ -411,7 +411,7 @@ int MwGetInteger(MwWidget handle, const char* key) {
}
const char* MwGetText(MwWidget handle, const char* key) {
if(shgeti(handle->text, key) == -1 && (strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0)) {
if(shgeti(handle->text, key) == -1 && (strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0 || strcmp(key, MwNsubBackground) == 0 || strcmp(key, MwNsubForeground) == 0)) {
const char* v = NULL;
MwWidget h = handle->parent;
while(h != NULL) {
@@ -422,9 +422,13 @@ const char* MwGetText(MwWidget handle, const char* key) {
if(handle->dark_theme) {
if(strcmp(key, MwNbackground) == 0) return MwDefaultDarkBackground;
if(strcmp(key, MwNforeground) == 0) return MwDefaultDarkForeground;
if(strcmp(key, MwNsubBackground) == 0) return MwDefaultDarkSubBackground;
if(strcmp(key, MwNsubForeground) == 0) return MwDefaultDarkSubForeground;
} else {
if(strcmp(key, MwNbackground) == 0) return MwDefaultBackground;
if(strcmp(key, MwNforeground) == 0) return MwDefaultForeground;
if(strcmp(key, MwNsubBackground) == 0) return MwDefaultSubBackground;
if(strcmp(key, MwNsubForeground) == 0) return MwDefaultSubForeground;
}
}
return v;

View File

@@ -1,11 +1,15 @@
/* $Id$ */
#include <Mw/Milsko.h>
const char* MwDefaultBackground = "#d2d2d2";
const char* MwDefaultForeground = "#000";
const char* MwDefaultBackground = "#d2d2d2";
const char* MwDefaultForeground = "#000";
const char* MwDefaultSubBackground = "#fff";
const char* MwDefaultSubForeground = "#000";
const char* MwDefaultDarkBackground = "#333";
const char* MwDefaultDarkForeground = "#ddd";
const char* MwDefaultDarkBackground = "#333";
const char* MwDefaultDarkForeground = "#ddd";
const char* MwDefaultDarkSubBackground = "#000";
const char* MwDefaultDarkSubForeground = "#fff";
int MwDefaultBorderWidth(MwWidget handle) {
if(MwGetInteger(handle, MwNmodernLook)) {

View File

@@ -185,10 +185,12 @@ static void frame_mouse_move(MwWidget handle, void* user, void* call) {
}
static void frame_draw(MwWidget handle) {
MwRect r;
MwListBox lb = handle->parent->internal;
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
MwRect r, r2;
MwListBox lb = handle->parent->internal;
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwLLColor base2 = MwParseColor(handle, MwGetText(handle, MwNsubBackground));
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
MwLLColor text2 = MwParseColor(handle, MwGetText(handle, MwNsubForeground));
int i;
MwPoint p;
int st = 0;
@@ -199,10 +201,16 @@ static void frame_draw(MwWidget handle) {
r.y = 0;
r.width = MwGetInteger(handle, MwNwidth);
r.height = MwGetInteger(handle, MwNheight);
r2 = r;
p.x = MwDefaultBorderWidth(handle);
p.y = MwDefaultBorderWidth(handle);
MwDrawFrame(handle, &r, base, 1);
MwDrawRect(handle, &r, base2);
r = r2;
st = get_first_entry(handle->parent, lb);
area = r.height - MwDefaultBorderWidth(handle) * 2;
@@ -218,8 +226,8 @@ static void frame_draw(MwWidget handle) {
r2.y = p.y;
r2.width = r.width;
r2.height = MwTextHeight(handle, "M");
MwDrawRect(handle, &r2, text);
handle->bgcolor = text;
MwDrawRect(handle, &r2, text2);
handle->bgcolor = text2;
}
if(lb->list[i].pixmap != NULL) {
MwRect r2;
@@ -238,7 +246,7 @@ static void frame_draw(MwWidget handle) {
if(t == NULL) t = "";
p.x += MwDefaultBorderWidth(handle);
MwDrawText(handle, &p, t, 0, MwALIGNMENT_BEGINNING, selected ? base : text);
MwDrawText(handle, &p, t, 0, MwALIGNMENT_BEGINNING, selected ? base2 : text2);
p.x += get_col_width(lb, j) - MwDefaultBorderWidth(handle);
if(j == 0) p.x -= 4;
@@ -250,7 +258,9 @@ static void frame_draw(MwWidget handle) {
MwDrawFrame(handle, &r, base, 1);
MwLLFreeColor(text2);
MwLLFreeColor(text);
MwLLFreeColor(base2);
MwLLFreeColor(base);
}

View File

@@ -5,7 +5,7 @@
#include "Mw/TypeDefs.h"
static void set_xywh(MwWidget handle) {
int height = 0;
int height = 0;
height = MwTextHeight(handle, "M") + 10;

View File

@@ -23,7 +23,7 @@ static void set_all(MwTreeViewEntry** root, int v) {
}
}
static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry** root, MwLLColor base, MwLLColor text, MwPoint* p, int next, int shift, int* skip, int* shared, int draw, MwPoint* mouse) {
static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry** root, MwLLColor base, MwLLColor text, MwLLColor base2, MwLLColor text2, MwPoint* p, int next, int shift, int* skip, int* shared, int draw, MwPoint* mouse) {
int i;
MwPoint l[2];
int skipped = 0;
@@ -40,7 +40,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
l[0] = *p;
l[0].x -= LineSpace / 2;
l[1] = *p;
if(draw) MwLLLine(handle->lowlevel, &l[0], text);
if(draw) MwLLLine(handle->lowlevel, &l[0], text2);
l[0] = *p;
l[0].x -= LineSpace / 2;
@@ -49,7 +49,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
if(next) {
l[1].y += MwTextHeight(handle, "M") / 2;
}
if(draw) MwLLLine(handle->lowlevel, &l[0], text);
if(draw) MwLLLine(handle->lowlevel, &l[0], text2);
}
if(tree->tree != NULL) {
r.width = OpenerSize;
@@ -114,10 +114,10 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
r.y = p->y - MwTextHeight(handle, "M") / 2;
r.width = MwTextWidth(handle, tree->label);
r.height = MwTextHeight(handle, "M");
MwDrawRect(handle, &r, text);
MwDrawRect(handle, &r, text2);
}
handle->bgcolor = tree->selected ? text : base;
MwDrawText(handle, p, tree->label, 0, MwALIGNMENT_BEGINNING, tree->selected ? base : text);
handle->bgcolor = tree->selected ? text2 : base2;
MwDrawText(handle, p, tree->label, 0, MwALIGNMENT_BEGINNING, tree->selected ? base2 : text2);
handle->bgcolor = NULL;
} else {
if(p->x <= mouse->x && mouse->x <= (p->x + MwTextWidth(handle, tree->label)) && (p->y - MwTextHeight(handle, "M") / 2) <= mouse->y && mouse->y <= (p->y + MwTextHeight(handle, "M") / 2)) {
@@ -126,7 +126,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
set_all(root, 0);
tree->selected = 1;
if(((t = MwTimeGetTick()) - tree->click_time) < MwDoubleClickTimeout || MwGetInteger(handle->parent, MwNsingleClickSelectable)) {
/* TODO: dispatch event */
MwDispatchUserHandler(handle->parent, MwNactivateHandler, tree);
}
tree->click_time = t;
@@ -145,7 +145,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
l[0].x += shift + LineSpace / 2;
l[0].y += MwTextHeight(handle, "M") - (MwTextHeight(handle, "M") - OpenerSize) / 2;
recursion(handle, tree->tree[i], root, base, text, p, i != (arrlen(tree->tree) - 1) ? 1 : 0, shift + LineSpace, skip, shared, draw, mouse);
recursion(handle, tree->tree[i], root, base, text, base2, text2, p, i != (arrlen(tree->tree) - 1) ? 1 : 0, shift + LineSpace, skip, shared, draw, mouse);
l[1] = *p;
l[1].x += shift + LineSpace / 2;
@@ -158,10 +158,12 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
}
static void frame_draw(MwWidget handle) {
MwRect r;
MwTreeView tv = handle->parent->internal;
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
MwRect r, r2;
MwTreeView tv = handle->parent->internal;
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwLLColor base2 = MwParseColor(handle, MwGetText(handle, MwNsubBackground));
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
MwLLColor text2 = MwParseColor(handle, MwGetText(handle, MwNsubForeground));
MwPoint p;
int shared = 0;
int i;
@@ -171,18 +173,26 @@ static void frame_draw(MwWidget handle) {
r.y = 0;
r.width = MwGetInteger(handle, MwNwidth);
r.height = MwGetInteger(handle, MwNheight);
r2 = r;
p.x = MwDefaultBorderWidth(handle);
p.y = MwDefaultBorderWidth(handle);
MwDrawFrame(handle, &r, base, 1);
MwDrawRect(handle, &r, base2);
r = r2;
for(i = 0; i < arrlen(tv->tree); i++) {
if(shared > (r.height / MwTextHeight(handle, "M"))) break;
recursion(handle, tv->tree[i], tv->tree, base, text, &p, 0, 0, &skip, &shared, 1, NULL);
recursion(handle, tv->tree[i], tv->tree, base, text, base2, text2, &p, 0, 0, &skip, &shared, 1, NULL);
}
MwDrawFrame(handle, &r, base, 1);
MwLLFreeColor(text2);
MwLLFreeColor(text);
MwLLFreeColor(base2);
MwLLFreeColor(base);
}
@@ -222,7 +232,7 @@ static void frame_mouse_up(MwWidget handle, void* user, void* call) {
p.y = MwDefaultBorderWidth(tv->frame);
for(i = 0; i < arrlen(tv->tree); i++) {
if(shared > (MwGetInteger(tv->frame, MwNheight) / MwTextHeight(tv->frame, "M"))) break;
recursion(tv->frame, tv->tree[i], tv->tree, NULL, NULL, &p, 0, 0, &skip, &shared, 0, &tv->pressed);
recursion(tv->frame, tv->tree[i], tv->tree, NULL, NULL, NULL, NULL, &p, 0, 0, &skip, &shared, 0, &tv->pressed);
}
resize(handle->parent);
}
@@ -356,6 +366,8 @@ static void mwTreeViewDeleteImpl(MwWidget handle, void* item) {
MwTreeViewEntry* e = item;
MwTreeViewEntry* p = e->parent;
(void)handle;
free_all(p->tree);
p->tree = NULL;
}
@@ -368,6 +380,14 @@ static void mwTreeViewResetImpl(MwWidget handle) {
resize(handle);
}
static const char* mwTreeViewGetImpl(MwWidget handle, void* item) {
MwTreeViewEntry* e = item;
(void)handle;
return e->label;
}
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
if(strcmp(name, "mwTreeViewAdd") == 0) {
void* parent = va_arg(va, void*);
@@ -382,6 +402,10 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
if(strcmp(name, "mwTreeViewReset") == 0) {
mwTreeViewResetImpl(handle);
}
if(strcmp(name, "mwTreeViewGet") == 0) {
void* item = va_arg(va, void*);
*(const char**)out = mwTreeViewGetImpl(handle, item);
}
}
static void tick(MwWidget handle) {