Make vertical tabs scrollable

This commit is contained in:
Henrik Rydgård 2024-01-19 11:53:12 +01:00
parent f73d0587d4
commit 0e03b66a95
4 changed files with 21 additions and 4 deletions

View file

@ -438,7 +438,7 @@ std::wstring ConvertUTF8ToWString(const std::string_view source) {
std::wstring str;
str.resize(size);
if (size > 0) {
MultiByteToWideChar(CP_UTF8, 0, source.data(), source.size(), &str[0], size);
MultiByteToWideChar(CP_UTF8, 0, source.data(), (int)source.size(), &str[0], size);
}
return str;
}

View file

@ -14,6 +14,7 @@
#include "Common/UI/Tween.h"
#include "Common/UI/Root.h"
#include "Common/UI/View.h"
#include "Common/UI/UIScreen.h"
#include "Common/UI/ViewGroup.h"
#include "Common/Render/DrawBuffer.h"
@ -949,9 +950,13 @@ TabHolder::TabHolder(Orientation orientation, float stripSize, LayoutParams *lay
tabScroll_->Add(tabStrip_);
Add(tabScroll_);
} else {
tabStrip_ = new ChoiceStrip(orientation, new LayoutParams(stripSize, WRAP_CONTENT));
tabContainer_ = new LinearLayout(ORIENT_VERTICAL, new LayoutParams(stripSize, FILL_PARENT));
tabStrip_ = new ChoiceStrip(orientation, new LayoutParams(FILL_PARENT, FILL_PARENT));
tabStrip_->SetTopTabs(true);
Add(tabStrip_);
tabScroll_ = new ScrollView(orientation, new LinearLayoutParams(1.0f));
tabScroll_->Add(tabStrip_);
tabContainer_->Add(tabScroll_);
Add(tabContainer_);
}
tabStrip_->OnChoice.Handle(this, &TabHolder::OnTabClick);
@ -959,6 +964,13 @@ TabHolder::TabHolder(Orientation orientation, float stripSize, LayoutParams *lay
Add(contents_)->SetClip(true);
}
void TabHolder::AddBack(UIScreen *parent) {
if (tabContainer_) {
auto di = GetI18NCategory(I18NCat::DIALOG);
tabContainer_->Add(new Choice(di->T("Back"), "", false, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 0.0f, Margins(0, 0, 10, 10))))->OnClick.Handle<UIScreen>(parent, &UIScreen::OnBack);
}
}
void TabHolder::AddTabContents(const std::string &title, View *tabContents) {
tabContents->ReplaceLayoutParams(new AnchorLayoutParams(FILL_PARENT, FILL_PARENT));
tabs_.push_back(tabContents);

View file

@ -9,6 +9,8 @@
#include "Common/Input/GestureDetector.h"
#include "Common/UI/View.h"
class UIScreen;
namespace UI {
class AnchorTranslateTween;
@ -298,6 +300,8 @@ public:
tabStrip_->EnableChoice(tab, enabled);
}
void AddBack(UIScreen *parent);
void SetCurrentTab(int tab, bool skipTween = false);
int GetCurrentTab() const { return currentTab_; }
@ -309,6 +313,7 @@ private:
void AddTabContents(const std::string &title, View *tabContents);
EventReturn OnTabClick(EventParams &e);
LinearLayout *tabContainer_ = nullptr;
ChoiceStrip *tabStrip_ = nullptr;
ScrollView *tabScroll_ = nullptr;
AnchorLayout *contents_ = nullptr;

View file

@ -49,8 +49,8 @@ void TabbedUIDialogScreenWithGameBackground::CreateViews() {
root_->Add(verticalLayout);
} else {
tabHolder_ = new TabHolder(ORIENT_VERTICAL, 200, new AnchorLayoutParams(10, 0, 10, 0, false));
tabHolder_->AddBack(this);
root_->Add(tabHolder_);
AddStandardBack(root_);
}
tabHolder_->SetTag(tag()); // take the tag from the screen.
root_->SetDefaultFocusView(tabHolder_);