#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_set_background_color(container, (mgl_color){ 255, 0, 0, 255 }); mgui_list_append(container, mgui_button_to_widget(mgui_button_create())); 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_scrollview *scrollview = mgui_scrollview_create(); 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))); } mgl_event event; while(mgl_window_is_open(&window)) { while(mgl_window_poll_event(&window, &event)) { if(event.type == MGL_EVENT_RESIZED) mgui_scrollview_set_size(scrollview, (mgl_vec2i){ event.size.width, event.size.height }); mgui_scrollview_on_event(scrollview, &window, &event); } mgl_window_clear(&window, (mgl_color){ 0, 0, 0, 0 }); mgui_draw(mgui_scrollview_to_widget(scrollview), &window); mgl_window_display(&window); } mgl_deinit(); return 0; }