aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-12-07 20:20:27 +0100
committerdec05eba <dec05eba@protonmail.com>2021-12-07 20:20:27 +0100
commit864ee5f167d1e2dda9bfce24ef617d71ce49bfd8 (patch)
tree14c3bfe2d9b28dce43be9efae8e18156de7787fc /tests
parentd3a5b3d579e30ce02afd5e270dfdd511af195c31 (diff)
scrollview
Diffstat (limited to 'tests')
-rw-r--r--tests/main.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/tests/main.c b/tests/main.c
index 2356cb3..eb1c24f 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -1,10 +1,13 @@
+#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 <mgl/mgl.h>
#include <mgl/window/window.h>
#include <mgl/window/event.h>
#include <string.h>
+#include <stdio.h>
static mgui_list* create_list_item(const char *title, const char *description) {
mgui_list *container = mgui_list_create(MGUI_LIST_HORIZONITAL);
@@ -22,26 +25,31 @@ 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_list_append(list, mgui_list_to_widget(create_list_item("Slashbash", "A government has a duty to its own people, first and foremost. If they don't protect their people, they are failing their duties and should be removed.")));
- mgui_list_append(list, mgui_list_to_widget(create_list_item("Andy F.", "Immigration to ANY nation is a privilege given by that nation, not a right.")));
+ 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)) {
- /* TODO:
- if(event.type == MGL_EVENT_RESIZED) {
- mgui_list_set_size(list, (mgl_vec2i){ event.size.width, event.size.height });
- }*/
- mgui_list_on_event(list, &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_list_draw(list, &window);
+ mgui_draw(mgui_scrollview_to_widget(scrollview), &window);
mgl_window_display(&window);
}