TextControl: Make background of invalid control red

Co-Authored-By: Niklas Poslovski <ni.pos@yandex.com>
Change-Id: Idd6aa8984aab5d8a8aee81bade23946b88f2497e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8428
Reviewed-by: nephele nephele <nep-git@packageloss.eu>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
Reviewed-by: John Scipione <jscipione@gmail.com>
This commit is contained in:
Pascal Abresch 2024-10-02 01:04:19 +02:00 committed by nephele nephele
parent 6ab7170720
commit ca9854451d

View File

@ -19,6 +19,7 @@
#include <AbstractLayoutItem.h>
#include <ControlLook.h>
#include <HSL.h>
#include <LayoutUtils.h>
#include <Message.h>
#include <PropertyInfo.h>
@ -470,7 +471,8 @@ BTextControl::MessageReceived(BMessage* message)
if (message->HasColor(ui_color_name(B_PANEL_BACKGROUND_COLOR))
|| message->HasColor(ui_color_name(B_PANEL_TEXT_COLOR))
|| message->HasColor(ui_color_name(B_DOCUMENT_BACKGROUND_COLOR))
|| message->HasColor(ui_color_name(B_DOCUMENT_TEXT_COLOR))) {
|| message->HasColor(ui_color_name(B_DOCUMENT_TEXT_COLOR))
|| message->HasColor(ui_color_name(B_FAILURE_COLOR))) {
_UpdateTextViewColors(IsEnabled());
}
}
@ -595,8 +597,10 @@ BTextControl::MarkAsInvalid(bool invalid)
else
fLook &= ~BControlLook::B_INVALID;
if (look != fLook)
if (look != fLook) {
_UpdateTextViewColors(IsEnabled());
Invalidate();
}
}
@ -1045,6 +1049,18 @@ BTextControl::_UpdateTextViewColors(bool enable)
if (!enable) {
textColor = disable_color(textColor, ViewColor());
viewColor = disable_color(ViewColor(), viewColor);
} else if (fLook & BControlLook::B_INVALID) {
hsl_color normalViewColor = hsl_color::from_rgb(viewColor);
rgb_color failureColor = ui_color(B_FAILURE_COLOR);
hsl_color newViewColor = hsl_color::from_rgb(failureColor);
if (normalViewColor.lightness < 0.15)
newViewColor.lightness = 0.15;
else if (normalViewColor.lightness > 0.95)
newViewColor.lightness = 0.95;
else
newViewColor.lightness = normalViewColor.lightness;
viewColor = newViewColor.to_rgb();
}
fText->SetFontAndColor(&font, B_FONT_ALL, &textColor);