From 01a0324e79d9ced75a37a242c44676eac89b9d9d Mon Sep 17 00:00:00 2001 From: Allanis <allanis@saracraft.net> Date: Wed, 6 Mar 2013 20:49:18 +0000 Subject: [PATCH] [Add] You can no longer focus unfocusable widgets. --- src/toolkit.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/toolkit.c b/src/toolkit.c index bb10bb8..8279209 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -90,6 +90,7 @@ static void toolkit_mouseEvent(SDL_Event* event); static int toolkit_keyEvent(SDL_Event* event); // Focus. static void toolkit_nextFocus(void); +static int toolkit_isFocusable(Widget* wgt); static void toolkit_triggerFocus(void); static Widget* toolkit_getFocus(void); static void toolkit_listScroll(Widget* wgt, int direction); @@ -791,7 +792,9 @@ static void toolkit_mouseEvent(SDL_Event* event) { break; case SDL_MOUSEBUTTONDOWN: wgt->status = WIDGET_STATUS_MOUSEDOWN; - w->focus = i; + + if(toolkit_isFocusable(wgt)) + w->focus = i; if(wgt->type == WIDGET_LIST) toolkit_listFocus(wgt, x-wgt->x, y-wgt->y); @@ -899,13 +902,24 @@ static void toolkit_nextFocus(void) { else if(wdw->focus >= wdw->nwidgets) wdw->focus = -1; else if((++wdw->focus+1) && // Just increment. - ((wdw->widgets[wdw->focus].type == WIDGET_BUTTON) || - (wdw->widgets[wdw->focus].type == WIDGET_LIST))) + toolkit_isFocusable(&wdw->widgets[wdw->focus])) return; else toolkit_nextFocus(); } +static int toolkit_isFocusable(Widget* wgt) { + if(wgt == NULL) return 0; + + switch(wgt->type) { + case WIDGET_BUTTON: + case WIDGET_LIST: + return 1; + default: + return 0; + } +} + static void toolkit_triggerFocus(void) { Window* wdw; Widget* wgt;