From 812cf76fbf1f1a1d23f04727c47c20a0fd9f1aad Mon Sep 17 00:00:00 2001 From: Pascal Abresch Date: Sun, 9 Feb 2025 23:47:08 +0100 Subject: [PATCH] Interface kit: Be explicit about text color for DrawLabel Previously NULL was the default argument for text labels, this caused ControlLooks to pick "something" for the text color In particular this previously caused mismatched color pairs. Properly set this in the code to prevent this implicit color choosing. Api Clients can still pass = NULL directly if they wish for the controlLook to think of a color itself. Change-Id: Iea56e8d61269284f1d1470b852093bac5bf70de4 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8963 Reviewed-by: John Scipione Reviewed-by: nephele nephele Tested-by: Commit checker robot --- src/apps/activitymonitor/ActivityView.cpp | 5 +++-- src/apps/debuganalyzer/gui/HeaderView.cpp | 3 ++- src/apps/installer/PackageViews.cpp | 7 ++++--- src/apps/mail/Header.cpp | 6 ++++-- src/apps/webpositive/tabview/TabView.cpp | 3 ++- src/kits/interface/AbstractSpinner.cpp | 3 ++- src/kits/interface/Slider.cpp | 17 +++++++++-------- src/kits/interface/TabView.cpp | 4 +++- src/kits/interface/TextControl.cpp | 4 +++- 9 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index 5fea2cd6b4..3d8ca237a6 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -1512,10 +1512,11 @@ ActivityView::Draw(BRect updateRect) DrawString(label.String(), BPoint(6 + colorBox.right, y)); DrawString(text.String(), BPoint(frame.right - width, y)); } else { + rgb_color parentHigh = Parent()->HighColor(); be_control_look->DrawLabel(this, label.String(), - Parent()->ViewColor(), 0, BPoint(6 + colorBox.right, y)); + Parent()->ViewColor(), 0, BPoint(6 + colorBox.right, y), &parentHigh); be_control_look->DrawLabel(this, text.String(), - Parent()->ViewColor(), 0, BPoint(frame.right - width, y)); + Parent()->ViewColor(), 0, BPoint(frame.right - width, y), &parentHigh); } } } diff --git a/src/apps/debuganalyzer/gui/HeaderView.cpp b/src/apps/debuganalyzer/gui/HeaderView.cpp index e33a29d91e..8d90a2e2b5 100644 --- a/src/apps/debuganalyzer/gui/HeaderView.cpp +++ b/src/apps/debuganalyzer/gui/HeaderView.cpp @@ -109,8 +109,9 @@ DefaultHeaderRenderer::DrawHeader(BView* view, BRect frame, BRect updateRect, frame.InsetBy(be_control_look->DefaultLabelSpacing(), 0); if (value.Type() == B_STRING_TYPE) { + rgb_color highColor = view->HighColor(); be_control_look->DrawLabel(view, value.ToString(), frame, updateRect, - view->LowColor(), 0); + view->LowColor(), 0, &highColor); } } diff --git a/src/apps/installer/PackageViews.cpp b/src/apps/installer/PackageViews.cpp index 25c2b827b6..802f117efc 100644 --- a/src/apps/installer/PackageViews.cpp +++ b/src/apps/installer/PackageViews.cpp @@ -160,8 +160,9 @@ PackageCheckBox::Draw(BRect update) float width = StringWidth(string); BRect sizeRect = Bounds(); sizeRect.left = sizeRect.right - width; + rgb_color documentText = ui_color(B_DOCUMENT_TEXT_COLOR); be_control_look->DrawLabel(this, string, NULL, sizeRect, update, - ui_color(B_DOCUMENT_BACKGROUND_COLOR), be_control_look->Flags(this)); + ui_color(B_DOCUMENT_BACKGROUND_COLOR), be_control_look->Flags(this), &documentText); } @@ -302,9 +303,9 @@ PackagesView::Draw(BRect updateRect) { if (CountChildren() > 0) return; - + rgb_color highColor = HighColor(); be_control_look->DrawLabel(this, B_TRANSLATE("No optional packages available."), Bounds(), updateRect, ViewColor(), BControlLook::B_DISABLED, - BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE)); + BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE), &highColor); } diff --git a/src/apps/mail/Header.cpp b/src/apps/mail/Header.cpp index c90b57e711..9942c65717 100644 --- a/src/apps/mail/Header.cpp +++ b/src/apps/mail/Header.cpp @@ -154,8 +154,9 @@ LabelView::Draw(BRect updateRect) if (!IsEnabled()) flags |= BControlLook::B_DISABLED; + rgb_color text = ui_color(B_PANEL_TEXT_COLOR); be_control_look->DrawLabel(this, Text(), rect, updateRect, - base, flags, BAlignment(Alignment(), B_ALIGN_MIDDLE)); + base, flags, BAlignment(Alignment(), B_ALIGN_MIDDLE), &text); } } @@ -197,6 +198,7 @@ HeaderTextControl::Draw(BRect updateRect) rect.InsetBy(-2, -2); rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); + rgb_color text = ui_color(B_PANEL_TEXT_COLOR); uint32 flags = 0; if (!enabled) flags = BControlLook::B_DISABLED; @@ -219,7 +221,7 @@ HeaderTextControl::Draw(BRect updateRect) GetAlignment(&labelAlignment, NULL); be_control_look->DrawLabel(this, Label(), rect, updateRect, - base, flags, BAlignment(labelAlignment, B_ALIGN_MIDDLE)); + base, flags, BAlignment(labelAlignment, B_ALIGN_MIDDLE), &text); } } diff --git a/src/apps/webpositive/tabview/TabView.cpp b/src/apps/webpositive/tabview/TabView.cpp index 683fd03d5c..ad642da74e 100644 --- a/src/apps/webpositive/tabview/TabView.cpp +++ b/src/apps/webpositive/tabview/TabView.cpp @@ -122,8 +122,9 @@ void TabView::DrawContents(BView* owner, BRect frame, const BRect& updateRect) { rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); + rgb_color text = ui_color(B_PANEL_TEXT_COLOR); be_control_look->DrawLabel(owner, fLabel.String(), frame, updateRect, - base, 0, BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); + base, 0, BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE), &text); } diff --git a/src/kits/interface/AbstractSpinner.cpp b/src/kits/interface/AbstractSpinner.cpp index 00c297b0e1..7a185a1a66 100644 --- a/src/kits/interface/AbstractSpinner.cpp +++ b/src/kits/interface/AbstractSpinner.cpp @@ -1474,7 +1474,8 @@ BAbstractSpinner::_DrawLabel(BRect updateRect) uint32 flags = be_control_look->Flags(this); - be_control_look->DrawLabel(this, label, LowColor(), flags, BPoint(x, y)); + rgb_color highColor = HighColor(); + be_control_look->DrawLabel(this, label, LowColor(), flags, BPoint(x, y), &highColor); } diff --git a/src/kits/interface/Slider.cpp b/src/kits/interface/Slider.cpp index 6bac3bd6db..9d67bc98c3 100644 --- a/src/kits/interface/Slider.cpp +++ b/src/kits/interface/Slider.cpp @@ -973,6 +973,7 @@ BSlider::DrawText() BView* view = OffscreenView(); rgb_color base = ViewColor(); + rgb_color text = HighColor(); uint32 flags = be_control_look->Flags(this); font_height fontHeight; @@ -980,25 +981,25 @@ BSlider::DrawText() if (Orientation() == B_HORIZONTAL) { if (Label() != NULL) { be_control_look->DrawLabel(view, Label(), base, flags, - BPoint(0.0f, ceilf(fontHeight.ascent))); + BPoint(0.0f, ceilf(fontHeight.ascent)), &text); } // the update text is updated in SetValue() only if (fUpdateText != NULL) { be_control_look->DrawLabel(view, fUpdateText, base, flags, BPoint(bounds.right - StringWidth(fUpdateText), - ceilf(fontHeight.ascent))); + ceilf(fontHeight.ascent)), &text); } if (fMinLimitLabel != NULL) { be_control_look->DrawLabel(view, fMinLimitLabel, base, flags, - BPoint(0.0f, bounds.bottom - fontHeight.descent)); + BPoint(0.0f, bounds.bottom - fontHeight.descent), &text); } if (fMaxLimitLabel != NULL) { be_control_look->DrawLabel(view, fMaxLimitLabel, base, flags, BPoint(bounds.right - StringWidth(fMaxLimitLabel), - bounds.bottom - fontHeight.descent)); + bounds.bottom - fontHeight.descent), &text); } } else { float lineHeight = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent) @@ -1008,14 +1009,14 @@ BSlider::DrawText() if (Label() != NULL) { be_control_look->DrawLabel(view, Label(), base, flags, BPoint((bounds.Width() - StringWidth(Label())) / 2.0, - baseLine)); + baseLine), &text); baseLine += lineHeight; } if (fMaxLimitLabel != NULL) { be_control_look->DrawLabel(view, fMaxLimitLabel, base, flags, BPoint((bounds.Width() - StringWidth(fMaxLimitLabel)) / 2.0, - baseLine)); + baseLine), &text); } baseLine = bounds.bottom - ceilf(fontHeight.descent); @@ -1023,14 +1024,14 @@ BSlider::DrawText() if (fMinLimitLabel != NULL) { be_control_look->DrawLabel(view, fMinLimitLabel, base, flags, BPoint((bounds.Width() - StringWidth(fMinLimitLabel)) / 2.0, - baseLine)); + baseLine), &text); baseLine -= lineHeight; } if (fUpdateText != NULL) { be_control_look->DrawLabel(view, fUpdateText, base, flags, BPoint((bounds.Width() - StringWidth(fUpdateText)) / 2.0, - baseLine)); + baseLine), &text); } } } diff --git a/src/kits/interface/TabView.cpp b/src/kits/interface/TabView.cpp index 34af9c4753..a1d4b31957 100644 --- a/src/kits/interface/TabView.cpp +++ b/src/kits/interface/TabView.cpp @@ -307,10 +307,12 @@ BTab::DrawLabel(BView* owner, BRect frame) BAffineTransform transform; transform.RotateBy(center, rotation * M_PI / 180.0f); owner->SetTransform(transform); + + rgb_color highColor = ui_color(B_PANEL_TEXT_COLOR); be_control_look->DrawLabel(owner, Label(), frame, frame, ui_color(B_PANEL_BACKGROUND_COLOR), IsEnabled() ? 0 : BControlLook::B_DISABLED, - BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER)); + BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER), &highColor); owner->SetTransform(BAffineTransform()); } diff --git a/src/kits/interface/TextControl.cpp b/src/kits/interface/TextControl.cpp index 3964ab49fc..cbb423c4fb 100644 --- a/src/kits/interface/TextControl.cpp +++ b/src/kits/interface/TextControl.cpp @@ -361,6 +361,8 @@ BTextControl::Draw(BRect updateRect) rect.InsetBy(-2, -2); rgb_color base = ViewColor(); + rgb_color text = HighColor(); + uint32 flags = fLook; if (!enabled) flags |= BControlLook::B_DISABLED; @@ -379,7 +381,7 @@ BTextControl::Draw(BRect updateRect) } be_control_look->DrawLabel(this, Label(), rect, updateRect, - base, flags, BAlignment(fLabelAlign, B_ALIGN_MIDDLE)); + base, flags, BAlignment(fLabelAlign, B_ALIGN_MIDDLE), &text); } }