Skip to content

Commit

Permalink
Merge pull request #16526 from hrydgard/vertical-layout-fixes
Browse files Browse the repository at this point in the history
Added vertical layout for display layout screen
  • Loading branch information
hrydgard authored Dec 8, 2022
2 parents 141e076 + d65a74e commit b06ea97
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 46 deletions.
11 changes: 11 additions & 0 deletions Common/UI/UIScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ static const bool ClickDebug = false;

UIScreen::UIScreen()
: Screen() {
lastVertical_ = UseVerticalLayout();
}

UIScreen::~UIScreen() {
delete root_;
}

bool UIScreen::UseVerticalLayout() const {
return dp_yres > dp_xres * 1.1f;
}

void UIScreen::DoRecreateViews() {
if (recreateViews_) {
std::lock_guard<std::recursive_mutex> guard(screenManager()->inputLock_);
Expand Down Expand Up @@ -60,6 +65,12 @@ void UIScreen::DoRecreateViews() {
}

void UIScreen::update() {
bool vertical = UseVerticalLayout();
if (vertical != lastVertical_) {
RecreateViews();
lastVertical_ = vertical;
}

DoRecreateViews();

if (root_) {
Expand Down
4 changes: 3 additions & 1 deletion Common/UI/UIScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class UIScreen : public Screen {
virtual void CreateViews() = 0;
virtual void DrawBackground(UIContext &dc) {}

virtual void RecreateViews() override { recreateViews_ = true; }
void RecreateViews() override { recreateViews_ = true; }
bool UseVerticalLayout() const;

UI::ViewGroup *root_ = nullptr;
Vec3 translation_ = Vec3(0.0f);
Expand All @@ -54,6 +55,7 @@ class UIScreen : public Screen {
void DoRecreateViews();

bool recreateViews_ = true;
bool lastVertical_;
};

class UIDialogScreen : public UIScreen {
Expand Down
32 changes: 24 additions & 8 deletions UI/DisplayLayoutScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,21 @@ void DisplayLayoutScreen::CreateViews() {

root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));

bool vertical = bounds.h > bounds.w;

// Make it so that a touch can only affect one view. Makes manipulating the background through the buttons
// impossible.
root_->SetExclusiveTouch(true);

ScrollView *leftScrollView = new ScrollView(ORIENT_VERTICAL, new AnchorLayoutParams(420.0f, FILL_PARENT, 0.f, 0.f, NONE, 0.f, false));
LinearLayout *leftColumn = new LinearLayout(ORIENT_VERTICAL);
leftColumn->padding.SetAll(8.0f);
leftScrollView->Add(leftColumn);
leftScrollView->SetClickableBackground(true);
root_->Add(leftScrollView);
LinearLayout *leftColumn;
if (!vertical) {
ScrollView *leftScrollView = new ScrollView(ORIENT_VERTICAL, new AnchorLayoutParams(420.0f, FILL_PARENT, 0.f, 0.f, NONE, 0.f, false));
leftColumn = new LinearLayout(ORIENT_VERTICAL);
leftColumn->padding.SetAll(8.0f);
leftScrollView->Add(leftColumn);
leftScrollView->SetClickableBackground(true);
root_->Add(leftScrollView);
}

ScrollView *rightScrollView = new ScrollView(ORIENT_VERTICAL, new AnchorLayoutParams(300.0f, FILL_PARENT, NONE, 0.f, 0.f, 0.f, false));
LinearLayout *rightColumn = new LinearLayout(ORIENT_VERTICAL);
Expand All @@ -217,8 +222,15 @@ void DisplayLayoutScreen::CreateViews() {
rightScrollView->SetClickableBackground(true);
root_->Add(rightScrollView);

LinearLayout *bottomControls = new LinearLayout(ORIENT_HORIZONTAL, new AnchorLayoutParams(NONE, NONE, NONE, 10.0f, false));
root_->Add(bottomControls);
LinearLayout *bottomControls;
if (vertical) {
bottomControls = new LinearLayout(ORIENT_HORIZONTAL);
rightColumn->Add(bottomControls);
leftColumn = rightColumn;
} else {
bottomControls = new LinearLayout(ORIENT_HORIZONTAL, new AnchorLayoutParams(NONE, NONE, NONE, 10.0f, false));
root_->Add(bottomControls);
}

// Set backgrounds for readability
Drawable backgroundWithAlpha(GetBackgroundColorWithAlpha(*screenManager()->getUIContext()));
Expand Down Expand Up @@ -266,6 +278,10 @@ void DisplayLayoutScreen::CreateViews() {
back->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
rightColumn->Add(back);

if (vertical) {
leftColumn->Add(new Spacer(24.0f));
}

static const char *bufFilters[] = { "Linear", "Nearest", };
leftColumn->Add(new PopupMultiChoice(&g_Config.iBufFilter, gr->T("Screen Scaling Filter"), bufFilters, 1, ARRAY_SIZE(bufFilters), gr->GetName(), screenManager()));

Expand Down
15 changes: 0 additions & 15 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,10 @@ extern AndroidAudioState *g_audioState;

GameSettingsScreen::GameSettingsScreen(const Path &gamePath, std::string gameID, bool editThenRestore)
: UIDialogScreenWithGameBackground(gamePath), gameID_(gameID), editThenRestore_(editThenRestore) {
lastVertical_ = UseVerticalLayout();
prevInflightFrames_ = g_Config.iInflightFrames;
analogSpeedMapped_ = KeyMap::AxisFromPspButton(VIRTKEY_SPEED_ANALOG, nullptr, nullptr, nullptr);
}

bool GameSettingsScreen::UseVerticalLayout() const {
return dp_yres > dp_xres * 1.1f;
}

// This needs before run CheckGPUFeatures()
// TODO: Remove this if fix the issue
bool CheckSupportShaderTessellationGLES() {
Expand Down Expand Up @@ -1297,16 +1292,6 @@ UI::EventReturn GameSettingsScreen::OnHwScaleChange(UI::EventParams &e) {
return UI::EVENT_DONE;
}

void GameSettingsScreen::update() {
UIScreen::update();

bool vertical = UseVerticalLayout();
if (vertical != lastVertical_) {
RecreateViews();
lastVertical_ = vertical;
}
}

void GameSettingsScreen::onFinish(DialogResult result) {
if (g_Config.bEnableSound) {
if (PSP_IsInited() && !IsAudioInitialised())
Expand Down
3 changes: 0 additions & 3 deletions UI/GameSettingsScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
public:
GameSettingsScreen(const Path &gamePath, std::string gameID = "", bool editThenRestore = false);

void update() override;
void onFinish(DialogResult result) override;
const char *tag() const override { return "GameSettings"; }

Expand All @@ -42,7 +41,6 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
void CallbackRenderingDevice(bool yes);
void CallbackInflightFrames(bool yes);
void CallbackMemstickFolder(bool yes);
bool UseVerticalLayout() const;
void dialogFinished(const Screen *dialog, DialogResult result) override;
void RecreateViews() override;

Expand All @@ -52,7 +50,6 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
void TriggerRestart(const char *why);

std::string gameID_;
bool lastVertical_;
UI::CheckBox *enableReportsCheckbox_;
UI::Choice *layoutEditorChoice_;
UI::Choice *displayEditor_;
Expand Down
10 changes: 0 additions & 10 deletions UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,6 @@ UI::EventReturn GameBrowser::OnHomebrewStore(UI::EventParams &e) {
MainScreen::MainScreen() {
System_SendMessage("event", "mainscreen");
g_BackgroundAudio.SetGame(Path());
lastVertical_ = UseVerticalLayout();
}

MainScreen::~MainScreen() {
Expand Down Expand Up @@ -1255,15 +1254,6 @@ void MainScreen::sendMessage(const char *message, const char *value) {
void MainScreen::update() {
UIScreen::update();
UpdateUIState(UISTATE_MENU);
bool vertical = UseVerticalLayout();
if (vertical != lastVertical_) {
RecreateViews();
lastVertical_ = vertical;
}
}

bool MainScreen::UseVerticalLayout() const {
return dp_yres > dp_xres * 1.1f;
}

UI::EventReturn MainScreen::OnLoadFile(UI::EventParams &e) {
Expand Down
1 change: 0 additions & 1 deletion UI/MainScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class MainScreen : public UIScreenWithBackground {
void sendMessage(const char *message, const char *value) override;
void dialogFinished(const Screen *dialog, DialogResult result) override;

bool UseVerticalLayout() const;
bool DrawBackgroundFor(UIContext &dc, const Path &gamePath, float progress);

UI::EventReturn OnGameSelected(UI::EventParams &e);
Expand Down
18 changes: 12 additions & 6 deletions UI/PauseScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ UI::EventReturn ScreenshotViewScreen::OnUndoState(UI::EventParams &e) {

class SaveSlotView : public UI::LinearLayout {
public:
SaveSlotView(const Path &gamePath, int slot, UI::LayoutParams *layoutParams = nullptr);
SaveSlotView(const Path &gamePath, int slot, bool vertical, UI::LayoutParams *layoutParams = nullptr);

void GetContentDimensions(const UIContext &dc, float &w, float &h) const override {
w = 500; h = 90;
Expand Down Expand Up @@ -169,7 +169,7 @@ class SaveSlotView : public UI::LinearLayout {
Path screenshotFilename_;
};

SaveSlotView::SaveSlotView(const Path &gameFilename, int slot, UI::LayoutParams *layoutParams) : UI::LinearLayout(UI::ORIENT_HORIZONTAL, layoutParams), slot_(slot), gamePath_(gameFilename) {
SaveSlotView::SaveSlotView(const Path &gameFilename, int slot, bool vertical, UI::LayoutParams *layoutParams) : UI::LinearLayout(UI::ORIENT_HORIZONTAL, layoutParams), slot_(slot), gamePath_(gameFilename) {
using namespace UI;

screenshotFilename_ = SaveState::GenerateSaveSlotFilename(gamePath_, slot, SaveState::SCREENSHOT_EXTENSION);
Expand All @@ -185,7 +185,7 @@ SaveSlotView::SaveSlotView(const Path &gameFilename, int slot, UI::LayoutParams

Add(lines);

LinearLayout *buttons = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT));
LinearLayout *buttons = new LinearLayout(vertical ? ORIENT_VERTICAL : ORIENT_HORIZONTAL, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT));
buttons->SetSpacing(10.0f);

lines->Add(buttons);
Expand All @@ -201,7 +201,11 @@ SaveSlotView::SaveSlotView(const Path &gameFilename, int slot, UI::LayoutParams

std::string dateStr = SaveState::GetSlotDateAsString(gamePath_, slot_);
if (!dateStr.empty()) {
lines->Add(new TextView(dateStr, new LinearLayoutParams(0.0, G_VCENTER)))->SetShadow(true);
TextView *dateView = new TextView(dateStr, new LinearLayoutParams(0.0, G_VCENTER));
if (vertical) {
dateView->SetSmall(true);
}
lines->Add(dateView)->SetShadow(true);
}
} else {
fv->SetFilename(Path());
Expand Down Expand Up @@ -262,6 +266,8 @@ void GamePauseScreen::CreateViews() {

using namespace UI;

bool vertical = UseVerticalLayout();

Margins scrollMargins(0, 20, 0, 0);
Margins actionMenuMargins(0, 20, 15, 0);
auto gr = GetI18NCategory("Graphics");
Expand All @@ -278,7 +284,7 @@ void GamePauseScreen::CreateViews() {
leftColumnItems->Add(new Spacer(0.0));
leftColumnItems->SetSpacing(10.0);
for (int i = 0; i < NUM_SAVESLOTS; i++) {
SaveSlotView *slot = leftColumnItems->Add(new SaveSlotView(gamePath_, i, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
SaveSlotView *slot = leftColumnItems->Add(new SaveSlotView(gamePath_, i, vertical, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
slot->OnStateLoaded.Handle(this, &GamePauseScreen::OnState);
slot->OnStateSaved.Handle(this, &GamePauseScreen::OnState);
slot->OnScreenshotClicked.Handle(this, &GamePauseScreen::OnScreenshotClicked);
Expand All @@ -302,7 +308,7 @@ void GamePauseScreen::CreateViews() {
rewindButton->OnClick.Handle(this, &GamePauseScreen::OnRewind);
}

ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins));
ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(vertical ? 200 : 300, FILL_PARENT, actionMenuMargins));
root_->Add(rightColumn);

LinearLayout *rightColumnItems = new LinearLayout(ORIENT_VERTICAL);
Expand Down
4 changes: 2 additions & 2 deletions UI/RemoteISOScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,11 @@ RemoteISOBrowseScreen::RemoteISOBrowseScreen(const std::string &url, const std::
}

void RemoteISOBrowseScreen::CreateViews() {
bool vertical = UseVerticalLayout();

auto di = GetI18NCategory("Dialog");
auto ri = GetI18NCategory("RemoteISO");

bool vertical = UseVerticalLayout();

Margins actionMenuMargins(0, 10, 10, 0);

TabHolder *leftColumn = new TabHolder(ORIENT_HORIZONTAL, 64, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
Expand Down

0 comments on commit b06ea97

Please sign in to comment.