diff --git a/UI/CustomButtonMappingScreen.cpp b/UI/CustomButtonMappingScreen.cpp index ded01b9e60..010b78e9af 100644 --- a/UI/CustomButtonMappingScreen.cpp +++ b/UI/CustomButtonMappingScreen.cpp @@ -121,15 +121,13 @@ std::string_view CustomButtonMappingScreen::GetTitle() const { return co->T("Custom touch button setup"); } -void CustomButtonMappingScreen::CreateViews() { +void CustomButtonMappingScreen::CreateDialogViews(UI::ViewGroup *parent) { using namespace UI; using namespace CustomKeyData; auto co = GetI18NCategory(I18NCat::CONTROLS); auto mc = GetI18NCategory(I18NCat::MAPPABLECONTROLS); - root_ = new LinearLayout(ORIENT_VERTICAL); - root_->Add(new ItemHeader(GetTitle())); - LinearLayout *root__ = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(1.0)); - root_->Add(root__); + LinearLayout *root__ = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0)); + parent->Add(root__); LinearLayout *leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(120, FILL_PARENT)); auto di = GetI18NCategory(I18NCat::DIALOG); @@ -143,13 +141,14 @@ void CustomButtonMappingScreen::CreateViews() { for (int i = 0; i < ARRAY_SIZE(g_customKeyList); i++) array[i] = (0x01 == ((g_Config.CustomButton[id_].key >> i) & 0x01)); + // TODO: Less hacky layout work + const Bounds layoutBounds = screenManager()->getUIContext()->GetLayoutBounds(); leftColumn->Add(new ButtonPreview(g_Config.iTouchButtonStyle == 0 ? customKeyShapes[cfg->shape].i : customKeyShapes[cfg->shape].l, - customKeyImages[cfg->image].i, customKeyImages[cfg->image].r, customKeyShapes[cfg->shape].f, customKeyShapes[cfg->shape].r, 62, 82)); + customKeyImages[cfg->image].i, customKeyImages[cfg->image].r, customKeyShapes[cfg->shape].f, customKeyShapes[cfg->shape].r, layoutBounds.x + 62, layoutBounds.y + 102)); root__->Add(leftColumn); + ScrollView *rightScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1.0f)); - leftColumn->Add(new Spacer(new LinearLayoutParams(1.0f))); - leftColumn->Add(new Choice(di->T("Back")))->OnClick.Handle(this, &UIScreen::OnBack); root__->Add(rightScroll); LinearLayout *vertLayout = new LinearLayout(ORIENT_VERTICAL); diff --git a/UI/CustomButtonMappingScreen.h b/UI/CustomButtonMappingScreen.h index 2fa658b00e..f5af27f51f 100644 --- a/UI/CustomButtonMappingScreen.h +++ b/UI/CustomButtonMappingScreen.h @@ -19,23 +19,25 @@ #include "UI/BaseScreens.h" #include "UI/GamepadEmu.h" +#include "UI/SimpleDialogScreen.h" namespace UI { class CheckBox; } -class CustomButtonMappingScreen : public UIBaseDialogScreen { +class CustomButtonMappingScreen : public UISimpleBaseDialogScreen { public: - CustomButtonMappingScreen(DeviceOrientation deviceOrientation, const Path &gamePath, int id) : UIBaseDialogScreen(gamePath), deviceOrientation_(deviceOrientation), id_(id) {} + CustomButtonMappingScreen(DeviceOrientation deviceOrientation, const Path &gamePath, int id) : UISimpleBaseDialogScreen(gamePath, SimpleDialogFlags::Default), deviceOrientation_(deviceOrientation), id_(id) {} const char *tag() const override { return "CustomButton"; } - void CreateViews() override; + void CreateDialogViews(UI::ViewGroup *parent) override; void onFinish(DialogResult result) override; protected: void dialogFinished(const Screen *dialog, DialogResult result) override; - std::string_view GetTitle() const; + std::string_view GetTitle() const override; + private: void saveArray(); diff --git a/UI/MiscScreens.h b/UI/MiscScreens.h index 0ce81762ee..b01175b9ba 100644 --- a/UI/MiscScreens.h +++ b/UI/MiscScreens.h @@ -119,13 +119,12 @@ private: class CreditsScreen : public UISimpleBaseDialogScreen { public: - CreditsScreen() : UISimpleBaseDialogScreen() {} + CreditsScreen() : UISimpleBaseDialogScreen(Path(), SimpleDialogFlags::Default) {} void update() override; protected: std::string_view GetTitle() const override; void CreateDialogViews(UI::ViewGroup *parent) override; - bool CanScroll() const override { return false; } const char *tag() const override { return "Credits"; } }; diff --git a/UI/ReportScreen.cpp b/UI/ReportScreen.cpp index 52c7b9f0d3..15f8f780d7 100644 --- a/UI/ReportScreen.cpp +++ b/UI/ReportScreen.cpp @@ -418,7 +418,7 @@ void ReportScreen::HandleBrowser(UI::EventParams &e) { } ReportFinishScreen::ReportFinishScreen(const Path &gamePath, ReportingOverallScore score) - : UISimpleBaseDialogScreen(), gamePath_(gamePath), score_(score) { + : UISimpleBaseDialogScreen(Path(), SimpleDialogFlags::ContentsCanScroll), gamePath_(gamePath), score_(score) { } std::string_view ReportFinishScreen::GetTitle() const { diff --git a/UI/SimpleDialogScreen.cpp b/UI/SimpleDialogScreen.cpp index 4eec0d1a22..e43d36ba39 100644 --- a/UI/SimpleDialogScreen.cpp +++ b/UI/SimpleDialogScreen.cpp @@ -7,7 +7,7 @@ void UISimpleBaseDialogScreen::CreateViews() { using namespace UI; - const bool canScroll = CanScroll(); + const bool canScroll = flags_ & SimpleDialogFlags::ContentsCanScroll; ignoreBottomInset_ = canScroll; const bool portrait = GetDeviceOrientation() == DeviceOrientation::Portrait; diff --git a/UI/SimpleDialogScreen.h b/UI/SimpleDialogScreen.h index 62fa6491e7..4a5464f55c 100644 --- a/UI/SimpleDialogScreen.h +++ b/UI/SimpleDialogScreen.h @@ -5,11 +5,17 @@ #include "UI/BaseScreens.h" +enum class SimpleDialogFlags { + Default = 0, + ContentsCanScroll = 8, +}; +ENUM_CLASS_BITOPS(SimpleDialogFlags); + // The simpler cousin of TabbedDialogScreen, without tabs or the other bling, // but with a consistent portrait-compatible back button and title. class UISimpleBaseDialogScreen : public UIBaseDialogScreen { public: - UISimpleBaseDialogScreen(const Path &gamePath = Path()) : UIBaseDialogScreen(gamePath) { + UISimpleBaseDialogScreen(const Path &gamePath, SimpleDialogFlags flags) : UIBaseDialogScreen(gamePath), flags_(flags) { // We need to check CanScroll before we know whether to ignore // bottom inset. Can't do that here, we do it in CreateViews } @@ -17,11 +23,10 @@ public: // Override this, don't override CreateViews. And don't touch root_ directly. virtual void CreateDialogViews(UI::ViewGroup *parent) = 0; virtual std::string_view GetTitle() const { return ""; } -protected: - virtual bool CanScroll() const { return true; } private: void CreateViews() override; + SimpleDialogFlags flags_; }; enum class TwoPaneFlags { diff --git a/UI/Store.cpp b/UI/Store.cpp index f34547672e..53b755f7cb 100644 --- a/UI/Store.cpp +++ b/UI/Store.cpp @@ -422,7 +422,7 @@ void ProductView::OnLaunchClick(UI::EventParams &e) { OnClickLaunch.Trigger(e2); } -StoreScreen::StoreScreen() { +StoreScreen::StoreScreen() : UISimpleBaseDialogScreen(Path(), SimpleDialogFlags::Default) { lang_ = g_Config.sLanguageIni; loading_ = true; diff --git a/UI/Store.h b/UI/Store.h index eabdb55492..ffb785191f 100644 --- a/UI/Store.h +++ b/UI/Store.h @@ -76,7 +76,6 @@ protected: void OnGameLaunch(UI::EventParams &e); std::string_view GetTitle() const override; - bool CanScroll() const override { return false; } // does its own scrolling private: void ParseListing(const std::string &json); ProductItemView *GetSelectedItem(); diff --git a/UI/TouchControlVisibilityScreen.cpp b/UI/TouchControlVisibilityScreen.cpp index cd28557e75..5362bcd8bc 100644 --- a/UI/TouchControlVisibilityScreen.cpp +++ b/UI/TouchControlVisibilityScreen.cpp @@ -46,15 +46,27 @@ private: UI::CheckBox *checkbox_; }; -void TouchControlVisibilityScreen::CreateTabs() { +std::string_view TouchControlVisibilityScreen::GetTitle() const { auto co = GetI18NCategory(I18NCat::CONTROLS); + return co->T("Touch Control Visibility"); +} - AddTab("Visibility", co->T("Visibility"), [this](UI::LinearLayout *contents) { - CreateVisibilityTab(contents); +void TouchControlVisibilityScreen::CreateSettingsViews(UI::ViewGroup *parent) { + using namespace UI; + + auto di = GetI18NCategory(I18NCat::DIALOG); + + Choice *toggleAll = parent->Add(new Choice(di->T("Toggle All"))); + toggleAll->OnClick.Add([this](UI::EventParams &e) { + // TODO: Is this a meaningful operation to support? + for (auto toggle : toggles_) { + *toggle.show = nextToggleAll_; + } + nextToggleAll_ = !nextToggleAll_; }); } -void TouchControlVisibilityScreen::CreateVisibilityTab(UI::LinearLayout *vert) { +void TouchControlVisibilityScreen::CreateContentViews(UI::ViewGroup *parent) { using namespace UI; using namespace CustomKeyData; @@ -63,25 +75,10 @@ void TouchControlVisibilityScreen::CreateVisibilityTab(UI::LinearLayout *vert) { const bool portrait = GetDeviceOrientation() == DeviceOrientation::Portrait; - Choice *toggleAll = new Choice(di->T("Toggle All"), "", false, new AnchorLayoutParams(leftColumnWidth - 10, WRAP_CONTENT, 10, NONE, NONE, 84)); - - vert->SetSpacing(0); - - vert->Add(toggleAll)->OnClick.Add([this](UI::EventParams &e) { - // TODO: Is this a meaningful operation to support? - for (auto toggle : toggles_) { - *toggle.show = nextToggleAll_; - } - nextToggleAll_ = !nextToggleAll_; - }); - - vert->Add(new ItemHeader(co->T("Touch Control Visibility"))); - const int cellSize = portrait ? std::min((g_display.dp_xres / 2 - 10), 290) : 380; - UI::GridLayoutSettings gridsettings(cellSize, 64, 5); gridsettings.fillCells = true; - GridLayout *grid = vert->Add(new GridLayoutList(gridsettings, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); + GridLayout *grid = parent->Add(new GridLayoutList(gridsettings, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); TouchControlConfig &touch = g_Config.GetTouchControlsConfig(GetDeviceOrientation()); diff --git a/UI/TouchControlVisibilityScreen.h b/UI/TouchControlVisibilityScreen.h index b9718c5268..f88417c591 100644 --- a/UI/TouchControlVisibilityScreen.h +++ b/UI/TouchControlVisibilityScreen.h @@ -21,7 +21,7 @@ #include #include "Common/Render/TextureAtlas.h" #include "UI/BaseScreens.h" -#include "UI/TabbedDialogScreen.h" +#include "UI/SimpleDialogScreen.h" namespace UI { class CheckBox; @@ -34,18 +34,16 @@ struct TouchButtonToggle { std::function handle; }; -class TouchControlVisibilityScreen : public UITabbedBaseDialogScreen { +class TouchControlVisibilityScreen : public UITwoPaneBaseDialogScreen { public: - TouchControlVisibilityScreen(const Path &gamePath) : UITabbedBaseDialogScreen(gamePath) {} - void CreateTabs() override; + TouchControlVisibilityScreen(const Path &gamePath) : UITwoPaneBaseDialogScreen(gamePath, TwoPaneFlags::SettingsInContextMenu | TwoPaneFlags::ContentsCanScroll) {} + void CreateContentViews(UI::ViewGroup *parent) override; + void CreateSettingsViews(UI::ViewGroup *parent) override; void onFinish(DialogResult result) override; const char *tag() const override { return "TouchControlVisibility"; } -protected: - bool ShowSearchControls() const override { return false; } - void CreateVisibilityTab(UI::LinearLayout *contents); - + std::string_view GetTitle() const override; private: std::vector toggles_; bool nextToggleAll_ = true; diff --git a/UI/UploadScreen.cpp b/UI/UploadScreen.cpp index 9004d5b021..9f8e29242e 100644 --- a/UI/UploadScreen.cpp +++ b/UI/UploadScreen.cpp @@ -9,7 +9,7 @@ #include "UI/UploadScreen.h" #include "UI/MiscViews.h" -UploadScreen::UploadScreen(const Path &targetFolder) : targetFolder_(targetFolder) { +UploadScreen::UploadScreen(const Path &targetFolder) : UISimpleBaseDialogScreen(Path(), SimpleDialogFlags::Default), targetFolder_(targetFolder) { std::vector ips; net::GetLocalIP4List(ips); localIPs_.clear();