add label

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@213 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-08 10:09:10 +00:00
parent b07ee601cd
commit 406452391b
18 changed files with 167 additions and 15 deletions

53
src/widget/label.c Normal file
View File

@@ -0,0 +1,53 @@
/* $Id$ */
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
MwSetDefault(handle);
MwSetInteger(handle, MwNalignment, MwALIGNMENT_CENTER);
return 0;
}
static void draw(MwWidget handle) {
MwRect r;
MwPoint p;
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
int align;
const char* str = MwGetText(handle, MwNtext);
if(str == NULL) str = "";
r.x = 0;
r.y = 0;
r.width = MwGetInteger(handle, MwNwidth);
r.height = MwGetInteger(handle, MwNheight);
MwDrawRect(handle, &r, base);
align = MwGetInteger(handle, MwNalignment);
if(align == MwALIGNMENT_CENTER) {
p.x = r.width / 2;
} else if(align == MwALIGNMENT_BEGINNING) {
p.x = MwTextWidth(handle, str) / 2;
} else if(align == MwALIGNMENT_END) {
p.x = r.width - MwTextWidth(handle, str) / 2;
}
p.y = r.height / 2;
MwDrawText(handle, &p, str, 0, text);
MwLLFreeColor(text);
MwLLFreeColor(base);
}
MwClassRec MwLabelClassRec = {
create, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL /* mouse_down */
};
MwClass MwLabelClass = &MwLabelClassRec;