summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/macos.m12
-rw-r--r--src/ui/color.c18
-rw-r--r--src/ui/color.h2
-rw-r--r--src/ui/labelwidget.c87
4 files changed, 74 insertions, 45 deletions
diff --git a/src/macos.m b/src/macos.m
index 24c83aec..53a6da00 100644
--- a/src/macos.m
+++ b/src/macos.m
@@ -529,15 +529,9 @@ enum iColorId removeColorEscapes_String(iString *d) {
529 for (;;) { 529 for (;;) {
530 const char *esc = strchr(cstr_String(d), '\v'); 530 const char *esc = strchr(cstr_String(d), '\v');
531 if (esc) { 531 if (esc) {
532 const char *ptr = esc + 1; 532 const char *endp;
533 color = 0; 533 color = parseEscape_Color(esc, &endp);
534 if (*ptr == '\v') { 534 remove_Block(&d->chars, esc - cstr_String(d), endp - esc);
535 color += asciiExtended_ColorEscape;
536 ptr++;
537 }
538 color += *ptr - asciiBase_ColorEscape;
539 ptr++;
540 remove_Block(&d->chars, esc - cstr_String(d), ptr - esc);
541 } 535 }
542 else break; 536 else break;
543 } 537 }
diff --git a/src/ui/color.c b/src/ui/color.c
index 4ecdcf76..072c4b3f 100644
--- a/src/ui/color.c
+++ b/src/ui/color.c
@@ -482,6 +482,24 @@ const char *escape_Color(int color) {
482 return format_CStr("\v%c", color + asciiBase_ColorEscape); 482 return format_CStr("\v%c", color + asciiBase_ColorEscape);
483} 483}
484 484
485enum iColorId parseEscape_Color(const char *cstr, const char **endp) {
486 enum iColorId color = none_ColorId;
487 if (*cstr == '\v') {
488 cstr++;
489 color = 0;
490 if (*cstr == '\v') {
491 color += asciiExtended_ColorEscape;
492 cstr++;
493 }
494 color += *cstr - asciiBase_ColorEscape;
495 cstr++;
496 }
497 if (endp) {
498 *endp = cstr;
499 }
500 return color;
501}
502
485iHSLColor setSat_HSLColor(iHSLColor d, float sat) { 503iHSLColor setSat_HSLColor(iHSLColor d, float sat) {
486 d.sat = iClamp(sat, 0, 1); 504 d.sat = iClamp(sat, 0, 1);
487 return d; 505 return d;
diff --git a/src/ui/color.h b/src/ui/color.h
index a1d863dc..b6571c86 100644
--- a/src/ui/color.h
+++ b/src/ui/color.h
@@ -250,4 +250,4 @@ void setThemePalette_Color (enum iColorTheme theme);
250 250
251iColor ansiForeground_Color (iRangecc escapeSequence, int fallback); 251iColor ansiForeground_Color (iRangecc escapeSequence, int fallback);
252const char * escape_Color (int color); 252const char * escape_Color (int color);
253 253enum iColorId parseEscape_Color (const char *cstr, const char **endp);
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c
index c8748efa..cfc81863 100644
--- a/src/ui/labelwidget.c
+++ b/src/ui/labelwidget.c
@@ -188,7 +188,8 @@ static void keyStr_LabelWidget_(const iLabelWidget *d, iString *str) {
188 toString_Sym(d->key, d->kmods, str); 188 toString_Sym(d->key, d->kmods, str);
189} 189}
190 190
191static 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,
192 int *icon, int *meta) {
192 const iWidget *w = constAs_Widget(d); 193 const iWidget *w = constAs_Widget(d);
193 const int64_t flags = flags_Widget(w); 194 const int64_t flags = flags_Widget(w);
194 const iBool isFocus = (flags & focusable_WidgetFlag && isFocused_Widget(d)); 195 const iBool isFocus = (flags & focusable_WidgetFlag && isFocused_Widget(d));
@@ -197,6 +198,7 @@ static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int
197 const iBool isFrameless = (flags & frameless_WidgetFlag) != 0; 198 const iBool isFrameless = (flags & frameless_WidgetFlag) != 0;
198 const iBool isButton = d->click.button != 0; 199 const iBool isButton = d->click.button != 0;
199 const iBool isKeyRoot = (w->root == get_Window()->keyRoot); 200 const iBool isKeyRoot = (w->root == get_Window()->keyRoot);
201 const iBool isDarkTheme = isDark_ColorTheme(colorTheme_App());
200 /* Default color state. */ 202 /* Default color state. */
201 *bg = isButton && ~flags & noBackground_WidgetFlag ? (d->widget.bgColor != none_ColorId ? 203 *bg = isButton && ~flags & noBackground_WidgetFlag ? (d->widget.bgColor != none_ColorId ?
202 d->widget.bgColor : uiBackground_ColorId) 204 d->widget.bgColor : uiBackground_ColorId)
@@ -204,8 +206,12 @@ static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int
204 *fg = uiText_ColorId; 206 *fg = uiText_ColorId;
205 *frame1 = isButton ? uiEmboss1_ColorId : d->widget.frameColor; 207 *frame1 = isButton ? uiEmboss1_ColorId : d->widget.frameColor;
206 *frame2 = isButton ? uiEmboss2_ColorId : *frame1; 208 *frame2 = isButton ? uiEmboss2_ColorId : *frame1;
209 *icon = uiIcon_ColorId;
210 *meta = uiTextShortcut_ColorId;
207 if (flags & disabled_WidgetFlag && isButton) { 211 if (flags & disabled_WidgetFlag && isButton) {
208 *fg = uiTextDisabled_ColorId; 212 *icon = uiTextDisabled_ColorId;
213 *fg = uiTextDisabled_ColorId;
214 *meta = uiTextDisabled_ColorId;
209 } 215 }
210 if (isSel) { 216 if (isSel) {
211 *bg = uiBackgroundSelected_ColorId; 217 *bg = uiBackgroundSelected_ColorId;
@@ -230,7 +236,10 @@ static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int
230 } 236 }
231 int colorEscape = none_ColorId; 237 int colorEscape = none_ColorId;
232 if (startsWith_String(&d->label, "\v")) { 238 if (startsWith_String(&d->label, "\v")) {
233 colorEscape = cstr_String(&d->label)[1] - asciiBase_ColorEscape; /* TODO: can be two bytes long */ 239 colorEscape = parseEscape_Color(cstr_String(&d->label), NULL);
240 }
241 if (colorEscape == uiTextCaution_ColorId) {
242 *icon = *meta = colorEscape;
234 } 243 }
235 if (isHover_LabelWidget_(d)) { 244 if (isHover_LabelWidget_(d)) {
236 if (isFrameless) { 245 if (isFrameless) {
@@ -239,41 +248,46 @@ static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int
239 } 248 }
240 else { 249 else {
241 /* Frames matching color escaped text. */ 250 /* Frames matching color escaped text. */
242 if (colorEscape != none_ColorId) { 251 if (colorEscape == uiTextCaution_ColorId) {
243 if (isDark_ColorTheme(colorTheme_App())) { 252 *frame1 = colorEscape;
244 *frame1 = colorEscape; 253 *frame2 = isDarkTheme ? darker_Color(*frame1) : lighter_Color(*frame1);
245 *frame2 = darker_Color(*frame1);
246 }
247 else {
248 *bg = *frame1 = *frame2 = colorEscape;
249 *fg = white_ColorId | permanent_ColorId;
250 }
251 } 254 }
252 else if (isSel) { 255 else if (isSel) {
253 *frame1 = uiEmbossSelectedHover1_ColorId; 256 *frame1 = uiEmbossSelectedHover1_ColorId;
254 *frame2 = uiEmbossSelectedHover2_ColorId; 257 *frame2 = uiEmbossSelectedHover2_ColorId;
255 } 258 }
256 else { 259 else {
257 if (isButton) *bg = uiBackgroundHover_ColorId;
258 *frame1 = uiEmbossHover1_ColorId; 260 *frame1 = uiEmbossHover1_ColorId;
259 *frame2 = uiEmbossHover2_ColorId; 261 *frame2 = uiEmbossHover2_ColorId;
260 } 262 }
261 } 263 }
264 if (colorEscape == uiTextCaution_ColorId) {
265 *icon = *meta = *fg = colorEscape;
266 *bg = isDarkTheme ? darker_Color(colorEscape) : lighter_Color(colorEscape);
267 }
262 } 268 }
263 if (d->forceFg >= 0) { 269 if (d->forceFg >= 0) {
264 *fg = d->forceFg; 270 *fg = *icon = *meta = d->forceFg;
265 } 271 }
266 if (isPress) { 272 if (isPress) {
267 *bg = uiBackgroundPressed_ColorId | permanent_ColorId; 273 if (colorEscape == uiTextAction_ColorId || colorEscape == uiTextCaution_ColorId) {
268 if (isButton) { 274 *bg = colorEscape;
269 *frame1 = uiEmbossPressed1_ColorId; 275 *frame1 = *bg;
270 *frame2 = colorEscape != none_ColorId ? colorEscape : uiEmbossPressed2_ColorId; 276 *frame2 = *bg;
271 } 277 *fg = *icon = *meta = (isDarkTheme ? black_ColorId : white_ColorId) | permanent_ColorId;
272 if (colorEscape == none_ColorId || colorEscape == uiTextAction_ColorId) {
273 *fg = uiTextPressed_ColorId | permanent_ColorId;
274 } 278 }
275 else { 279 else {
276 *fg = isDark_ColorTheme(colorTheme_App()) ? white_ColorId : black_ColorId; 280 *bg = uiBackgroundPressed_ColorId | permanent_ColorId;
281 if (isButton) {
282 *frame1 = uiEmbossPressed1_ColorId;
283 *frame2 = colorEscape != none_ColorId ? colorEscape : uiEmbossPressed2_ColorId;
284 }
285 //if (colorEscape == none_ColorId || colorEscape == uiTextAction_ColorId) {
286 *fg = *icon = *meta = uiTextPressed_ColorId | permanent_ColorId;
287 // }
288 // else {
289 // *fg = (isDark_ColorTheme(colorTheme_App()) ? white_ColorId : black_ColorId) | permanent_ColorId;
290 // }
277 } 291 }
278 } 292 }
279} 293}
@@ -305,11 +319,12 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
305 } 319 }
306 iPaint p; 320 iPaint p;
307 init_Paint(&p); 321 init_Paint(&p);
308 int bg, fg, frame, frame2; 322 int bg, fg, frame, frame2, iconColor, metaColor;
309 getColors_LabelWidget_(d, &bg, &fg, &frame, &frame2); 323 getColors_LabelWidget_(d, &bg, &fg, &frame, &frame2, &iconColor, &metaColor);
310 const iBool isCaution = startsWith_String(&d->label, uiTextCaution_ColorEscape); 324 const enum iColorId colorEscape = parseEscape_Color(cstr_String(&d->label), NULL);
325 const iBool isCaution = (colorEscape == uiTextCaution_ColorId);
311 if (bg >= 0) { 326 if (bg >= 0) {
312 fillRect_Paint(&p, rect, isCaution && isHover ? uiMarked_ColorId : bg); 327 fillRect_Paint(&p, rect, bg);
313 } 328 }
314 if (isFocused_Widget(w)) { 329 if (isFocused_Widget(w)) {
315 iRect frameRect = adjusted_Rect(rect, zero_I2(), init1_I2(-1)); 330 iRect frameRect = adjusted_Rect(rect, zero_I2(), init1_I2(-1));
@@ -340,10 +355,10 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
340 } 355 }
341 setClip_Paint(&p, rect); 356 setClip_Paint(&p, rect);
342 const int iconPad = iconPadding_LabelWidget_(d); 357 const int iconPad = iconPadding_LabelWidget_(d);
343 const int iconColor = isCaution ? uiTextCaution_ColorId 358// const int iconColor = isCaution ? uiTextCaution_ColorId
344 : flags & (disabled_WidgetFlag | pressed_WidgetFlag) ? fg 359// : flags & (disabled_WidgetFlag | pressed_WidgetFlag) ? fg
345 : isHover ? uiIconHover_ColorId 360// : isHover ? uiIconHover_ColorId
346 : uiIcon_ColorId; 361// : uiIcon_ColorId;
347 if (d->icon && d->icon != 0x20) { /* no need to draw an empty icon */ 362 if (d->icon && d->icon != 0x20) { /* no need to draw an empty icon */
348 iString str; 363 iString str;
349 initUnicodeN_String(&str, &d->icon, 1); 364 initUnicodeN_String(&str, &d->icon, 1);
@@ -363,7 +378,7 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
363 deinit_String(&str); 378 deinit_String(&str);
364 } 379 }
365 if (d->flags.wrap) { 380 if (d->flags.wrap) {
366 const iRect cont = contentBounds_LabelWidget_(d); //djusted_Rect(innerBounds_Widget(w), init_I2(iconPad, 0), zero_I2()); 381 const iRect cont = contentBounds_LabelWidget_(d);
367 drawWrapRange_Text( 382 drawWrapRange_Text(
368 d->font, topLeft_Rect(cont), width_Rect(cont), fg, range_String(&d->label)); 383 d->font, topLeft_Rect(cont), width_Rect(cont), fg, range_String(&d->label));
369 } 384 }
@@ -378,9 +393,11 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
378 add_I2(topRight_Rect(bounds), 393 add_I2(topRight_Rect(bounds),
379 addX_I2(negX_I2(padding_LabelWidget_(d, 1)), 394 addX_I2(negX_I2(padding_LabelWidget_(d, 1)),
380 deviceType_App() == tablet_AppDeviceType ? gap_UI : 0)), 395 deviceType_App() == tablet_AppDeviceType ? gap_UI : 0)),
381 flags & pressed_WidgetFlag ? fg 396 metaColor,/*
382 : isCaution ? uiTextCaution_ColorId 397 isHover || flags & pressed_WidgetFlag ? fg
383 : uiTextShortcut_ColorId, 398// : isCaution ? uiTextCaution_ColorId
399 : colorEscape != none_ColorId ? colorEscape
400 : uiTextShortcut_ColorId,*/
384 right_Alignment, 401 right_Alignment,
385 cstr_String(&str)); 402 cstr_String(&str));
386 deinit_String(&str); 403 deinit_String(&str);
@@ -410,7 +427,7 @@ static void draw_LabelWidget_(const iLabelWidget *d) {
410 drawCentered_Text(d->font, 427 drawCentered_Text(d->font,
411 (iRect){ addX_I2(topRight_Rect(chRect), -iconPad), 428 (iRect){ addX_I2(topRight_Rect(chRect), -iconPad),
412 init_I2(chSize, height_Rect(chRect)) }, 429 init_I2(chSize, height_Rect(chRect)) },
413 iTrue, iconColor /*uiSeparator_ColorId*/, rightAngle_Icon); 430 iTrue, iconColor, rightAngle_Icon);
414 } 431 }
415 unsetClip_Paint(&p); 432 unsetClip_Paint(&p);
416} 433}