#include "../include/mgui/mgui.h" #include "../include/mgui/list.h" #include "../include/mgui/scrollview.h" #include "../include/mgui/button.h" #include "../include/mgui/label.h" #include "../include/mgui/richtext.h" #include #include #include #include #include static mgui_list* create_list_item(const char *title, const char *description) { mgui_list *container = mgui_list_create(MGUI_LIST_HORIZONITAL); mgui_list_append(container, mgui_button_to_widget(mgui_button_create("button", 6, 30))); mgui_list *list = mgui_list_create(MGUI_LIST_VERTICAL); mgui_list_append(container, mgui_list_to_widget(list)); mgui_list_append(list, mgui_richtext_to_widget(mgui_richtext_create(title, strlen(title), 30))); mgui_list_append(list, mgui_richtext_to_widget(mgui_richtext_create(description, strlen(description), 24))); return container; } int main() { if(mgl_init() != 0) return 1; mgui_init(); mgl_window window; if(mgl_window_create(&window, "mgl", &(mgl_window_create_params){ .size = { 1280, 720 } }) != 0) return 1; mgui_list *root = mgui_list_create(MGUI_LIST_VERTICAL); mgui_widget *root_widget = mgui_list_to_widget(root); mgui_list_append(root, mgui_list_to_widget(create_list_item("Title", "Description"))); mgui_scrollview *scrollview = mgui_scrollview_create(); mgui_widget_set_expand(mgui_scrollview_to_widget(scrollview), false, true); mgui_list_append(root, mgui_scrollview_to_widget(scrollview)); mgui_list *list = mgui_list_create(MGUI_LIST_VERTICAL); mgui_scrollview_set_child(scrollview, mgui_list_to_widget(list)); for(int i = 0; i < 30; ++i) { char text[256]; snprintf(text, sizeof(text), "hello world 東京 %d", i); mgui_list_append(list, mgui_list_to_widget(create_list_item("User", text))); } mgui_list_append(root, mgui_list_to_widget(create_list_item("Bottom", "bottom"))); mgl_event event; while(mgl_window_is_open(&window)) { while(mgl_window_poll_event(&window, &event)) { mgui_on_event(root_widget, &window, &event); } mgl_window_clear(&window, (mgl_color){ 0, 0, 0, 0 }); mgui_draw(root_widget, &window); mgl_window_display(&window); } mgui_widget_destroy(root_widget); mgl_window_deinit(&window); mgl_deinit(); return 0; }