Initial commit
This commit is contained in:
commit
56f7cd1875
105 changed files with 22109 additions and 0 deletions
91
tests/program.c
Normal file
91
tests/program.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#include <pgpl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
struct AppData {
|
||||
int counter;
|
||||
char counter_buffer[128];
|
||||
PGPL_Gui *gui;
|
||||
};
|
||||
|
||||
static void on_counter_button_click(void *data) {
|
||||
struct AppData *app = data;
|
||||
app->counter++;
|
||||
snprintf(app->counter_buffer, sizeof(app->counter_buffer), "%d",
|
||||
app->counter);
|
||||
|
||||
if (app->counter % 10 == 0) {
|
||||
pgpl_gui_theme_configure(
|
||||
&app->gui->theme,
|
||||
pgpl_color_create(rand() % 256, rand() % 256, rand() % 256, 255), 48,
|
||||
app->gui->theme.font);
|
||||
}
|
||||
}
|
||||
|
||||
static void configure_widget_default(PGPL_GuiWidget *widget) {
|
||||
pgpl_gui_widget_configure(widget, 0, 0, true, true, true, true,
|
||||
PGPL_GUI_FONT_SIZE_CONTENT, NULL, false, false,
|
||||
false, false);
|
||||
}
|
||||
|
||||
PGPL_GuiWidget *create_main_view(struct AppData *app) {
|
||||
PGPL_GuiContainerLayout *column_layout;
|
||||
PGPL_GuiButtonWidget *counter_button;
|
||||
PGPL_GuiTextWidget *counter;
|
||||
|
||||
column_layout = pgpl_gui_container_layout_create(
|
||||
PGPL_GUI_CONTAINER_LAYOUT_DIRECTION_VERTICAL);
|
||||
pgpl_gui_widget_configure(&column_layout->parent, 0, 0, true, true, false,
|
||||
false, PGPL_GUI_FONT_SIZE_CONTENT, NULL, false,
|
||||
true, true, false);
|
||||
|
||||
counter_button =
|
||||
pgpl_gui_button_widget_create("Click me!", on_counter_button_click);
|
||||
configure_widget_default(&counter_button->parent);
|
||||
|
||||
counter = pgpl_gui_text_widget_create(app->counter_buffer);
|
||||
configure_widget_default(&counter->parent);
|
||||
counter->parent.font_size = PGPL_GUI_FONT_SIZE_TITLE;
|
||||
counter->parent.background = false;
|
||||
counter->parent.border = false;
|
||||
|
||||
pgpl_gui_container_layout_widget_add(column_layout, &counter->parent);
|
||||
pgpl_gui_container_layout_widget_add(column_layout, &counter_button->parent);
|
||||
|
||||
return (PGPL_GuiWidget *)column_layout;
|
||||
}
|
||||
|
||||
int32_t main(void) {
|
||||
PGPL_Gui *gui;
|
||||
PGPL_GuiTheme theme;
|
||||
PGPL_Font *font;
|
||||
struct AppData app;
|
||||
|
||||
pgpl_init();
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
strcpy(app.counter_buffer, "0");
|
||||
app.counter = 0;
|
||||
|
||||
font = pgpl_font_create_from_file("../roboto.ttf", 256);
|
||||
|
||||
pgpl_gui_theme_configure(&theme, pgpl_color_create(255, 255, 255, 255), 48,
|
||||
font);
|
||||
|
||||
gui = pgpl_gui_create("PGPL Test", 320, 320, 0, 0, &theme, &app);
|
||||
|
||||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue