<commit_before>#include "SDL.h"
#include "../src/fgui.h"

#define WIDTH 640
#define HEIGHT 480

// Screen surface
SDL_Surface *gScreen;

struct fgui_button button;
struct fgui_button button2;
struct fgui_label label;
struct fgui_combobox combobox;

// define the "callback" that fgui uses to set pixels
void fgui_set_pixel(uint16_t x, uint16_t y, uint32_t color)
{
	SDL_Rect r;
	r.x = x;
	r.y = y;
	r.w = 1;
	r.h = 1;
	SDL_FillRect(gScreen, &r, color);
}

// test some fgui primitives
void render_stuff(void)
{
	/* draw background */
	fgui_fill_rectangle(0, 0, WIDTH, HEIGHT, 0xdddddddd);

	fgui_draw_line(0, 0, 10, 10, 0xff << 8);
	fgui_draw_rectangle(50, 100, 20, 30, 0xff);
	fgui_fill_rectangle(100, 100, 20, 30, 0xff << 8);
	fgui_draw_circle(300, 300, 100, 0xffffffff);
	fgui_fill_circle(200, 150, 20, 0xff << 16);
	fgui_draw_string("this string\nspans multiple\nlines", 200, 50, 0xff << 16);
	fgui_draw_string("hello world", 100, 200, 0xff);
	fgui_draw_string("hello world", 100, 210, 0xff << 8);
	fgui_draw_string("hello world", 100, 220, 0xff << 16);
	fgui_button_draw(&button.base);
	fgui_button_draw(&button2.base);
	fgui_widget_draw((struct fgui_widget *)&combobox);
	//(*button.base.draw)(&button);
	fgui_label_draw(&label);
	fgui_draw_triangle(50, 50, 55, 55, 60, 50, 0xff);
}

struct btn_cb_data {
	struct fgui_button *button;
	char *str;
	int *number;
};

void on_button_click(void *arg)
{
	char buf[30];
	struct btn_cb_data *data = arg;

	sprintf(buf, "clicked \n%d times", ++(*data->number));
	printf("button %p clicked\n", data->button);
	fgui_button_set_text(data->button, buf);
}

void on_combobox_change(void *userdata)
{
	printf("%s\n", __func__);
}

int main(int argc, char *argv[])
{
	int ret;
	SDL_Event event;
	struct fgui_event fgui_event;
	struct fgui_application app;
	int button_clicks = 0;
	int button2_clicks = 0;
	struct btn_cb_data btn_cb_data = {
		&button,
		"hello button userdata",
		&button_clicks,
	};

	struct btn_cb_data btn_cb_data2 = {
		&button2,
		"hello button2 userdata",
		&button2_clicks,
	};

	fgui_application_init(&app);
	fgui_button_init(&button, 100, 250, 82, 12, "hello world", NULL);
	fgui_button_init(&button2, 100, 290, 82, 12, "hello world 2", NULL);
	fgui_label_init(&label, 100, 270, "hello fgui label", NULL);
	fgui_combobox_init(&combobox, 250, 120, 60, 12, NULL);
	fgui_combobox_add_item(&combobox, "item1");
	fgui_combobox_add_item(&combobox, "item2");
	fgui_combobox_add_item(&combobox, "item3");
	fgui_combobox_set_index(&combobox, 0);
	fgui_application_add_widget(&app, &button.base);
	fgui_application_add_widget(&app, &button2.base);
	fgui_application_add_widget(&app, (struct fgui_widget *)&combobox);
	fgui_button_set_on_click_handler(&button, on_button_click, &btn_cb_data);
	fgui_button_set_on_click_handler(&button2, on_button_click, &btn_cb_data2);
	fgui_combobox_set_on_change_handler(&combobox, on_combobox_change, NULL);

	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
		exit(1);
	}

	// make sure things are cleaned up when we quit
	atexit(SDL_Quit);<commit_msg>fgui_test: test the lineedit widget<commit_after>#include "SDL.h"
#include "../src/fgui.h"

#define WIDTH 640
#define HEIGHT 480

// Screen surface
SDL_Surface *gScreen;

struct fgui_button button;
struct fgui_button button2;
struct fgui_label label;
struct fgui_combobox combobox;
struct fgui_lineedit lineedit;

// define the "callback" that fgui uses to set pixels
void fgui_set_pixel(uint16_t x, uint16_t y, uint32_t color)
{
	SDL_Rect r;
	r.x = x;
	r.y = y;
	r.w = 1;
	r.h = 1;
	SDL_FillRect(gScreen, &r, color);
}

// test some fgui primitives
void render_stuff(void)
{
	/* draw background */
	fgui_fill_rectangle(0, 0, WIDTH, HEIGHT, 0xdddddddd);

	fgui_draw_line(0, 0, 10, 10, 0xff << 8);
	fgui_draw_rectangle(50, 100, 20, 30, 0xff);
	fgui_fill_rectangle(100, 100, 20, 30, 0xff << 8);
	fgui_draw_circle(300, 300, 100, 0xffffffff);
	fgui_fill_circle(200, 150, 20, 0xff << 16);
	fgui_draw_string("this string\nspans multiple\nlines", 200, 50, 0xff << 16);
	fgui_draw_string("hello world", 100, 200, 0xff);
	fgui_draw_string("hello world", 100, 210, 0xff << 8);
	fgui_draw_string("hello world", 100, 220, 0xff << 16);
	fgui_button_draw(&button.base);
	fgui_button_draw(&button2.base);
	fgui_widget_draw((struct fgui_widget *)&combobox);
	//(*button.base.draw)(&button);
	fgui_label_draw(&label);
	fgui_widget_draw((struct fgui_widget *)&lineedit);
	fgui_draw_triangle(50, 50, 55, 55, 60, 50, 0xff);
}

struct btn_cb_data {
	struct fgui_button *button;
	char *str;
	int *number;
};

void on_button_click(void *arg)
{
	char buf[30];
	struct btn_cb_data *data = arg;

	sprintf(buf, "clicked \n%d times", ++(*data->number));
	printf("button %p clicked\n", data->button);
	fgui_button_set_text(data->button, buf);
}

void on_combobox_change(void *userdata)
{
	printf("%s\n", __func__);
}

int main(int argc, char *argv[])
{
	int ret;
	SDL_Event event;
	struct fgui_event fgui_event;
	struct fgui_application app;
	int button_clicks = 0;
	int button2_clicks = 0;
	struct btn_cb_data btn_cb_data = {
		&button,
		"hello button userdata",
		&button_clicks,
	};

	struct btn_cb_data btn_cb_data2 = {
		&button2,
		"hello button2 userdata",
		&button2_clicks,
	};

	fgui_application_init(&app);
	fgui_button_init(&button, 100, 250, 82, 12, "hello world", NULL);
	fgui_button_init(&button2, 100, 290, 82, 12, "hello world 2", NULL);
	fgui_label_init(&label, 100, 270, "hello fgui label", NULL);
	fgui_lineedit_init(&lineedit, 200, 20, 100, 15, NULL);
	fgui_combobox_init(&combobox, 250, 120, 60, 12, NULL);
	fgui_combobox_add_item(&combobox, "item1");
	fgui_combobox_add_item(&combobox, "item2");
	fgui_combobox_add_item(&combobox, "item3");
	fgui_combobox_set_index(&combobox, 0);
	fgui_application_add_widget(&app, &button.base);
	fgui_application_add_widget(&app, &button2.base);
	fgui_application_add_widget(&app, (struct fgui_widget *)&combobox);
	fgui_application_add_widget(&app, (struct fgui_widget *)&lineedit);
	fgui_button_set_on_click_handler(&button, on_button_click, &btn_cb_data);
	fgui_button_set_on_click_handler(&button2, on_button_click, &btn_cb_data2);
	fgui_combobox_set_on_change_handler(&combobox, on_combobox_change, NULL);

	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
		exit(1);
	}

	// make sure things are cleaned up when we quit
	atexit(SDL_Quit);
{'fraction_non_alphanumeric': 0.14003115264797508, 'fraction_numerical': 0.05482866043613707, 'mean_word_length': 5.994553376906318, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2594866', 'n_tokens_mistral': 2954, 'n_tokens_neox': 2569, 'n_words': 579}