Skip to content

Commit

Permalink
Make vertical tabs scrollable
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 19, 2024
1 parent f73d058 commit 0e03b66
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Common/Data/Encoding/Utf8.cpp
Expand Up @@ -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;
}
Expand Down
16 changes: 14 additions & 2 deletions Common/UI/ViewGroup.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -949,16 +950,27 @@ 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);

contents_ = new AnchorLayout(new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f));
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);
Expand Down
5 changes: 5 additions & 0 deletions Common/UI/ViewGroup.h
Expand Up @@ -9,6 +9,8 @@
#include "Common/Input/GestureDetector.h"
#include "Common/UI/View.h"

class UIScreen;

namespace UI {

class AnchorTranslateTween;
Expand Down Expand Up @@ -298,6 +300,8 @@ class TabHolder : public LinearLayout {
tabStrip_->EnableChoice(tab, enabled);
}

void AddBack(UIScreen *parent);

void SetCurrentTab(int tab, bool skipTween = false);

int GetCurrentTab() const { return currentTab_; }
Expand All @@ -309,6 +313,7 @@ class TabHolder : public LinearLayout {
void AddTabContents(const std::string &title, View *tabContents);
EventReturn OnTabClick(EventParams &e);

LinearLayout *tabContainer_ = nullptr;
ChoiceStrip *tabStrip_ = nullptr;
ScrollView *tabScroll_ = nullptr;
AnchorLayout *contents_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion UI/TabbedDialogScreen.cpp
Expand Up @@ -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_);
Expand Down

0 comments on commit 0e03b66

Please sign in to comment.