Clean up the main screen logo view (adjust spacing, extract function)

This commit is contained in:
Henrik Rydgård
2025-10-23 14:03:40 +02:00
parent 9d0dfea04f
commit 21f9438682
2 changed files with 48 additions and 44 deletions
+47 -43
View File
@@ -1121,6 +1121,52 @@ GameBrowser *MainScreen::CreateBrowserTab(const Path &path, std::string_view tit
return gameBrowser;
}
UI::ViewGroup *MainScreen::CreateLogoView() {
using namespace UI;
AnchorLayout *logos = new AnchorLayout(new AnchorLayoutParams(FILL_PARENT, 80.0f, false));
if (System_GetPropertyBool(SYSPROP_APP_GOLD)) {
logos->Add(new ImageView(ImageID("I_ICON_GOLD"), "", IS_DEFAULT, new AnchorLayoutParams(64, 64, 0, 0, NONE, NONE, false)));
} else {
logos->Add(new ImageView(ImageID("I_ICON"), "", IS_DEFAULT, new AnchorLayoutParams(64, 64, 0, 0, NONE, NONE, false)));
}
logos->Add(new ImageView(ImageID("I_LOGO"), "PPSSPP", IS_DEFAULT, new AnchorLayoutParams(180, 64, 68, 2, NONE, NONE, false)));
#if !defined(MOBILE_DEVICE)
auto gr = GetI18NCategory(I18NCat::GRAPHICS);
ImageID icon(g_Config.UseFullScreen() ? "I_RESTORE" : "I_FULLSCREEN");
fullscreenButton_ = logos->Add(new Button(gr->T("FullScreen", "Full Screen"), icon, new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, false)));
fullscreenButton_->SetIgnoreText(true);
fullscreenButton_->OnClick.Handle(this, &MainScreen::OnFullScreenToggle);
#endif
std::string versionString = PPSSPP_GIT_VERSION;
// Strip the 'v' from the displayed version, and shorten the commit hash.
if (versionString.size() > 2) {
if (versionString[0] == 'v' && isdigit(versionString[1])) {
versionString = versionString.substr(1);
}
if (CountChar(versionString, '-') == 2) {
// Shorten the commit hash.
size_t cutPos = versionString.find_last_of('-') + 8;
versionString = versionString.substr(0, std::min(cutPos, versionString.size()));
}
}
ClickableTextView *ver = logos->Add(new ClickableTextView(versionString, new AnchorLayoutParams(68, NONE, NONE, 0)));
ver->SetSmall(true);
ver->SetClip(false);
// Only allow copying the version if it looks like a git version string. 1.19 for example is not really necessary to be able to copy/paste.
if (strchr(PPSSPP_GIT_VERSION, '-')) {
ver->OnClick.Add([](UI::EventParams &e) {
auto di = GetI18NCategory(I18NCat::DIALOG);
System_CopyStringToClipboard(PPSSPP_GIT_VERSION);
g_OSD.Show(OSDType::MESSAGE_INFO, ApplySafeSubstitutions(di->T("Copied to clipboard: %1"), PPSSPP_GIT_VERSION));
});
}
return logos;
}
void MainScreen::CreateViews() {
// Information in the top left.
// Back button to the bottom left.
@@ -1217,49 +1263,7 @@ void MainScreen::CreateViews() {
LinearLayout *rightColumnItems = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
rightColumnItems->SetSpacing(0.0f);
std::string versionString = PPSSPP_GIT_VERSION;
// Strip the 'v' from the displayed version, and shorten the commit hash.
if (versionString.size() > 2) {
if (versionString[0] == 'v' && isdigit(versionString[1])) {
versionString = versionString.substr(1);
}
if (CountChar(versionString, '-') == 2) {
// Shorten the commit hash.
size_t cutPos = versionString.find_last_of('-') + 8;
versionString = versionString.substr(0, std::min(cutPos, versionString.size()));
}
}
rightColumnItems->SetSpacing(0.0f);
AnchorLayout *logos = new AnchorLayout(new AnchorLayoutParams(FILL_PARENT, 60.0f, false));
if (System_GetPropertyBool(SYSPROP_APP_GOLD)) {
logos->Add(new ImageView(ImageID("I_ICON_GOLD"), "", IS_DEFAULT, new AnchorLayoutParams(64, 64, 0, 0, NONE, NONE, false)));
} else {
logos->Add(new ImageView(ImageID("I_ICON"), "", IS_DEFAULT, new AnchorLayoutParams(64, 64, 0, 0, NONE, NONE, false)));
}
logos->Add(new ImageView(ImageID("I_LOGO"), "PPSSPP", IS_DEFAULT, new AnchorLayoutParams(180, 64, 64, 0.0f, NONE, NONE, false)));
#if !defined(MOBILE_DEVICE)
auto gr = GetI18NCategory(I18NCat::GRAPHICS);
ImageID icon(g_Config.UseFullScreen() ? "I_RESTORE" : "I_FULLSCREEN");
fullscreenButton_ = logos->Add(new Button(gr->T("FullScreen", "Full Screen"), icon, new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, false)));
fullscreenButton_->SetIgnoreText(true);
fullscreenButton_->OnClick.Handle(this, &MainScreen::OnFullScreenToggle);
#endif
rightColumnItems->Add(logos);
ClickableTextView *ver = rightColumnItems->Add(new ClickableTextView(versionString, new LinearLayoutParams(Margins(70, -10, 0, 4))));
ver->SetSmall(true);
ver->SetClip(false);
// Only allow copying the version if it looks like a git version string. 1.19 for example is not really necessary to be able to copy/paste.
if (strchr(PPSSPP_GIT_VERSION, '-')) {
ver->OnClick.Add([](UI::EventParams &e) {
auto di = GetI18NCategory(I18NCat::DIALOG);
System_CopyStringToClipboard(PPSSPP_GIT_VERSION);
g_OSD.Show(OSDType::MESSAGE_INFO, ApplySafeSubstitutions(di->T("Copied to clipboard: %1"), PPSSPP_GIT_VERSION));
});
}
rightColumnItems->Add(CreateLogoView());
LinearLayout *rightColumnChoices = rightColumnItems;
if (vertical) {
+1 -1
View File
@@ -135,7 +135,7 @@ protected:
void CreateViews() override;
void CreateRecentTab();
GameBrowser *CreateBrowserTab(const Path &path, std::string_view title, std::string_view howToTitle, std::string_view howToUri, BrowseFlags browseFlags, bool *bGridView, float *scrollPos);
UI::ViewGroup *CreateButtons(bool vertical);
UI::ViewGroup *MainScreen::CreateLogoView();
void DrawBackground(UIContext &dc) override;
void update() override;