77 lines
1.9 KiB
C
77 lines
1.9 KiB
C
#include <pgpl.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
struct AppData {
|
|
PGPL_Gui *gui;
|
|
char buffer[128];
|
|
};
|
|
|
|
static void slide_callback(void *data, double value) {
|
|
struct AppData *app_data = data;
|
|
snprintf(app_data->buffer, 127, "%d", (int)(value * 100));
|
|
}
|
|
|
|
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_VERTICAL);
|
|
layout->parent.ignore_margin = true;
|
|
layout->parent.ignore_border = true;
|
|
|
|
slider = pgpl_gui_slider_widget_create(false, false, 0.0, slide_callback);
|
|
slider->parent.border = true;
|
|
slider->parent.background = true;
|
|
|
|
text = pgpl_gui_text_widget_create(app->buffer);
|
|
text->parent.border = true;
|
|
text->parent.background = true;
|
|
text->parent.font_size = PGPL_GUI_FONT_SIZE_TITLE;
|
|
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;
|
|
}
|
|
|
|
int main(void) {
|
|
PGPL_Gui *gui;
|
|
PGPL_GuiTheme theme;
|
|
PGPL_Font *font;
|
|
struct AppData app;
|
|
|
|
pgpl_init();
|
|
|
|
srand(time(NULL));
|
|
|
|
strcpy(app.buffer, "0");
|
|
|
|
font = pgpl_font_create_from_file("../roboto.ttf", 256);
|
|
|
|
pgpl_gui_theme_configure(&theme, pgpl_color_create(0, 128, 255, 255), 32,
|
|
font);
|
|
|
|
gui = pgpl_gui_create("PGPL Test", 480, 320, 0, 0, &theme, &app);
|
|
|
|
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);
|
|
|
|
pgpl_gui_run_and_show(gui, true);
|
|
|
|
pgpl_font_destroy(NULL, font);
|
|
|
|
pgpl_deinit();
|
|
|
|
return 0;
|
|
}
|