pgpl/tests/program.c

78 lines
2 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
}
static void configure_widget_default(PGPL_GuiWidget *widget) {
pgpl_gui_widget_configure(widget, 0, 0, true, true, false, false,
2025-10-03 20:16:11 +02:00
PGPL_GUI_FONT_SIZE_CONTENT, NULL, false, false,
false, false);
}
PGPL_GuiWidget *create_main_view(struct AppData *app) {
PGPL_GuiContainerLayout *layout;
PGPL_GuiSliderWidget *slider;
PGPL_GuiTextWidget *text;
layout = pgpl_gui_container_layout_create(
PGPL_GUI_CONTAINER_LAYOUT_DIRECTION_HORIZONTAL);
pgpl_gui_widget_configure(&layout->parent, 0, 0, true, true, false, false,
PGPL_GUI_FONT_SIZE_CONTENT, NULL, false, true, true,
false);
slider = pgpl_gui_slider_widget_create(16, true, true, 0.0, slide_callback);
configure_widget_default(&slider->parent);
text = pgpl_gui_text_widget_create(app->buffer);
configure_widget_default(&text->parent);
text->parent.font_size = PGPL_GUI_FONT_SIZE_TITLE;
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
}
int32_t main(void) {
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
font = pgpl_font_create_from_file("../roboto.ttf", 128);
2025-10-03 20:16:11 +02:00
pgpl_gui_theme_configure(&theme, pgpl_color_create(255, 255, 255, 255), 48,
font);
gui = pgpl_gui_create("PGPL Test", 480, 240, 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_gui_run_and_show(gui, true);
pgpl_font_destroy(NULL, font);
pgpl_deinit();
return 0;
}