diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-08-06 08:45:44 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-08-06 09:02:17 (EDT) |
commit | 331420a4c787f21864abb836fe2d6bcbc6bda816 (patch) | |
tree | 14c15a1f39e4daa4694e82986ea496da5a292f14 /src/tk | |
parent | 6cdb2c0a1e1e6c965e662bbf24710e387d1f8d52 (diff) | |
download | mazefight-331420a4c787f21864abb836fe2d6bcbc6bda816.zip mazefight-331420a4c787f21864abb836fe2d6bcbc6bda816.tar.gz mazefight-331420a4c787f21864abb836fe2d6bcbc6bda816.tar.bz2 |
tk: Implement focus switching
Diffstat (limited to 'src/tk')
-rw-r--r-- | src/tk/text.c | 10 | ||||
-rw-r--r-- | src/tk/window.c | 25 |
2 files changed, 32 insertions, 3 deletions
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 |