diff --git a/Common/UI/PopupScreens.cpp b/Common/UI/PopupScreens.cpp index 1384e4bf43..d72d21ce54 100644 --- a/Common/UI/PopupScreens.cpp +++ b/Common/UI/PopupScreens.cpp @@ -20,7 +20,7 @@ void MessagePopupScreen::CreatePopupContents(UI::ViewGroup *parent) { std::vector messageLines; SplitString(message_, '\n', messageLines); for (auto lineOfText : messageLines) - parent->Add(new UI::TextView(lineOfText, ALIGN_LEFT | ALIGN_VCENTER, false))->SetTextColor(dc.theme->popupStyle.fgColor); + parent->Add(new UI::TextView(lineOfText, ALIGN_LEFT | ALIGN_VCENTER, false)); } void MessagePopupScreen::OnCompleted(DialogResult result) { @@ -374,7 +374,6 @@ void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) { edit_ = new TextEdit("", Title(), "", new LinearLayoutParams(1.0f)); edit_->SetMaxLen(16); - edit_->SetTextColor(dc.theme->itemStyle.fgColor); edit_->SetTextAlign(FLAG_DYNAMIC_ASCII); edit_->OnTextChange.Handle(this, &SliderPopupScreen::OnTextChange); changing_ = true; @@ -383,7 +382,7 @@ void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) { lin->Add(edit_); if (!units_.empty()) - lin->Add(new TextView(units_))->SetTextColor(dc.theme->itemStyle.fgColor); + lin->Add(new TextView(units_)); if (defaultValue_ != NO_DEFAULT_FLOAT) { auto di = GetI18NCategory(I18NCat::DIALOG); diff --git a/Common/UI/Tween.cpp b/Common/UI/Tween.cpp index bf7e29026e..f71aaac856 100644 --- a/Common/UI/Tween.cpp +++ b/Common/UI/Tween.cpp @@ -1,4 +1,4 @@ -#include "Common/Data/Color/RGBAUtil.h" +#include "Common/Data/Color/RGBAUtil.h" #include "Common/UI/Tween.h" #include "Common/UI/View.h" #include "Common/UI/ViewGroup.h" @@ -73,12 +73,6 @@ uint32_t ColorTween::Current(float pos) { return colorBlend(to_, from_, pos); } -void TextColorTween::DoApply(View *view, float pos) { - // TODO: No validation without RTTI? - TextView *tv = (TextView *)view; - tv->SetTextColor(Current(pos)); -} - void CallbackColorTween::DoApply(View *view, float pos) { if (callback_) { callback_(view, Current(pos)); diff --git a/Common/UI/Tween.h b/Common/UI/Tween.h index f290c0e497..d5973e36bd 100644 --- a/Common/UI/Tween.h +++ b/Common/UI/Tween.h @@ -151,14 +151,6 @@ protected: uint32_t Current(float pos) override; }; -class TextColorTween : public ColorTween { -public: - using ColorTween::ColorTween; - -protected: - void DoApply(View *view, float pos) override; -}; - class CallbackColorTween : public ColorTween { public: using ColorTween::ColorTween; diff --git a/Common/UI/UIScreen.cpp b/Common/UI/UIScreen.cpp index 9412008276..ee5a5c1b76 100644 --- a/Common/UI/UIScreen.cpp +++ b/Common/UI/UIScreen.cpp @@ -430,11 +430,15 @@ void PopupScreen::CreateViews() { box_->SetSpacing(0.0f); if (HasTitleBar()) { - View* title = new PopupHeader(title_); + View *title = new PopupHeader(title_); box_->Add(title); } CreatePopupContents(box_); + root_->Recurse([](View *view) { + view->SetPopupStyle(true); + }); + root_->SetDefaultFocusView(box_); if (ShowButtons() && !button1_.empty()) { // And the two buttons at the bottom. diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index cec3e26e84..a250ffc305 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -711,11 +711,11 @@ void PopupHeader::Draw(UIContext &dc) { } // Header background - dc.FillRect(dc.theme->popupHeaderStyle.background, bounds_); + dc.FillRect(dc.theme->popupTitleStyle.background, bounds_); // Header title text - dc.DrawText(text_, bounds_.x + tx, bounds_.centerY(), dc.theme->popupHeaderStyle.fgColor, ALIGN_LEFT | ALIGN_VCENTER); + dc.DrawText(text_, bounds_.x + tx, bounds_.centerY(), dc.theme->popupTitleStyle.fgColor, ALIGN_LEFT | ALIGN_VCENTER); // Underline - dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), dc.theme->popupHeaderStyle.fgColor); + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), dc.theme->popupTitleStyle.fgColor); if (availableWidth < tw) { dc.PopScissor(); @@ -1055,7 +1055,7 @@ void TextView::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz } void TextView::Draw(UIContext &dc) { - uint32_t textColor = hasTextColor_ ? textColor_ : dc.theme->infoStyle.fgColor; + uint32_t textColor = hasTextColor_ ? textColor_ : (popupStyle_ ? dc.theme->popupStyle.fgColor : dc.theme->infoStyle.fgColor); if (!(textColor & 0xFF000000)) return; @@ -1130,9 +1130,11 @@ void TextEdit::FocusChanged(int focusFlags) { void TextEdit::Draw(UIContext &dc) { dc.PushScissor(bounds_); dc.SetFontStyle(dc.theme->uiFont); + + // TODO: make background themeable? dc.FillRect(HasFocus() ? UI::Drawable(0x80000000) : UI::Drawable(0x30000000), bounds_); - uint32_t textColor = hasTextColor_ ? textColor_ : dc.theme->infoStyle.fgColor; + uint32_t textColor = popupStyle_ ? dc.theme->popupStyle.fgColor : dc.theme->infoStyle.fgColor; float textX = bounds_.x; float w, h; diff --git a/Common/UI/View.h b/Common/UI/View.h index 4ede036922..89bf62a3bb 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -110,7 +110,7 @@ struct Theme { Style collapsibleHeaderStyle; Style popupStyle; - Style popupHeaderStyle; + Style popupTitleStyle; Style tooltipStyle; @@ -429,6 +429,8 @@ public: virtual bool CanBeFocused() const { return true; } virtual bool SubviewFocused(View *view) { return false; } + void SetPopupStyle(bool popupStyle) { popupStyle_ = popupStyle; } + bool HasFocus() const { return GetFocusedView() == this; } @@ -480,6 +482,8 @@ public: return t; } + virtual void Recurse(void (*func)(View *view)) {} + protected: // Inputs to layout std::unique_ptr layoutParams_; @@ -496,6 +500,9 @@ protected: std::vector tweens_; + // Whether to use popup colors for styling. + bool popupStyle_ = false; + private: std::function enabledFunc_; bool *enabledPtr_ = nullptr; @@ -851,11 +858,9 @@ public: std::string DescribeText() const override; void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override; void SetLarge(bool large) { large_ = large; } - void SetPopupStyle(bool popupStyle) { popupStyle_ = popupStyle; } private: std::string text_; bool large_ = false; - bool popupStyle_ = false; }; class PopupHeader : public Item { diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index a544952929..f55b07ab5a 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -48,6 +48,13 @@ ViewGroup::~ViewGroup() { Clear(); } +void ViewGroup::Recurse(void (*func)(View *view)) { + for (View *view : views_) { + func(view); + view->Recurse(func); + } +} + void ViewGroup::RemoveSubview(View *subView) { // loop counter needed, so can't convert loop. for (size_t i = 0; i < views_.size(); i++) { diff --git a/Common/UI/ViewGroup.h b/Common/UI/ViewGroup.h index 6a3ef5a222..1cfbddb01b 100644 --- a/Common/UI/ViewGroup.h +++ b/Common/UI/ViewGroup.h @@ -82,6 +82,8 @@ public: std::string DescribeLog() const override { return "ViewGroup: " + View::DescribeLog(); } std::string DescribeText() const override; + void Recurse(void (*func)(View *view)) override; + protected: std::string DescribeListUnordered(std::string_view heading) const; std::string DescribeListOrdered(std::string_view heading) const; diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 81bbab19da..3c9fffbdf2 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1738,16 +1738,16 @@ void GridSettingsPopupScreen::CreatePopupContents(UI::ViewGroup *parent) { static const char *defaultTabs[] = { "Recent", "Games", "Homebrew & Demos" }; PopupMultiChoice *beziersChoice = items->Add(new PopupMultiChoice(&g_Config.iDefaultTab, sy->T("Default tab"), defaultTabs, 0, ARRAY_SIZE(defaultTabs), I18NCat::MAINMENU, screenManager())); - items->Add(new ItemHeader(sy->T("Grid icon size")))->SetPopupStyle(true); + items->Add(new ItemHeader(sy->T("Grid icon size"))); items->Add(new Choice(sy->T("Increase size")))->OnClick.Handle(this, &GridSettingsPopupScreen::GridPlusClick); items->Add(new Choice(sy->T("Decrease size")))->OnClick.Handle(this, &GridSettingsPopupScreen::GridMinusClick); - items->Add(new ItemHeader(sy->T("Display Extra Info")))->SetPopupStyle(true); + items->Add(new ItemHeader(sy->T("Display Extra Info"))); items->Add(new CheckBox(&g_Config.bShowIDOnGameIcon, sy->T("Show ID"))); items->Add(new CheckBox(&g_Config.bShowRegionOnGameIcon, sy->T("Show region flag"))); if (g_Config.iMaxRecent > 0) { - items->Add(new ItemHeader(sy->T("Clear Recent")))->SetPopupStyle(true); + items->Add(new ItemHeader(sy->T("Clear Recent"))); items->Add(new Choice(sy->T("Clear Recent Games List")))->OnClick.Handle(this, &GridSettingsPopupScreen::OnRecentClearClick); } diff --git a/UI/Theme.cpp b/UI/Theme.cpp index 0a93b95378..914236de33 100644 --- a/UI/Theme.cpp +++ b/UI/Theme.cpp @@ -51,8 +51,8 @@ struct ThemeInfo { uint32_t uInfoStyleBg = 0x00000000; uint32_t uPopupStyleFg = 0xFFFFFFFF; uint32_t uPopupStyleBg = 0xFF303030; - uint32_t uPopupHeaderStyleFg = 0xFFFFFFFF; - uint32_t uPopupHeaderStyleBg = 0x00000000; // default to invisible + uint32_t uPopupTitleStyleFg = 0xFFFFFFFF; + uint32_t uPopupTitleStyleBg = 0x00000000; // default to invisible uint32_t uTooltipStyleFg = 0xFFFFFFFF; uint32_t uTooltipStyleBg = 0xC0303030; uint32_t uCollapsibleHeaderStyleFg = 0xFFFFFFFF; @@ -148,8 +148,8 @@ static void LoadThemeInfo(const std::vector &directories) { section.Get("PopupStyleBg", &info.uPopupStyleBg, info.uPopupStyleBg); section.Get("TooltipStyleFg", &info.uTooltipStyleFg, info.uTooltipStyleFg); // Backwards compat section.Get("TooltipStyleBg", &info.uTooltipStyleBg, info.uTooltipStyleBg); - section.Get("PopupHeaderStyleFg", &info.uPopupHeaderStyleFg, info.uItemStyleFg); // Backwards compat - section.Get("PopupHeaderStyleBg", &info.uPopupHeaderStyleBg, info.uPopupHeaderStyleBg); + section.Get("PopupHeaderStyleFg", &info.uPopupTitleStyleFg, info.uItemStyleFg); // Backwards compat + section.Get("PopupHeaderStyleBg", &info.uPopupTitleStyleBg, info.uPopupTitleStyleBg); section.Get("CollapsibleHeaderStyleFg", &info.uCollapsibleHeaderStyleFg, info.uItemStyleFg); // Backwards compat section.Get("CollapsibleHeaderStyleBg", &info.uCollapsibleHeaderStyleBg, info.uItemStyleBg); section.Get("BackgroundColor", &info.uBackgroundColor, info.uBackgroundColor); @@ -256,7 +256,7 @@ void UpdateTheme(UIContext *ctx) { ui_theme.infoStyle = MakeStyle(themeInfo.uInfoStyleFg, themeInfo.uInfoStyleBg); ui_theme.popupStyle = MakeStyle(themeInfo.uPopupStyleFg, themeInfo.uPopupStyleBg); - ui_theme.popupHeaderStyle = MakeStyle(themeInfo.uPopupHeaderStyleFg, themeInfo.uPopupHeaderStyleBg); + ui_theme.popupTitleStyle = MakeStyle(themeInfo.uPopupTitleStyleFg, themeInfo.uPopupTitleStyleBg); ui_theme.tooltipStyle = MakeStyle(themeInfo.uTooltipStyleFg, themeInfo.uTooltipStyleBg); diff --git a/assets/themes/1995.ini b/assets/themes/1995.ini index 3c193d8c14..d7560670ee 100644 --- a/assets/themes/1995.ini +++ b/assets/themes/1995.ini @@ -26,8 +26,8 @@ InfoStyleFg = "#FFFFFFFF" InfoStyleBg = "#00000000" PopupStyleFg = "#000000FF" PopupStyleBg = "#FFFFAAFF" -PopupHeaderStyleFg = "#FFFFFFFF" -PopupHeaderStyleBg = "#000080FF" +PopupTitleStyleFg = "#FFFFFFFF" +PopupTitleStyleBg = "#000080FF" CollapsibleHeaderStyleFg = "#000000FF" CollapsibleHeaderStyleBg = "#C0C0C0FF" TooltipStyleFg = "#FFFFFFFF" diff --git a/assets/themes/defaultthemes.ini b/assets/themes/defaultthemes.ini index 76c5558f96..c8e8a0a14f 100644 --- a/assets/themes/defaultthemes.ini +++ b/assets/themes/defaultthemes.ini @@ -14,8 +14,8 @@ InfoStyleFg = "#FFFFFFFF" InfoStyleBg = "#00000000" PopupStyleFg = "#FFFFFFFF" PopupStyleBg = "#1f4d5eFF" -PopupHeaderStyleFg = "#FFFFFFFF" -PopupHeaderStyleBg = "#00000000" +PopupTitleStyleFg = "#FFFFFFFF" +PopupTitleStyleBg = "#00000000" CollapsibleHeaderStyleFg = "#FFFFFFFF" CollapsibleHeaderStyleBg = "#00000055" TooltipStyleFg = "#FFFFFFFF" @@ -44,8 +44,8 @@ InfoStyleFg = "#FFFFFFFF" InfoStyleBg = "#00000000" PopupStyleFg = "#FFFFFFFF" PopupStyleBg = "#0c1d24FF" -PopupHeaderStyleFg = "#FFFFFFFF" -PopupHeaderStyleBg = "#00000000" +PopupTitleStyleFg = "#FFFFFFFF" +PopupTitleStyleBg = "#00000000" CollapsibleHeaderStyleFg = "#FFFFFFFF" CollapsibleHeaderStyleBg = "#00000055" TooltipStyleFg = "#FFFFFFFF" diff --git a/assets/themes/slateforest.ini b/assets/themes/slateforest.ini index 4abf128302..3d811e1e38 100644 --- a/assets/themes/slateforest.ini +++ b/assets/themes/slateforest.ini @@ -24,8 +24,8 @@ InfoStyleFg = "#FFFFFFFF" InfoStyleBg = "#00000000" PopupStyleFg = "#FFFFFFFF" PopupStyleBg = "#9498A1FF" -PopupHeaderStyleFg = "#FFFFFFFF" -PopupHeaderStyleBg = "#00000000" +PopupTitleStyleFg = "#FFFFFFFF" +PopupTitleStyleBg = "#00000000" CollapsibleHeaderStyleFg = "#FFFFFFFF" CollapsibleHeaderStyleBg = "#2D4459B0" TooltipStyleFg = "#FFFFFFFF" diff --git a/assets/themes/vinewood.ini b/assets/themes/vinewood.ini index b1dd3403a8..8cd769bf53 100644 --- a/assets/themes/vinewood.ini +++ b/assets/themes/vinewood.ini @@ -25,8 +25,8 @@ InfoStyleFg = "#FFFFFFFF" InfoStyleBg = "#00000000" PopupStyleFg = "#C3D7A4FF" PopupStyleBg = "#94B185FF" -PopupHeaderStyleFg = "#FFFFFFFF" -PopupHeaderStyleBg = "#00000000" +PopupTitleStyleFg = "#FFFFFFFF" +PopupTitleStyleBg = "#00000000" CollapsibleHeaderStyleFg = "#C3D7A4FF" CollapsibleHeaderStyleBg = "#000000C0" TooltipStyleFg = "#FFFFFFFF"