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
}
2026-09-17 02:03:09 +09:00
static void MWAPI activate_document ( MwWidget handle , void * user , void * call ) {
if ( strcmp ( ( const char * ) call , " you_clicked " ) = = 0 ) {
MwVaApply ( document ,
MwNtext , " # You clicked the thing! " ,
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 ;
2026-09-17 02:03:09 +09:00
strcpy ( text , " # Hello world! \n This is a __test__ text... \n \n " ) ;
strcat ( text , " `Some monospace here` \n \n " ) ;
strcat ( text , " ~~Removed~~ \n " ) ;
strcat ( text , " ``` \n int main(){ \n printf( \" Hello, world! \\ n \" ); \n } \n ``` \n " ) ;
strcat ( text , " [Click me!](you_clicked) \n \n " ) ;
2026-09-15 12:05:02 +09:00
for ( i = 0 ; i < 10 ; i + + ) {
2026-09-17 02:03:09 +09:00
strcat ( text , " **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. \n \n " ) ;
2026-09-15 12:05:02 +09:00
}
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-17 02:03:09 +09:00
MwAddUserHandler ( document , MwNdocumentActivateHandler , activate_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 ) ;
}