From 89911082edd8de93248fe0537d369b4ce633c95f Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Wed, 6 May 2026 00:12:06 +0900 Subject: [PATCH] things --- examples/basic/periodic.c | 23 ++++++++--- include/Mw/Milsko.h | 23 ++++++----- include/Mw/StringDefs.h | 4 ++ include/Mw/Widget/Calendar.h | 24 +++++++++++ milsko.xml | 19 +++++++++ pl/rules.pl | 1 + src/text/text.c | 2 +- src/widget/box.c | 3 +- src/widget/calendar.c | 79 ++++++++++++++++++++++++++++++++++++ 9 files changed, 160 insertions(+), 18 deletions(-) create mode 100644 include/Mw/Widget/Calendar.h create mode 100644 src/widget/calendar.c diff --git a/examples/basic/periodic.c b/examples/basic/periodic.c index a1c36b2..24a886f 100644 --- a/examples/basic/periodic.c +++ b/examples/basic/periodic.c @@ -30,7 +30,9 @@ static void newrow(void) { for(i = n; i < Columns; i++) MwCreateWidget(MwFrameClass, "frame", boxes[row], 0, 0, 0, 0); } - boxes[++row] = MwCreateWidget(MwBoxClass, "box", box, 0, 0, 0, 0); + boxes[++row] = MwVaCreateWidget(MwBoxClass, "box", box, 0, 0, 0, 0, + MwNwaitLayout, 1, + NULL); n = 0; } @@ -224,6 +226,7 @@ int main() { box = MwVaCreateWidget(MwBoxClass, "box", window, 0, 0, 0, 0, MwNorientation, MwVERTICAL, + MwNwaitLayout, 1, NULL); newrow(); @@ -263,6 +266,10 @@ int main() { add(f); } + f = frame("Calendar", -PaddingContent, -PaddingContent, MwCalendarClass, + NULL); + add(f); + f = frame("ComboBox", -PaddingContent, 24, MwComboBoxClass, NULL); w = child(f); MwComboBoxAdd(w, -1, "Hello!"); @@ -306,21 +313,18 @@ int main() { f = frame("Separator", -PaddingContent, -PaddingContent, MwSeparatorClass, NULL); add(f); -#if 1 f = frame("SubWindow", -PaddingContent, -PaddingContent, MwViewportClass, - MwNratio, 3, + MwNratio, 2, NULL); w = child(f); MwViewportSetSize(w, 512, 512); MwVaCreateWidget(MwSubWindowClass, "swnd", MwViewportGetViewport(w), 32, 32, 256, 128, MwNtitle, "Sub window", NULL); - add(f); MwVaCreateWidget(MwSubWindowClass, "swnd", MwViewportGetViewport(w), 64, 64, 256, 128, MwNtitle, "Sub window 2", NULL); add(f); -#endif f = frame("TreeView", -PaddingContent, -PaddingContent, MwTreeViewClass, NULL); w = child(f); @@ -344,6 +348,15 @@ int main() { resize(window, NULL, NULL); + MwVaApply(box, + MwNwaitLayout, 0, + NULL); + for(i = 0; i < row; i++) { + MwVaApply(boxes[i], + MwNwaitLayout, 0, + NULL); + } + MwLoop(window); MwLLDestroyPixmap(px); diff --git a/include/Mw/Milsko.h b/include/Mw/Milsko.h index 9600b0c..40aebc5 100644 --- a/include/Mw/Milsko.h +++ b/include/Mw/Milsko.h @@ -32,25 +32,26 @@ #include #include -#include -#include -#include +#include #include -#include +#include #include +#include +#include #include #include -#include -#include -#include -#include +#include #include +#include +#include #include #include +#include #include -#include -#include -#include +#include #include +#include +#include +#include #endif diff --git a/include/Mw/StringDefs.h b/include/Mw/StringDefs.h index 67a53a4..ccf86dc 100644 --- a/include/Mw/StringDefs.h +++ b/include/Mw/StringDefs.h @@ -43,6 +43,10 @@ #define MwNdarkTheme "IdarkTheme" #define MwNuseMonospace "IuseMonospace" #define MwNdarkThemeAutomatic "IdarkThemeAutomatic" +#define MwNmonth "Imonth" +#define MwNdate "Idate" +#define MwNday "Iday" +#define MwNwaitLayout "IwaitLayout" #define MwNtitle "Stitle" #define MwNtext "Stext" diff --git a/include/Mw/Widget/Calendar.h b/include/Mw/Widget/Calendar.h new file mode 100644 index 0000000..a01968f --- /dev/null +++ b/include/Mw/Widget/Calendar.h @@ -0,0 +1,24 @@ +/*! + * @file Mw/Widget/Calendar.h + * @brief Calendar widget + */ +#ifndef __MW_WIDGET_CALENDAR_H__ +#define __MW_WIDGET_CALENDAR_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * @brief Calendar widget class + */ +MWDECL MwClass MwCalendarClass; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/milsko.xml b/milsko.xml index a69cf0b..2247af6 100644 --- a/milsko.xml +++ b/milsko.xml @@ -97,6 +97,10 @@ + + + + @@ -612,6 +616,7 @@ + @@ -627,6 +632,13 @@ + + + + + + + @@ -883,6 +895,13 @@ + + + + + + + diff --git a/pl/rules.pl b/pl/rules.pl index ecb45ec..8c0eb0f 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -143,6 +143,7 @@ new_object("src/text/font/*.c"); new_object("src/widget/box.c"); new_object("src/widget/button.c"); +new_object("src/widget/calendar.c"); new_object("src/widget/checkbox.c"); new_object("src/widget/combobox.c"); new_object("src/widget/entry.c"); diff --git a/src/text/text.c b/src/text/text.c index cf7bf64..ac60ca6 100644 --- a/src/text/text.c +++ b/src/text/text.c @@ -74,7 +74,7 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, if(!MwGetInteger(handle, MwNbitmapFont) && ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf); #endif - p.y -= MwTextHeight(handle, ttf, text) / 2 - (MwTextHeight(handle, ttf, text) / count_nl(text)) / 2; + p.y -= (MwTextHeight(handle, ttf, text) - (MwTextHeight(handle, ttf, text) / count_nl(text))) / 2; while(*input != 0) { input += MwUTF8ToUTF32(input, &cp); diff --git a/src/widget/box.c b/src/widget/box.c index 626ebad..e6afea6 100644 --- a/src/widget/box.c +++ b/src/widget/box.c @@ -15,6 +15,7 @@ static int wcreate(MwWidget handle) { MwSetInteger(handle, MwNpadding, 0); MwSetInteger(handle, MwNhasBorder, 0); MwSetInteger(handle, MwNinverted, 1); + MwSetInteger(handle, MwNwaitLayout, 0); b->layout = 0; @@ -116,7 +117,7 @@ static void children_prop_change(MwWidget handle, MwWidget child, const char* ke static void tick(MwWidget handle) { MwBox b = handle->internal; - if(b->layout) { + if(b->layout && !MwGetInteger(handle, MwNwaitLayout)) { layout(handle); b->layout = 0; diff --git a/src/widget/calendar.c b/src/widget/calendar.c new file mode 100644 index 0000000..0d92b4e --- /dev/null +++ b/src/widget/calendar.c @@ -0,0 +1,79 @@ +#include + +static int wcreate(MwWidget handle) { + MwSetDefault(handle); + + MwSetInteger(handle, MwNmonth, 0); + MwSetInteger(handle, MwNdate, 1); + MwSetInteger(handle, MwNday, 3); + return 0; +} + +static void draw(MwWidget handle) { + MwLLColor c = MwParseColor(handle, MwGetText(handle, MwNbackground)); + MwLLColor csb = MwParseColor(handle, MwGetText(handle, MwNsubBackground)); + MwLLColor csf = MwParseColor(handle, MwGetText(handle, MwNsubForeground)); + MwRect r, r2; + MwPoint p[4]; + int tw = 2; + int th = 6; + char buf[3]; + + r.x = 0; + r.y = 0; + r.width = MwGetInteger(handle, MwNwidth); + r.height = MwGetInteger(handle, MwNheight); + MwDrawRect(handle, &r, c); + + r2.width = 32; + r2.height = 32 - th - 1; + r2.x = (r.width - r2.width) / 2; + r2.y = (r.height - r2.height - th - 1) / 2; + MwDrawRect(handle, &r2, csb); + + p[0].x = r2.x; + p[0].y = r2.y + r2.height; + p[1].x = r2.x - tw; + p[1].y = r2.y + r2.height + th; + p[2].x = r2.x + r2.width - tw; + p[2].y = r2.y + r2.height + th; + p[3].x = r2.x + r2.width; + p[3].y = r2.y + r2.height; + MwLLPolygon(handle->lowlevel, p, 4, csb); + + p[0].x = r.width / 2; + p[0].y = r.height / 2; + sprintf(buf, "%d", MwGetInteger(handle, MwNdate)); + MwDrawText(handle, MwFLBuildFont(MwFLFlagBold), p, buf, MwALIGNMENT_CENTER, csf); + + MwLLFreeColor(csf); + MwLLFreeColor(csb); + MwLLFreeColor(c); +} + +static void prop_change(MwWidget handle, const char* key) { + if(strcmp(key, MwNmonth) == 0 || strcmp(key, MwNdate) == 0 || strcmp(key, MwNday) == 0) MwForceRender(handle); +} + +MwClassRec MwCalendarClassRec = { + wcreate, /* create */ + NULL, /* destroy */ + draw, /* draw */ + NULL, /* click */ + NULL, /* parent_resize */ + prop_change, /* prop_change */ + NULL, /* mouse_move */ + NULL, /* mouse_up */ + NULL, /* mouse_down */ + NULL, /* key */ + NULL, /* execute */ + NULL, /* tick */ + NULL, /* resize */ + NULL, /* children_update */ + NULL, /* children_prop_change */ + NULL, /* clipboard */ + NULL, /* props_change */ + NULL, + NULL, + NULL}; +MwClass MwCalendarClass = &MwCalendarClassRec;