diff --git a/examples/basic/periodic.c b/examples/basic/periodic.c new file mode 100644 index 0000000..10ca442 --- /dev/null +++ b/examples/basic/periodic.c @@ -0,0 +1,79 @@ +#include + +#define Columns 4 +#define Padding 20 + +MwWidget window, menu, box; +MwWidget boxes[32]; +int n = 0, row = -1; + +static void resize(MwWidget handle, void* user, void* call){ + int w = MwGetInteger(window, MwNwidth); + int h = MwGetInteger(window, MwNheight); + + MwVaApply(box, + MwNx, Padding, + MwNy, MwGetInteger(menu, MwNheight) + Padding, + MwNwidth, w - Padding * 2, + MwNheight, h - MwGetInteger(menu, MwNheight) - Padding * 2, + NULL); +} + +static void newrow(void){ + if(row >= 0){ + } + + boxes[++row] = MwCreateWidget(MwBoxClass, "box", box, 0, 0, 0, 0); +} + +static void add(MwWidget w){ + int r = MwGetInteger(w, MwNratio); + + if(r == MwDEFAULT) r = 1; + + n += r; + + if(n == Columns){ + n = 0; + newrow(); + } +} + +static MwWidget frame(const char* name, MwWidget w){ + MwWidget f = MwVaCreateWidget(MwFrameClass, "frame", boxes[row], 0, 0, 0, 0, + MwNhasBorder, 1, + MwNinverted, 1, + NULL); + + return f; +} + +int main(){ + MwLibraryInit(); + + window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 800, 800, + MwNtitle, "Milsko Periodic Table", + NULL); + + menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0); + + box = MwVaCreateWidget(MwBoxClass, "box", window, 0, 0, 0, 0, + MwNorientation, MwVERTICAL, + NULL); + + newrow(); + + add(frame("Separator", NULL)); + + add(MwVaCreateWidget(MwLabelClass, "label", boxes[row], 0, 0, 0, 0, + MwNbold, 1, + MwNtext, "The Periodic Table of Milsko Widgets", + MwNratio, Columns - 2, + NULL)); + + add(frame("TODO", NULL)); + + resize(window, NULL, NULL); + + MwLoop(window); +} diff --git a/pl/rules.pl b/pl/rules.pl index 748ce8a..e49f01c 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -138,6 +138,7 @@ new_example("examples/basic/box"); new_example("examples/basic/clipboard"); new_example("examples/basic/sevensegment"); new_example("examples/basic/calculator"); +new_example("examples/basic/periodic"); if (param_get("opengl")) { new_example("examples/gldemos/boing", $gl_libs);