fixes more or less
This commit is contained in:
parent
a315d72a57
commit
74c5f7a004
7 changed files with 67 additions and 63 deletions
|
|
@ -28,9 +28,10 @@ typedef enum PGPL_GuiStatusColor {
|
||||||
/* This controls what font size from the theme should be used. There are three
|
/* This controls what font size from the theme should be used. There are three
|
||||||
* different types. */
|
* different types. */
|
||||||
typedef enum PGPL_GuiFontSize {
|
typedef enum PGPL_GuiFontSize {
|
||||||
PGPL_GUI_FONT_SIZE_TITLE,
|
PGPL_GUI_FONT_SIZE_CONTENT,
|
||||||
PGPL_GUI_FONT_SIZE_HEADING,
|
PGPL_GUI_FONT_SIZE_HEADING_SMALL,
|
||||||
PGPL_GUI_FONT_SIZE_CONTENT
|
PGPL_GUI_FONT_SIZE_HEADING_LARGE,
|
||||||
|
PGPL_GUI_FONT_SIZE_TITLE
|
||||||
} PGPL_GuiFontSize;
|
} PGPL_GuiFontSize;
|
||||||
|
|
||||||
/* This is the struct for the themes. This controls the colors, font sizes, font
|
/* This is the struct for the themes. This controls the colors, font sizes, font
|
||||||
|
|
@ -54,7 +55,7 @@ typedef struct PGPL_GuiTheme {
|
||||||
PGPL_Rectangle padding;
|
PGPL_Rectangle padding;
|
||||||
/* Controls the font size of the widgets, this is an array of three so that it
|
/* Controls the font size of the widgets, this is an array of three so that it
|
||||||
* can support all values from PGPL_GuiFontSize. */
|
* can support all values from PGPL_GuiFontSize. */
|
||||||
double font_size[3];
|
double font_size[4];
|
||||||
/* The font of the theme. */
|
/* The font of the theme. */
|
||||||
PGPL_Font *font;
|
PGPL_Font *font;
|
||||||
} PGPL_GuiTheme;
|
} PGPL_GuiTheme;
|
||||||
|
|
|
||||||
|
|
@ -91,11 +91,9 @@ void pgpl_gui_empty_widget_destroy(PGPL_GuiWidget *empty_widget);
|
||||||
|
|
||||||
/* This is the struct for a slider widget. The inversed option inverses its
|
/* This is the struct for a slider widget. The inversed option inverses its
|
||||||
* slide direction, vertical determines if it's vertical or horizontal. The
|
* slide direction, vertical determines if it's vertical or horizontal. The
|
||||||
* bar_height is the height of the slider bar. The slide_callback gets called
|
* slide_callback gets called whenever there is sliding activity. */
|
||||||
* whenever there is sliding activity. */
|
|
||||||
typedef struct PGPL_GuiSliderWidget {
|
typedef struct PGPL_GuiSliderWidget {
|
||||||
PGPL_GuiWidget parent;
|
PGPL_GuiWidget parent;
|
||||||
uint32_t bar_height;
|
|
||||||
bool inversed;
|
bool inversed;
|
||||||
bool vertical;
|
bool vertical;
|
||||||
double current_value;
|
double current_value;
|
||||||
|
|
@ -107,7 +105,7 @@ typedef struct PGPL_GuiSliderWidget {
|
||||||
|
|
||||||
/* This creates a new slider with the given properties. */
|
/* This creates a new slider with the given properties. */
|
||||||
PGPL_GuiSliderWidget *pgpl_gui_slider_widget_create(
|
PGPL_GuiSliderWidget *pgpl_gui_slider_widget_create(
|
||||||
uint32_t bar_height, bool inversed, bool vertical, double value,
|
bool inversed, bool vertical, double value,
|
||||||
void (*slide_callback)(void *app_data, double value));
|
void (*slide_callback)(void *app_data, double value));
|
||||||
|
|
||||||
/* This destorys a slider widget. */
|
/* This destorys a slider widget. */
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,9 @@ static inline uint8_t pgpl_color_get_alpha(PGPL_Color color) {
|
||||||
|
|
||||||
/* Divides all color values by the given amount. */
|
/* Divides all color values by the given amount. */
|
||||||
static inline PGPL_Color pgpl_color_divide(PGPL_Color color, double divisor) {
|
static inline PGPL_Color pgpl_color_divide(PGPL_Color color, double divisor) {
|
||||||
return pgpl_color_create(pgpl_color_get_red(color) / divisor,
|
return pgpl_color_create((uint8_t)(pgpl_color_get_red(color) / divisor),
|
||||||
pgpl_color_get_green(color) / divisor,
|
(uint8_t)(pgpl_color_get_green(color) / divisor),
|
||||||
pgpl_color_get_blue(color) / divisor,
|
(uint8_t)(pgpl_color_get_blue(color) / divisor),
|
||||||
pgpl_color_get_alpha(color));
|
pgpl_color_get_alpha(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,29 +4,35 @@ void pgpl_gui_theme_configure(PGPL_GuiTheme *theme, PGPL_Color base_color,
|
||||||
double content_font_size, PGPL_Font *font) {
|
double content_font_size, PGPL_Font *font) {
|
||||||
theme->background_color = pgpl_color_divide(base_color, 8);
|
theme->background_color = pgpl_color_divide(base_color, 8);
|
||||||
|
|
||||||
theme->widget_background_color[0] = pgpl_color_divide(base_color, 5);
|
theme->widget_background_color[PGPL_GUI_STATUS_COLOR_NORMAL] =
|
||||||
theme->widget_background_color[1] = pgpl_color_divide(base_color, 4);
|
pgpl_color_divide(base_color, 5);
|
||||||
theme->widget_background_color[2] = pgpl_color_divide(base_color, 3);
|
theme->widget_background_color[PGPL_GUI_STATUS_COLOR_HOVER] =
|
||||||
|
pgpl_color_divide(base_color, 4);
|
||||||
|
theme->widget_background_color[PGPL_GUI_STATUS_COLOR_ACTIVE] =
|
||||||
|
pgpl_color_divide(base_color, 3);
|
||||||
|
|
||||||
theme->text_color[0] = pgpl_color_divide(base_color, 1.5);
|
theme->text_color[PGPL_GUI_STATUS_COLOR_NORMAL] =
|
||||||
theme->text_color[1] = pgpl_color_divide(base_color, 1.25);
|
pgpl_color_divide(base_color, 1.5);
|
||||||
theme->text_color[2] = base_color;
|
theme->text_color[PGPL_GUI_STATUS_COLOR_HOVER] =
|
||||||
|
pgpl_color_divide(base_color, 1.25);
|
||||||
|
theme->text_color[PGPL_GUI_STATUS_COLOR_ACTIVE] = base_color;
|
||||||
|
|
||||||
theme->font_size[0] = content_font_size * 3;
|
theme->font_size[PGPL_GUI_FONT_SIZE_TITLE] = content_font_size * 4;
|
||||||
theme->font_size[1] = content_font_size * 2;
|
theme->font_size[PGPL_GUI_FONT_SIZE_HEADING_LARGE] = content_font_size * 3;
|
||||||
theme->font_size[2] = content_font_size;
|
theme->font_size[PGPL_GUI_FONT_SIZE_HEADING_SMALL] = content_font_size * 2;
|
||||||
|
theme->font_size[PGPL_GUI_FONT_SIZE_CONTENT] = content_font_size;
|
||||||
|
|
||||||
theme->margin.top = content_font_size / 6;
|
theme->margin.top = content_font_size / 3;
|
||||||
theme->margin.left = theme->margin.top;
|
theme->margin.left = theme->margin.top;
|
||||||
theme->margin.bottom = theme->margin.top;
|
theme->margin.bottom = theme->margin.top;
|
||||||
theme->margin.right = theme->margin.top;
|
theme->margin.right = theme->margin.top;
|
||||||
|
|
||||||
theme->border.top = content_font_size / 12;
|
theme->border.top = content_font_size / 6;
|
||||||
theme->border.left = theme->border.top;
|
theme->border.left = theme->border.top;
|
||||||
theme->border.bottom = theme->border.top;
|
theme->border.bottom = theme->border.top;
|
||||||
theme->border.right = theme->border.top;
|
theme->border.right = theme->border.top;
|
||||||
|
|
||||||
theme->padding.top = content_font_size / 6;
|
theme->padding.top = content_font_size / 3;
|
||||||
theme->padding.left = theme->padding.top;
|
theme->padding.left = theme->padding.top;
|
||||||
theme->padding.bottom = theme->padding.top;
|
theme->padding.bottom = theme->padding.top;
|
||||||
theme->padding.right = theme->padding.top;
|
theme->padding.right = theme->padding.top;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static void get_slider_size(PGPL_GuiSliderWidget *slider_widget,
|
static void get_slider_size(PGPL_GuiSliderWidget *slider_widget,
|
||||||
double *slider_x, double *slider_y, double x,
|
PGPL_GuiTheme *theme, double *slider_x,
|
||||||
double y, double max_width, double max_height) {
|
double *slider_y, double x, double y,
|
||||||
|
double max_width, double max_height) {
|
||||||
double offset;
|
double offset;
|
||||||
|
double bar_height = theme->font_size[PGPL_GUI_FONT_SIZE_CONTENT] / 2;
|
||||||
|
|
||||||
if (slider_widget->inversed) {
|
if (slider_widget->inversed) {
|
||||||
offset = 1.0 - slider_widget->current_value;
|
offset = 1.0 - slider_widget->current_value;
|
||||||
|
|
@ -13,13 +15,11 @@ static void get_slider_size(PGPL_GuiSliderWidget *slider_widget,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slider_widget->vertical) {
|
if (slider_widget->vertical) {
|
||||||
*slider_x = x - slider_widget->bar_height / 2.0;
|
*slider_x = x - bar_height / 2.0;
|
||||||
*slider_y = y + offset * (max_height - slider_widget->bar_height) -
|
*slider_y = y + offset * (max_height - bar_height) - bar_height / 2.0;
|
||||||
slider_widget->bar_height / 2.0;
|
|
||||||
} else {
|
} else {
|
||||||
*slider_x = x + offset * (max_width - slider_widget->bar_height) -
|
*slider_x = x + offset * (max_width - bar_height) - bar_height / 2.0;
|
||||||
slider_widget->bar_height / 2.0;
|
*slider_y = y - bar_height / 2.0;
|
||||||
*slider_y = y - slider_widget->bar_height / 2.0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,15 +27,16 @@ static void get_content_size(PGPL_GuiWidget *widget, PGPL_GuiTheme *theme,
|
||||||
double *width, double *height, double max_width,
|
double *width, double *height, double max_width,
|
||||||
double max_height) {
|
double max_height) {
|
||||||
PGPL_GuiSliderWidget *slider_widget = (PGPL_GuiSliderWidget *)widget;
|
PGPL_GuiSliderWidget *slider_widget = (PGPL_GuiSliderWidget *)widget;
|
||||||
|
double bar_height = theme->font_size[PGPL_GUI_FONT_SIZE_CONTENT] / 2;
|
||||||
|
|
||||||
(void)theme;
|
(void)theme;
|
||||||
|
|
||||||
if (slider_widget->vertical) {
|
if (slider_widget->vertical) {
|
||||||
*width = slider_widget->bar_height;
|
*width = bar_height;
|
||||||
*height = max_height;
|
*height = max_height;
|
||||||
} else {
|
} else {
|
||||||
*width = max_width;
|
*width = max_width;
|
||||||
*height = slider_widget->bar_height;
|
*height = bar_height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,6 +44,7 @@ static void render_content(PGPL_GuiWidget *widget, PGPL_Renderer *renderer,
|
||||||
PGPL_GuiTheme *theme, double x, double y,
|
PGPL_GuiTheme *theme, double x, double y,
|
||||||
double max_width, double max_height) {
|
double max_width, double max_height) {
|
||||||
PGPL_GuiSliderWidget *slider_widget = (PGPL_GuiSliderWidget *)widget;
|
PGPL_GuiSliderWidget *slider_widget = (PGPL_GuiSliderWidget *)widget;
|
||||||
|
double bar_height = theme->font_size[PGPL_GUI_FONT_SIZE_CONTENT] / 2;
|
||||||
|
|
||||||
double slider_x;
|
double slider_x;
|
||||||
double slider_y;
|
double slider_y;
|
||||||
|
|
@ -52,44 +54,42 @@ static void render_content(PGPL_GuiWidget *widget, PGPL_Renderer *renderer,
|
||||||
double completion_width;
|
double completion_width;
|
||||||
double completion_height;
|
double completion_height;
|
||||||
|
|
||||||
get_slider_size(slider_widget, &slider_x, &slider_y, x, y, max_width,
|
get_slider_size(slider_widget, theme, &slider_x, &slider_y, x, y, max_width,
|
||||||
max_height);
|
max_height);
|
||||||
|
|
||||||
if (slider_widget->vertical) {
|
if (slider_widget->vertical) {
|
||||||
max_width = slider_widget->bar_height;
|
max_width = bar_height;
|
||||||
} else {
|
} else {
|
||||||
max_height = slider_widget->bar_height;
|
max_height = bar_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
pgpl_render_rectangle(renderer, theme->text_color[widget->gui_color], x, y,
|
pgpl_render_rectangle(renderer, theme->text_color[widget->gui_color], x, y,
|
||||||
max_width, max_height);
|
max_width, max_height);
|
||||||
|
|
||||||
pgpl_render_rectangle(renderer, theme->background_color,
|
pgpl_render_rectangle(renderer, theme->background_color, x + bar_height / 4.0,
|
||||||
x + slider_widget->bar_height / 4.0,
|
y + bar_height / 4.0, max_width - bar_height / 2.0,
|
||||||
y + slider_widget->bar_height / 4.0,
|
max_height - bar_height / 2.0);
|
||||||
max_width - slider_widget->bar_height / 2.0,
|
|
||||||
max_height - slider_widget->bar_height / 2.0);
|
|
||||||
|
|
||||||
max_width -= slider_widget->bar_height / 2.0;
|
max_width -= bar_height / 2.0;
|
||||||
max_height -= slider_widget->bar_height / 2.0;
|
max_height -= bar_height / 2.0;
|
||||||
|
|
||||||
if (slider_widget->inversed) {
|
if (slider_widget->inversed) {
|
||||||
if (slider_widget->vertical) {
|
if (slider_widget->vertical) {
|
||||||
completion_x = x + slider_widget->bar_height / 4.0;
|
completion_x = x + bar_height / 4.0;
|
||||||
completion_y = y + slider_widget->bar_height / 4.0 +
|
completion_y = y + bar_height / 4.0 +
|
||||||
max_height * (1.0 - slider_widget->current_value);
|
max_height * (1.0 - slider_widget->current_value);
|
||||||
completion_width = max_width;
|
completion_width = max_width;
|
||||||
completion_height = max_height * slider_widget->current_value;
|
completion_height = max_height * slider_widget->current_value;
|
||||||
} else {
|
} else {
|
||||||
completion_x = x + slider_widget->bar_height / 4.0 +
|
completion_x = x + bar_height / 4.0 +
|
||||||
max_width * (1.0 - slider_widget->current_value);
|
max_width * (1.0 - slider_widget->current_value);
|
||||||
completion_y = y + slider_widget->bar_height / 4.0;
|
completion_y = y + bar_height / 4.0;
|
||||||
completion_width = max_width * slider_widget->current_value;
|
completion_width = max_width * slider_widget->current_value;
|
||||||
completion_height = max_height;
|
completion_height = max_height;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
completion_x = x + slider_widget->bar_height / 4.0;
|
completion_x = x + bar_height / 4.0;
|
||||||
completion_y = y + slider_widget->bar_height / 4.0;
|
completion_y = y + bar_height / 4.0;
|
||||||
|
|
||||||
if (slider_widget->vertical) {
|
if (slider_widget->vertical) {
|
||||||
completion_width = max_width;
|
completion_width = max_width;
|
||||||
|
|
@ -105,7 +105,7 @@ static void render_content(PGPL_GuiWidget *widget, PGPL_Renderer *renderer,
|
||||||
completion_y, completion_width, completion_height);
|
completion_y, completion_width, completion_height);
|
||||||
|
|
||||||
pgpl_render_circle(renderer, theme->text_color[widget->gui_color], slider_x,
|
pgpl_render_circle(renderer, theme->text_color[widget->gui_color], slider_x,
|
||||||
slider_y, slider_widget->bar_height, 32);
|
slider_y, bar_height, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event(PGPL_GuiWidget *widget, PGPL_GuiTheme *theme, PGPL_Gui *gui,
|
static void event(PGPL_GuiWidget *widget, PGPL_GuiTheme *theme, PGPL_Gui *gui,
|
||||||
|
|
@ -116,20 +116,20 @@ static void event(PGPL_GuiWidget *widget, PGPL_GuiTheme *theme, PGPL_Gui *gui,
|
||||||
event_type == PGPL_WINDOW_EVENT_MOUSE_RELEASE ||
|
event_type == PGPL_WINDOW_EVENT_MOUSE_RELEASE ||
|
||||||
event_type == PGPL_WINDOW_EVENT_MOUSE_MOVE) {
|
event_type == PGPL_WINDOW_EVENT_MOUSE_MOVE) {
|
||||||
PGPL_GuiSliderWidget *slider_widget = (PGPL_GuiSliderWidget *)widget;
|
PGPL_GuiSliderWidget *slider_widget = (PGPL_GuiSliderWidget *)widget;
|
||||||
|
double bar_height = theme->font_size[PGPL_GUI_FONT_SIZE_CONTENT] / 2;
|
||||||
double slider_x;
|
double slider_x;
|
||||||
double slider_y;
|
double slider_y;
|
||||||
|
|
||||||
pgpl_gui_widget_adjust_event_params(widget, theme, &x, &y, &max_width,
|
pgpl_gui_widget_adjust_event_params(widget, theme, &x, &y, &max_width,
|
||||||
&max_height);
|
&max_height);
|
||||||
|
|
||||||
get_slider_size(slider_widget, &slider_x, &slider_y, x, y, max_width,
|
get_slider_size(slider_widget, theme, &slider_x, &slider_y, x, y, max_width,
|
||||||
max_height);
|
max_height);
|
||||||
|
|
||||||
if (event_type == PGPL_WINDOW_EVENT_MOUSE_PRESS) {
|
if (event_type == PGPL_WINDOW_EVENT_MOUSE_PRESS) {
|
||||||
if (pgpl_gui_widget_within_area(event_data->input_event.x,
|
if (pgpl_gui_widget_within_area(
|
||||||
event_data->input_event.y, slider_x,
|
event_data->input_event.x, event_data->input_event.y, slider_x,
|
||||||
slider_y, slider_widget->bar_height * 2,
|
slider_y, bar_height * 2, bar_height * 2)) {
|
||||||
slider_widget->bar_height * 2)) {
|
|
||||||
slider_widget->sliding = true;
|
slider_widget->sliding = true;
|
||||||
if (slider_widget->vertical) {
|
if (slider_widget->vertical) {
|
||||||
slider_widget->last_pos = event_data->input_event.y;
|
slider_widget->last_pos = event_data->input_event.y;
|
||||||
|
|
@ -151,7 +151,7 @@ static void event(PGPL_GuiWidget *widget, PGPL_GuiTheme *theme, PGPL_Gui *gui,
|
||||||
axis_length = max_width;
|
axis_length = max_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
axis_length -= slider_widget->bar_height;
|
axis_length -= bar_height;
|
||||||
|
|
||||||
if (slider_widget->inversed) {
|
if (slider_widget->inversed) {
|
||||||
slider_widget->current_value -=
|
slider_widget->current_value -=
|
||||||
|
|
@ -180,7 +180,7 @@ static void destroy(PGPL_GuiWidget *widget) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PGPL_GuiSliderWidget *pgpl_gui_slider_widget_create(
|
PGPL_GuiSliderWidget *pgpl_gui_slider_widget_create(
|
||||||
uint32_t bar_height, bool inversed, bool vertical, double value,
|
bool inversed, bool vertical, double value,
|
||||||
void (*slide_callback)(void *app_data, double value)) {
|
void (*slide_callback)(void *app_data, double value)) {
|
||||||
PGPL_GuiSliderWidget *slider_widget = calloc(1, sizeof(*slider_widget));
|
PGPL_GuiSliderWidget *slider_widget = calloc(1, sizeof(*slider_widget));
|
||||||
pgpl_gui_widget_default_config(&slider_widget->parent);
|
pgpl_gui_widget_default_config(&slider_widget->parent);
|
||||||
|
|
@ -189,7 +189,6 @@ PGPL_GuiSliderWidget *pgpl_gui_slider_widget_create(
|
||||||
slider_widget->parent.render_content = render_content;
|
slider_widget->parent.render_content = render_content;
|
||||||
slider_widget->parent.event = event;
|
slider_widget->parent.event = event;
|
||||||
slider_widget->parent.destroy = destroy;
|
slider_widget->parent.destroy = destroy;
|
||||||
slider_widget->bar_height = bar_height;
|
|
||||||
slider_widget->inversed = inversed;
|
slider_widget->inversed = inversed;
|
||||||
slider_widget->vertical = vertical;
|
slider_widget->vertical = vertical;
|
||||||
slider_widget->current_value = value;
|
slider_widget->current_value = value;
|
||||||
|
|
|
||||||
|
|
@ -181,8 +181,8 @@ PGPL_Window *pgpl_window_create(const char *title, uint32_t width,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
24,
|
0,
|
||||||
8,
|
0,
|
||||||
0,
|
0,
|
||||||
PFD_MAIN_PLANE,
|
PFD_MAIN_PLANE,
|
||||||
0,
|
0,
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ PGPL_GuiWidget *create_main_view(struct AppData *app) {
|
||||||
layout->parent.ignore_margin = true;
|
layout->parent.ignore_margin = true;
|
||||||
layout->parent.ignore_border = true;
|
layout->parent.ignore_border = true;
|
||||||
|
|
||||||
slider = pgpl_gui_slider_widget_create(16, false, false, 0.0, slide_callback);
|
slider = pgpl_gui_slider_widget_create(false, false, 0.0, slide_callback);
|
||||||
slider->parent.border = true;
|
slider->parent.border = true;
|
||||||
slider->parent.background = true;
|
slider->parent.background = true;
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ PGPL_GuiWidget *create_main_view(struct AppData *app) {
|
||||||
return (PGPL_GuiWidget *)layout;
|
return (PGPL_GuiWidget *)layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t main(void) {
|
int main(void) {
|
||||||
PGPL_Gui *gui;
|
PGPL_Gui *gui;
|
||||||
PGPL_GuiTheme theme;
|
PGPL_GuiTheme theme;
|
||||||
PGPL_Font *font;
|
PGPL_Font *font;
|
||||||
|
|
@ -55,7 +55,7 @@ int32_t main(void) {
|
||||||
|
|
||||||
font = pgpl_font_create_from_file("../roboto.ttf", 256);
|
font = pgpl_font_create_from_file("../roboto.ttf", 256);
|
||||||
|
|
||||||
pgpl_gui_theme_configure(&theme, pgpl_color_create(255, 255, 255, 255), 64,
|
pgpl_gui_theme_configure(&theme, pgpl_color_create(0, 128, 255, 255), 32,
|
||||||
font);
|
font);
|
||||||
|
|
||||||
gui = pgpl_gui_create("PGPL Test", 480, 320, 0, 0, &theme, &app);
|
gui = pgpl_gui_create("PGPL Test", 480, 320, 0, 0, &theme, &app);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue