pgpl/tests/program.c

77 lines
1.9 KiB
C
Raw Normal View History

2025-10-03 20:16:11 +02:00
#include <pgpl.h>
#include <stdbool.h>
2025-10-03 20:16:11 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
struct AppData {
PGPL_Gui *gui;
char buffer[128];
2025-10-03 20:16:11 +02:00
};
static void slide_callback(void *data, double value) {
struct AppData *app_data = data;
snprintf(app_data->buffer, 127, "%d", (int)(value * 100));
2025-10-03 20:16:11 +02:00
}
PGPL_GuiWidget *create_main_view(struct AppData *app) {
PGPL_GuiContainerLayout *layout;
PGPL_GuiSliderWidget *slider;
PGPL_GuiTextWidget *text;
layout = pgpl_gui_container_layout_create(
2025-10-07 23:39:22 +02:00
PGPL_GUI_CONTAINER_LAYOUT_DIRECTION_VERTICAL);
layout->parent.ignore_margin = true;
layout->parent.ignore_border = true;
2025-10-08 18:22:43 +02:00
slider = pgpl_gui_slider_widget_create(false, false, 0.0, slide_callback);
2025-10-07 23:39:22 +02:00
slider->parent.border = true;
slider->parent.background = true;
text = pgpl_gui_text_widget_create(app->buffer);
2025-10-07 23:39:22 +02:00
text->parent.border = true;
text->parent.background = true;
text->parent.font_size = PGPL_GUI_FONT_SIZE_TITLE;
2025-10-07 23:39:22 +02:00
text->parent.expansion_fraction = 3;
pgpl_gui_container_layout_widget_add(layout, &text->parent);
pgpl_gui_container_layout_widget_add(layout, &slider->parent);
return (PGPL_GuiWidget *)layout;
2025-10-03 20:16:11 +02:00
}
2025-10-08 18:22:43 +02:00
int main(void) {
2025-10-03 20:16:11 +02:00
PGPL_Gui *gui;
PGPL_GuiTheme theme;
PGPL_Font *font;
struct AppData app;
pgpl_init();
srand(time(NULL));
strcpy(app.buffer, "0");
2025-10-03 20:16:11 +02:00
2025-10-07 23:39:22 +02:00
font = pgpl_font_create_from_file("../roboto.ttf", 256);
2025-10-03 20:16:11 +02:00
2025-10-08 18:22:43 +02:00
pgpl_gui_theme_configure(&theme, pgpl_color_create(0, 128, 255, 255), 32,
2025-10-03 20:16:11 +02:00
font);
2025-10-07 23:39:22 +02:00
gui = pgpl_gui_create("PGPL Test", 480, 320, 0, 0, &theme, &app);
2025-10-03 20:16:11 +02:00
app.gui = gui;
pgpl_gui_widget_add(gui, create_main_view(&app));
pgpl_window_thread_set_minimum_size(gui->window_thread, 320, 240);
pgpl_window_thread_set_maximum_size(gui->window_thread, 640, 480);
2025-10-03 20:16:11 +02:00
pgpl_gui_run_and_show(gui, true);
pgpl_font_destroy(NULL, font);
pgpl_deinit();
return 0;
}