summaryrefslogtreecommitdiff
path: root/src/ui/labelwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/labelwidget.c')
-rw-r--r--src/ui/labelwidget.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c
index c3c5fbe5..9c8fb2ee 100644
--- a/src/ui/labelwidget.c
+++ b/src/ui/labelwidget.c
@@ -126,6 +126,11 @@ static iBool processEvent_LabelWidget_(iLabelWidget *d, const SDL_Event *ev) {
126 updateKey_LabelWidget_(d); 126 updateKey_LabelWidget_(d);
127 return iFalse; 127 return iFalse;
128 } 128 }
129 else if (isCommand_Widget(w, ev, "focus.gained") ||
130 isCommand_Widget(w, ev, "focus.lost")) {
131 refresh_Widget(d);
132 return iFalse;
133 }
129 if (!isEmpty_String(&d->command)) { 134 if (!isEmpty_String(&d->command)) {
130#if 0 && defined (iPlatformAppleMobile) 135#if 0 && defined (iPlatformAppleMobile)
131 /* Touch allows activating any button on release. */ 136 /* Touch allows activating any button on release. */
@@ -161,10 +166,17 @@ static iBool processEvent_LabelWidget_(iLabelWidget *d, const SDL_Event *ev) {
161 switch (ev->type) { 166 switch (ev->type) {
162 case SDL_KEYDOWN: { 167 case SDL_KEYDOWN: {
163 const int mods = ev->key.keysym.mod; 168 const int mods = ev->key.keysym.mod;
164 if (d->key && ev->key.keysym.sym == d->key && checkModifiers_(mods, d->kmods)) { 169 const int sym = ev->key.keysym.sym;
170 if (d->key && sym == d->key && checkModifiers_(mods, d->kmods)) {
165 trigger_LabelWidget_(d); 171 trigger_LabelWidget_(d);
166 return iTrue; 172 return iTrue;
167 } 173 }
174 if (isFocused_Widget(d) && mods == 0 &&
175 (sym == SDLK_SPACE || sym == SDLK_RETURN || sym == SDLK_KP_ENTER)) {
176 trigger_LabelWidget_(d);
177 refresh_Widget(d);
178 return iTrue;
179 }
168 break; 180 break;
169 } 181 }
170 } 182 }
@@ -179,6 +191,7 @@ static void keyStr_LabelWidget_(const iLabelWidget *d, iString *str) {
179static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int *frame1, int *frame2) { 191static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int *frame1, int *frame2) {
180 const iWidget *w = constAs_Widget(d); 192 const iWidget *w = constAs_Widget(d);
181 const int64_t flags = flags_Widget(w); 193 const int64_t flags = flags_Widget(w);
194 const iBool isFocus = (flags & focusable_WidgetFlag && isFocused_Widget(d));
182 const iBool isPress = (flags & pressed_WidgetFlag) != 0; 195 const iBool isPress = (flags & pressed_WidgetFlag) != 0;
183 const iBool isSel = (flags & selected_WidgetFlag) != 0; 196 const iBool isSel = (flags & selected_WidgetFlag) != 0;
184 const iBool isFrameless = (flags & frameless_WidgetFlag) != 0; 197 const iBool isFrameless = (flags & frameless_WidgetFlag) != 0;
@@ -212,6 +225,9 @@ static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int
212 } 225 }
213 } 226 }
214 } 227 }
228 if (isFocus) {
229 *frame1 = *frame2 = uiInputFrameFocused_ColorId;
230 }
215 int colorEscape = none_ColorId; 231 int colorEscape = none_ColorId;
216 if (startsWith_String(&d->label, "\v")) { 232 if (startsWith_String(&d->label, "\v")) {
217 colorEscape = cstr_String(&d->label)[1] - asciiBase_ColorEscape; /* TODO: can be two bytes long */ 233 colorEscape = cstr_String(&d->label)[1] - asciiBase_ColorEscape; /* TODO: can be two bytes long */
@@ -295,7 +311,11 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
295 if (bg >= 0) { 311 if (bg >= 0) {
296 fillRect_Paint(&p, rect, isCaution && isHover ? uiMarked_ColorId : bg); 312 fillRect_Paint(&p, rect, isCaution && isHover ? uiMarked_ColorId : bg);
297 } 313 }
298 if (~flags & frameless_WidgetFlag) { 314 if (isFocused_Widget(w)) {
315 iRect frameRect = adjusted_Rect(rect, zero_I2(), init1_I2(-1));
316 drawRectThickness_Paint(&p, frameRect, gap_UI / 4, frame);
317 }
318 else if (~flags & frameless_WidgetFlag) {
299 iRect frameRect = adjusted_Rect(rect, zero_I2(), init1_I2(-1)); 319 iRect frameRect = adjusted_Rect(rect, zero_I2(), init1_I2(-1));
300 if (isButton) { 320 if (isButton) {
301 iInt2 points[] = { 321 iInt2 points[] = {
@@ -312,8 +332,10 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
312 } 332 }
313#endif 333#endif
314 drawLines_Paint(&p, points + 2, 3, frame2); 334 drawLines_Paint(&p, points + 2, 3, frame2);
315 drawLines_Paint( 335 drawLines_Paint(&p,
316 &p, points, !isHover && d->flags.noTopFrame ? 2 : 3, frame); 336 points,
337 isFocused_Widget(w) ? 3 : (!isHover && d->flags.noTopFrame ? 2 : 3),
338 frame);
317 } 339 }
318 } 340 }
319 setClip_Paint(&p, rect); 341 setClip_Paint(&p, rect);
@@ -473,7 +495,7 @@ void init_LabelWidget(iLabelWidget *d, const char *label, const char *cmd) {
473 d->key = 0; 495 d->key = 0;
474 d->kmods = 0; 496 d->kmods = 0;
475 init_Click(&d->click, d, !isEmpty_String(&d->command) ? SDL_BUTTON_LEFT : 0); 497 init_Click(&d->click, d, !isEmpty_String(&d->command) ? SDL_BUTTON_LEFT : 0);
476 setFlags_Widget(w, hover_WidgetFlag, d->click.button != 0); 498 setFlags_Widget(w, focusable_WidgetFlag | hover_WidgetFlag, d->click.button != 0);
477 updateSize_LabelWidget(d); 499 updateSize_LabelWidget(d);
478 updateKey_LabelWidget_(d); /* could be bound to another key */ 500 updateKey_LabelWidget_(d); /* could be bound to another key */
479} 501}