aboutsummaryrefslogtreecommitdiff
path: root/src/saffron_button.c
blob: bef00188601dc6e6e3431f27bd39e17e21187b0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <SDL3/SDL.h>
#include <stdlib.h>
#include <saffron.h>

static void saffron_button_draw(SaffronWidget* widget, SDL_Renderer* renderer) {
	SaffronButton* btn = (SaffronButton*)widget;

	SaffronTheme* theme = widget->theme;
	if (!theme) return;
	SaffronColor secondary = theme->secondary;
	SaffronColor tertiary = theme->tertiary;
	SDL_SetRenderDrawColor(renderer, secondary.r, secondary.g, secondary.b, secondary.a);
	SDL_FRect rect = {widget->x, widget->y, widget->w, widget->h};
	SDL_RenderFillRect(renderer, &rect);

	SDL_SetRenderDrawColor(renderer, tertiary.r, tertiary.g, tertiary.b, tertiary.a);
	SDL_RenderRect(renderer, &rect);
}

SaffronButton* saffron_button_new(bool enabled, void (*callback)(SaffronButton* self), int width, int height) {
	SaffronButton* button = malloc(sizeof(SaffronButton));
	saffron_widget_init((SaffronWidget*)button);

	((SaffronWidget*)button)->type = SAFFRON_WIDGET_BUTTON;
	((SaffronWidget*)button)->draw = saffron_button_draw;

	button->callback = callback;
	button->enabled = enabled;
	button->base = *saffron_box_new(SAFFRON_ORIENTATION_HORIZONTAL, SAFFRON_HALIGN_CENTER, SAFFRON_VALIGN_CENTER, 5, 5, 0, width, height);

	return button;
}