diff options
Diffstat (limited to 'src/ui/labelwidget.c')
-rw-r--r-- | src/ui/labelwidget.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c index a3daff44..8b2506e7 100644 --- a/src/ui/labelwidget.c +++ b/src/ui/labelwidget.c | |||
@@ -1,3 +1,25 @@ | |||
1 | /* Copyright 2020 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
2 | |||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions are met: | ||
5 | |||
6 | 1. Redistributions of source code must retain the above copyright notice, this | ||
7 | list of conditions and the following disclaimer. | ||
8 | 2. Redistributions in binary form must reproduce the above copyright notice, | ||
9 | this list of conditions and the following disclaimer in the documentation | ||
10 | and/or other materials provided with the distribution. | ||
11 | |||
12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
14 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
15 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
16 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
17 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
20 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | ||
22 | |||
1 | #include "labelwidget.h" | 23 | #include "labelwidget.h" |
2 | #include "text.h" | 24 | #include "text.h" |
3 | #include "color.h" | 25 | #include "color.h" |
@@ -133,6 +155,9 @@ static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int | |||
133 | *fg = uiText_ColorId; | 155 | *fg = uiText_ColorId; |
134 | *frame1 = isButton ? uiEmboss1_ColorId : uiFrame_ColorId; | 156 | *frame1 = isButton ? uiEmboss1_ColorId : uiFrame_ColorId; |
135 | *frame2 = isButton ? uiEmboss2_ColorId : *frame1; | 157 | *frame2 = isButton ? uiEmboss2_ColorId : *frame1; |
158 | if (flags_Widget(w) & disabled_WidgetFlag && isButton) { | ||
159 | *fg = uiTextDisabled_ColorId; | ||
160 | } | ||
136 | if (isSel) { | 161 | if (isSel) { |
137 | *bg = uiBackgroundSelected_ColorId; | 162 | *bg = uiBackgroundSelected_ColorId; |
138 | *fg = uiTextSelected_ColorId; | 163 | *fg = uiTextSelected_ColorId; |
@@ -150,11 +175,11 @@ static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int | |||
150 | /* Frames matching color escaped text. */ | 175 | /* Frames matching color escaped text. */ |
151 | if (startsWith_String(&d->label, "\r")) { | 176 | if (startsWith_String(&d->label, "\r")) { |
152 | if (isDark_ColorTheme(colorTheme_App())) { | 177 | if (isDark_ColorTheme(colorTheme_App())) { |
153 | *frame1 = cstr_String(&d->label)[1] - '0'; | 178 | *frame1 = cstr_String(&d->label)[1] - asciiBase_ColorEscape; |
154 | *frame2 = darker_Color(*frame1); | 179 | *frame2 = darker_Color(*frame1); |
155 | } | 180 | } |
156 | else { | 181 | else { |
157 | *bg = *frame1 = *frame2 = cstr_String(&d->label)[1] - '0'; | 182 | *bg = *frame1 = *frame2 = cstr_String(&d->label)[1] - asciiBase_ColorEscape; |
158 | *fg = uiBackground_ColorId | permanent_ColorId; | 183 | *fg = uiBackground_ColorId | permanent_ColorId; |
159 | } | 184 | } |
160 | } | 185 | } |
@@ -311,10 +336,20 @@ void setTextCStr_LabelWidget(iLabelWidget *d, const char *text) { | |||
311 | updateSize_LabelWidget(d); | 336 | updateSize_LabelWidget(d); |
312 | } | 337 | } |
313 | 338 | ||
339 | const iString *label_LabelWidget(const iLabelWidget *d) { | ||
340 | return &d->label; | ||
341 | } | ||
342 | |||
314 | const iString *command_LabelWidget(const iLabelWidget *d) { | 343 | const iString *command_LabelWidget(const iLabelWidget *d) { |
315 | return &d->command; | 344 | return &d->command; |
316 | } | 345 | } |
317 | 346 | ||
347 | iLabelWidget *newColor_LabelWidget(const char *text, int color) { | ||
348 | iLabelWidget *d = new_LabelWidget(format_CStr("%s%s", escape_Color(color), text), 0, 0, NULL); | ||
349 | setFlags_Widget(as_Widget(d), frameless_WidgetFlag, iTrue); | ||
350 | return d; | ||
351 | } | ||
352 | |||
318 | iBeginDefineSubclass(LabelWidget, Widget) | 353 | iBeginDefineSubclass(LabelWidget, Widget) |
319 | .processEvent = (iAny *) processEvent_LabelWidget_, | 354 | .processEvent = (iAny *) processEvent_LabelWidget_, |
320 | .draw = (iAny *) draw_LabelWidget_, | 355 | .draw = (iAny *) draw_LabelWidget_, |