From 331420a4c787f21864abb836fe2d6bcbc6bda816 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 06 Aug 2021 08:45:44 -0400 Subject: tk: Implement focus switching --- (limited to 'src/tk') diff --git a/src/tk/text.c b/src/tk/text.c index 6bac6e7..052beeb 100644 --- a/src/tk/text.c +++ b/src/tk/text.c @@ -139,8 +139,6 @@ _mftk_text_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y) t->color->r, t->color->g, t->color->b, t->color->a) < 0 || SDL_RenderDrawLine(renderer, - x + cur_x, y + t->y, x + cur_x, y + t->h) < 0 || - SDL_RenderDrawLine(renderer, x, y + w->h, x + w->w, y + w->h) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't render widget: %s", @@ -148,6 +146,14 @@ _mftk_text_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y) free(val); return -1; } + if (w->focused == SDL_TRUE && SDL_RenderDrawLine(renderer, + x + cur_x, y + t->y, x + cur_x, y + t->h) < 0) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "Couldn't render widget: %s", + SDL_GetError()); + free(val); + return -1; + } free(val); return 0; diff --git a/src/tk/window.c b/src/tk/window.c index b87e7c0..61c017f 100644 --- a/src/tk/window.c +++ b/src/tk/window.c @@ -48,6 +48,7 @@ mftk_window_new(struct mftk_widget *root) mftk_widget_layout(w->root); mftk_widget_index(w->root, w); w->focus = w->first; + w->focus->focused = SDL_TRUE; return w; } @@ -74,7 +75,29 @@ mftk_window_index(struct mftk_window *win, struct mftk_widget *wid) int mftk_window_event(struct mftk_window *w, SDL_Event *e) { - return mftk_widget_event(w->root, e, 0, 0); + switch (e->type) { + case SDL_KEYDOWN: + switch (e->key.keysym.sym) { + case SDLK_TAB: + w->focus->focused = SDL_FALSE; + if (e->key.keysym.mod & KMOD_SHIFT) { + w->focus = w->focus->prev; + } else { + w->focus = w->focus->next; + } + w->focus->focused = SDL_TRUE; + break; + default: + break; + } + break; + case SDL_MOUSEBUTTONUP: + return mftk_widget_event(w->root, e, 0, 0); + default: + break; + } + + return 0; } int -- cgit v0.9.1