Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions Common/UI/ViewGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ std::string GridLayoutList::DescribeText() const {
return DescribeListOrdered(u->T("List:"));
}

TabHolder::TabHolder(Orientation orientation, float stripSize, LayoutParams *layoutParams)
TabHolder::TabHolder(Orientation orientation, float stripSize, View *bannerView, LayoutParams *layoutParams)
: LinearLayout(Opposite(orientation), layoutParams) {
SetSpacing(0.0f);
if (orientation == ORIENT_HORIZONTAL) {
Expand All @@ -979,8 +979,14 @@ TabHolder::TabHolder(Orientation orientation, float stripSize, LayoutParams *lay

Add(new Spacer(4.0f))->SetSeparator();

contents_ = new AnchorLayout(new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f));
Add(contents_)->SetClip(true);
ViewGroup *contentHolder_ = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f));
if (bannerView) {
contentHolder_->Add(bannerView);
bannerView_ = bannerView;
}
contents_ = contentHolder_->Add(new AnchorLayout(new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f)));
contents_->SetClip(true);
Add(contentHolder_);
}

void TabHolder::AddBack(UIScreen *parent) {
Expand All @@ -990,16 +996,56 @@ void TabHolder::AddBack(UIScreen *parent) {
}
}

void TabHolder::AddTabContents(std::string_view title, View *tabContents) {
tabContents->ReplaceLayoutParams(new AnchorLayoutParams(FILL_PARENT, FILL_PARENT));
void TabHolder::AddTabContents(std::string_view title, ViewGroup *tabContents) {
tabs_.push_back(tabContents);
tabStrip_->AddChoice(title);
contents_->Add(tabContents);
if (tabs_.size() > 1)
tabContents->SetVisibility(V_GONE);
tabContents->ReplaceLayoutParams(new AnchorLayoutParams(FILL_PARENT, FILL_PARENT));

// Will be filled in later.
tabTweens_.push_back(nullptr);
// This entry doesn't need one.
createFuncs_.push_back(nullptr);
}

void TabHolder::AddTabDeferred(std::string_view title, std::function<ViewGroup *()> createCb) {
tabs_.push_back(nullptr); // marker
tabStrip_->AddChoice(title);
tabTweens_.push_back(nullptr);
createFuncs_.push_back(createCb);

// Pre-create the first tab in a non-deferred way.
if (tabs_.size() == 1) {
EnsureTab(0);
}
}

void TabHolder::EnsureAllCreated() {
for (int i = 0; i < createFuncs_.size(); i++) {
if (createFuncs_[i]) {
EnsureTab(i);
tabs_[i]->SetVisibility(i == currentTab_ ? V_VISIBLE : V_GONE);
}
}
}

void TabHolder::EnsureTab(int index) {
_dbg_assert_(index >= 0 && index < createFuncs_.size());

if (!tabs_[index]) {
_dbg_assert_(index < createFuncs_.size());
_dbg_assert_(createFuncs_[index]);
std::function<UI::ViewGroup * ()> func;
createFuncs_[index].swap(func);

ViewGroup *tabContents = func();
tabs_[index] = tabContents;
contents_->Add(tabContents);

tabContents->ReplaceLayoutParams(new AnchorLayoutParams(FILL_PARENT, FILL_PARENT));
}
}

void TabHolder::SetCurrentTab(int tab, bool skipTween) {
Expand All @@ -1008,7 +1054,10 @@ void TabHolder::SetCurrentTab(int tab, bool skipTween) {
return;
}

EnsureTab(tab);

auto setupTween = [&](View *view, AnchorTranslateTween *&tween) {
_dbg_assert_(view != nullptr);
if (tween)
return;

Expand Down Expand Up @@ -1051,6 +1100,7 @@ void TabHolder::SetCurrentTab(int tab, bool skipTween) {
tabs_[tab]->SetVisibility(V_VISIBLE);

currentTab_ = tab;
EnsureTab(currentTab_);
}
tabStrip_->SetSelection(tab, false);
}
Expand All @@ -1059,6 +1109,7 @@ EventReturn TabHolder::OnTabClick(EventParams &e) {
// We have e.b set when it was an explicit click action.
// In that case, we make the view gone and then visible - this scrolls scrollviews to the top.
if (e.b != 0) {
EnsureTab(e.a);
SetCurrentTab((int)e.a);
}
return EVENT_DONE;
Expand Down
22 changes: 16 additions & 6 deletions Common/UI/ViewGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ViewGroup : public View {

void Clear();
void PersistData(PersistStatus status, std::string anonId, PersistMap &storage) override;
View *GetViewByIndex(int index) { return views_[index]; }
View *GetViewByIndex(int index) const { return views_[index]; }
int GetNumSubviews() const { return (int)views_.size(); }
void SetHasDropShadow(bool has) { hasDropShadow_ = has; }
void SetDropShadowExpand(float s) { dropShadowExpand_ = s; }
Expand Down Expand Up @@ -291,13 +291,14 @@ class ChoiceStrip : public LinearLayout {

class TabHolder : public LinearLayout {
public:
TabHolder(Orientation orientation, float stripSize, LayoutParams *layoutParams = 0);
TabHolder(Orientation orientation, float stripSize, View *bannerView, LayoutParams *layoutParams = 0);

template <class T>
T *AddTab(std::string_view title, T *tabContents) {
AddTabContents(title, (View *)tabContents);
AddTabContents(title, tabContents);
return tabContents;
}
void AddTabDeferred(std::string_view title, std::function<ViewGroup *()> createCb);
void EnableTab(int tab, bool enabled) {
tabStrip_->EnableChoice(tab, enabled);
}
Expand All @@ -311,20 +312,29 @@ class TabHolder : public LinearLayout {

void PersistData(PersistStatus status, std::string anonId, PersistMap &storage) override;

void EnsureAllCreated();

LinearLayout *Container() { return tabContainer_; }

const std::vector<ViewGroup *> &GetTabContentViews() const {
return tabs_;
}

private:
void AddTabContents(std::string_view title, View *tabContents);
void AddTabContents(std::string_view title, ViewGroup *tabContents);
EventReturn OnTabClick(EventParams &e);
void EnsureTab(int index);

View *bannerView_ = nullptr;
LinearLayout *tabContainer_ = nullptr;
ChoiceStrip *tabStrip_ = nullptr;
ScrollView *tabScroll_ = nullptr;
AnchorLayout *contents_ = nullptr;
ViewGroup *contents_ = nullptr;

int currentTab_ = 0;
std::vector<View *> tabs_;
std::vector<ViewGroup *> tabs_;
std::vector<AnchorTranslateTween *> tabTweens_;
std::vector<std::function<ViewGroup *()>> createFuncs_;
};

class CollapsibleHeader;
Expand Down
4 changes: 2 additions & 2 deletions Core/Util/PPGeDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ PPGeImage::PPGeImage(std::string_view pspFilename)

PPGeImage::PPGeImage(u32 pngPointer, size_t pngSize)
: filename_(""), png_(pngPointer), size_(pngSize) {
if (!Memory::IsValidRange(this->png_, this->size_)) {
if (!Memory::IsValidRange(this->png_, (u32)this->size_)) {
WARN_LOG(Log::sceGe, "Created PPGeImage from invalid memory range %08x (%08x bytes). Will not be drawn.");
}
}
Expand Down Expand Up @@ -1417,7 +1417,7 @@ bool PPGeImage::IsValid() {
if (loadFailed_)
return false;

if (!Memory::IsValidRange(this->png_, this->size_)) {
if (!Memory::IsValidRange(this->png_, (u32)this->size_)) {
return false;
}

Expand Down
Loading