slider widget, tons of fixes and improvements for win32, reworked font loading.
This commit is contained in:
parent
54a0f5eb4e
commit
69f8a273f3
18 changed files with 452 additions and 90 deletions
|
|
@ -1,60 +1,48 @@
|
|||
#include <pgpl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
struct AppData {
|
||||
int counter;
|
||||
char counter_buffer[128];
|
||||
PGPL_Gui *gui;
|
||||
char buffer[128];
|
||||
};
|
||||
|
||||
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 slide_callback(void *data, double value) {
|
||||
struct AppData *app_data = data;
|
||||
snprintf(app_data->buffer, 127, "%d", (int)(value * 100));
|
||||
}
|
||||
|
||||
static void configure_widget_default(PGPL_GuiWidget *widget) {
|
||||
pgpl_gui_widget_configure(widget, 0, 0, true, true, true, true,
|
||||
pgpl_gui_widget_configure(widget, 0, 0, true, true, false, false,
|
||||
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;
|
||||
PGPL_GuiContainerLayout *layout;
|
||||
PGPL_GuiSliderWidget *slider;
|
||||
PGPL_GuiTextWidget *text;
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
counter_button =
|
||||
pgpl_gui_button_widget_create("Click me!", on_counter_button_click);
|
||||
configure_widget_default(&counter_button->parent);
|
||||
slider = pgpl_gui_slider_widget_create(16, true, true, 0.0, slide_callback);
|
||||
configure_widget_default(&slider->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;
|
||||
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(column_layout, &counter->parent);
|
||||
pgpl_gui_container_layout_widget_add(column_layout, &counter_button->parent);
|
||||
pgpl_gui_container_layout_widget_add(layout, &text->parent);
|
||||
pgpl_gui_container_layout_widget_add(layout, &slider->parent);
|
||||
|
||||
return (PGPL_GuiWidget *)column_layout;
|
||||
return (PGPL_GuiWidget *)layout;
|
||||
}
|
||||
|
||||
int32_t main(void) {
|
||||
|
|
@ -67,15 +55,14 @@ int32_t main(void) {
|
|||
|
||||
srand(time(NULL));
|
||||
|
||||
strcpy(app.counter_buffer, "0");
|
||||
app.counter = 0;
|
||||
strcpy(app.buffer, "0");
|
||||
|
||||
font = pgpl_font_create_from_file("../roboto.ttf", 256);
|
||||
font = pgpl_font_create_from_file("../roboto.ttf", 128);
|
||||
|
||||
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);
|
||||
gui = pgpl_gui_create("PGPL Test", 480, 240, 0, 0, &theme, &app);
|
||||
|
||||
app.gui = gui;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue