#include "saffron_api.h" #include "saffron_layout.h" #include #include #include #include #include /* PLEASE don't do this in production! * when wrappers are implemented, * THEY will make draw functions for you * THIS IS A BAD IDEA */ void my_test_draw(SaffronWidget* self, SDL_Renderer* renderer) { SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); SDL_FRect rect = {self->x, self->y, self->w, self->h}; SDL_RenderFillRect(renderer, &rect); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_RenderRect(renderer, &rect); } /* YET AGAIN DONT DO THIS IN PROD PLEASE * this is very lunatic */ void my_test_onclick(SaffronWidget* self) { printf("clicked!\n"); } int main(void) { saffron_init(); SaffronWindow* window = saffron_window_new("Saffron Test", 800, 600); /* replace the root with our own, because we want horizontal */ saffron_widget_free(window->root); window->root = (SaffronWidget*)saffron_box_new(SAFFRON_ORIENTATION_HORIZONTAL, SAFFRON_HALIGN_LEFT, SAFFRON_VALIGN_TOP, 5, 5, 0, window->w, window->h); /* i guess IM THE LUNATIC NOW * DEAL WITH IT */ SaffronWidget* test = saffron_widget_new(); /* we don't need to set X and Y, the window will layout them automatically */ test->w = 200; test->h = 150; test->draw = my_test_draw; test->on_click = my_test_onclick; /* make a vertical box */ SaffronWidget* box = (SaffronWidget*)saffron_box_new(SAFFRON_ORIENTATION_VERTICAL, SAFFRON_HALIGN_LEFT, SAFFRON_VALIGN_TOP, 5, 0, 0, 200, 150); /* lunatic method 2 */ SaffronWidget* test2 = saffron_widget_new(); test2->w = 200; test2->h = 72; test2->draw = my_test_draw; SDL_Color color = {255, 255, 255, 255}; TTF_Font* font = TTF_OpenFont("/usr/share/fonts/fantasque-sans-mono/FantasqueSansMono-Regular.otf", 24); SaffronText* test3 = saffron_text_new("Mangoes", font, color); /* become lunatic, add custom clickhandler to.. text????????????? */ ((SaffronWidget*)test3)->on_click = my_test_onclick; saffron_widget_add_child(window->root, test); saffron_widget_add_child(window->root, box); saffron_widget_add_child(box, test2); saffron_widget_add_child(box, (SaffronWidget*)test3); saffron_window_main(window); saffron_window_free(window); TTF_CloseFont(font); saffron_quit(); return 0; }