From ca9854451dd3266c6f098a006549c70f26f4b368 Mon Sep 17 00:00:00 2001 From: Pascal Abresch Date: Wed, 2 Oct 2024 01:04:19 +0200 Subject: [PATCH] TextControl: Make background of invalid control red Co-Authored-By: Niklas Poslovski Change-Id: Idd6aa8984aab5d8a8aee81bade23946b88f2497e Reviewed-on: https://review.haiku-os.org/c/haiku/+/8428 Reviewed-by: nephele nephele Tested-by: Commit checker robot Haiku-Format: Haiku-format Bot Reviewed-by: John Scipione --- src/kits/interface/TextControl.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/kits/interface/TextControl.cpp b/src/kits/interface/TextControl.cpp index 4e1bfc36c9..b4a26831c4 100644 --- a/src/kits/interface/TextControl.cpp +++ b/src/kits/interface/TextControl.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -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);