milsko/examples/basic/document.c

62 lines
2 KiB
C
Raw Normal View History

2026-09-15 05:14:36 +09:00
#include <Mw/Milsko.h>
MwWidget window, viewport, document;
static void MWAPI resize_window(MwWidget handle, void* user, void* call) {
int width = MwGetInteger(window, MwNwidth);
int height = MwGetInteger(window, MwNheight);
MwVaApply(viewport,
MwNx, 10,
MwNy, 10,
MwNwidth, width - 20,
MwNheight, height - 20,
NULL);
2026-09-15 11:58:16 +09:00
width = MwGetInteger(MwGetParent(MwViewportGetViewport(viewport)), MwNwidth);
height = MwGetInteger(MwGetParent(MwViewportGetViewport(viewport)), MwNheight);
MwVaApply(document,
MwNwidth, width,
NULL);
2026-09-15 05:14:36 +09:00
}
2026-09-15 11:58:16 +09:00
static void MWAPI layout_document(MwWidget handle, void* user, void* call) {
int height = *(int*)call;
MwViewportSetSize(viewport, MwGetInteger(document, MwNwidth), height);
MwVaApply(document,
MwNheight, height,
NULL);
2026-09-15 05:14:36 +09:00
}
int main() {
2026-09-15 12:05:02 +09:00
char* text = malloc(64 * 1024);
int i;
strcpy(text, "# Hello world!\nThis is a __test__ text...\n\n`Some monospace here`\n\n~~Removed~~");
for(i = 0; i < 10; i++) {
strcat(text, "\n\n**Lorem ipsum** dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
}
2026-09-15 05:14:36 +09:00
MwLibraryInit();
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 640, 480,
MwNtitle, "markdown document",
NULL);
viewport = MwCreateWidget(MwViewportClass, "viewport", window, 0, 0, 0, 0);
document = MwVaCreateWidget(MwDocumentClass, "document", MwViewportGetViewport(viewport), 0, 0, 0, 0,
2026-09-15 12:05:02 +09:00
MwNtext, text,
2026-09-15 05:14:36 +09:00
NULL);
MwAddUserHandler(window, MwNresizeHandler, resize_window, NULL);
2026-09-15 11:58:16 +09:00
MwAddUserHandler(document, MwNlayoutHandler, layout_document, NULL);
2026-09-15 05:14:36 +09:00
resize_window(window, NULL, NULL);
2026-09-15 12:05:02 +09:00
free(text);
2026-09-15 05:14:36 +09:00
MwLoop(window);
}