Skip to content

Commit 712deb7

Browse files
committed
make tab menu icons left aligned
1 parent e539a57 commit 712deb7

2 files changed

Lines changed: 33 additions & 43 deletions

File tree

cmake/IncludeLibs.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ endif()
2222
CPMAddPackage("gh:matcool/gd-imgui-cocos#fbd4103")
2323
CPMAddPackage("gh:maxnut/GDReplayFormat#4950cc2")
2424
set(RIFT_INCLUDE_MATJSON ON)
25-
CPMAddPackage("gh:EclipseMenu/rift#c8d983d")
25+
CPMAddPackage("gh:EclipseMenu/rift#d6dd2bd")
2626
CPMAddPackage("gh:SpaghettDev/subprocess#e12740b")
2727
CPMAddPackage("gh:simdutf/simdutf@6.1.0")
2828
CPMAddPackage(

src/modules/gui/cocos/popup/tab-menu.cpp

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ namespace eclipse::gui::cocos {
5151
}
5252
constexpr int amount = 9;
5353
auto newTabs = utils::gradualPaginate<CCMenuItemSpriteExtra*>(m_tabs, amount, m_currentPage);
54-
m_upArrow->setVisible(m_currentPage != 0 && m_tabs.size() > 10);
55-
m_downArrow->setVisible(m_tabs.size() > 10 && m_currentPage < (m_tabs.size() - amount));
54+
m_upArrow->setVisible(m_currentPage != 0 && m_tabs.size() > amount);
55+
m_downArrow->setVisible(m_tabs.size() > amount && m_currentPage < (m_tabs.size() - amount));
5656
for (auto const& tab : newTabs) {
5757
tab->setContentHeight(28.f);
5858
tab->setVisible(true);
5959
}
6060
this->updateLayout();
6161
}
62+
6263
bool TabMenu::init(Tabs const& tabs, std::function<void(int)> const& callback) {
6364
if (!CCMenu::init()) return false;
6465
this->setID("tab-menu"_spr);
@@ -123,49 +124,28 @@ namespace eclipse::gui::cocos {
123124
return true;
124125
}
125126

126-
inline TranslatedLabel* mapWithIcon(std::string_view name) {
127-
auto label = TranslatedLabel::create(name);
128-
129-
static const std::unordered_map<std::string_view, std::string_view> icons = {
130-
{"tab.global", "🌐 "},
131-
{"tab.level", ""},
132-
{"tab.bypass", "🔓 "},
133-
{"tab.player", "🎮 "},
134-
{"tab.bot", "🤖 "},
135-
{"tab.creator", "🛠️ "},
136-
{"tab.labels", "🏷️ "},
137-
{"tab.shortcuts", "🔗 "},
138-
{"tab.keybinds", "⌨️ "},
139-
{"tab.interface", "⚙️ "},
140-
{"tab.recorder", "📹 "},
141-
{"BetterInfo", "🇮 "},
142-
};
143-
144-
static const Label::EmojiMap emojis = {
145-
{U"🌐", "tab_global.png"_spr},
146-
{U"", "tab_level.png"_spr},
147-
{U"🔓", "tab_bypass.png"_spr},
148-
{U"🎮", "tab_player.png"_spr},
149-
{U"🤖", "tab_bot.png"_spr},
150-
{U"🛠️", "tab_creator.png"_spr},
151-
{U"🏷️", "tab_labels.png"_spr},
152-
{U"🔗", "tab_shortcuts.png"_spr},
153-
{U"⌨️", "tab_keybinds.png"_spr},
154-
{U"⚙️", "tab_interface.png"_spr},
155-
{U"📹", "tab_recorder.png"_spr},
156-
{U"🇮", "tab_betterinfo.png"_spr},
127+
inline cocos2d::CCSprite* getTabIcon(std::string_view name) {
128+
static const std::unordered_map<std::string_view, const char*> emojis = {
129+
{"tab.global", "tab_global.png"_spr},
130+
{"tab.level", "tab_level.png"_spr},
131+
{"tab.bypass", "tab_bypass.png"_spr},
132+
{"tab.player", "tab_player.png"_spr},
133+
{"tab.bot", "tab_bot.png"_spr},
134+
{"tab.creator", "tab_creator.png"_spr},
135+
{"tab.labels", "tab_labels.png"_spr},
136+
{"tab.shortcuts", "tab_shortcuts.png"_spr},
137+
{"tab.keybinds", "tab_keybinds.png"_spr},
138+
{"tab.interface", "tab_interface.png"_spr},
139+
{"tab.recorder", "tab_recorder.png"_spr},
140+
{"BetterInfo", "tab_betterinfo.png"_spr},
157141
};
158142

159143
std::string_view icon = "";
160-
if (auto it = icons.find(name); it != icons.end()) {
161-
icon = it->second;
144+
if (auto it = emojis.find(name); it != emojis.end()) {
145+
return cocos2d::CCSprite::createWithSpriteFrameName(it->second);
162146
}
163147

164-
label->enableEmojis("UISheet.png"_spr, &emojis);
165-
label->enableEmojiColors(true);
166-
label->setString(fmt::format("{}{}", icon, label->getString()));
167-
label->limitLabelWidth(100, 1.f, .2f);
168-
return label;
148+
return nullptr;
169149
}
170150

171151
bool TabButton::init(std::string name, cocos2d::CCSize size) {
@@ -174,12 +154,22 @@ namespace eclipse::gui::cocos {
174154
this->setID(fmt::format("tab-button-{}"_spr, name));
175155
this->setContentSize(size);
176156

177-
m_label = mapWithIcon(name);
157+
auto icon = getTabIcon(name);
158+
if (icon) {
159+
icon->setScale(0.6f);
160+
icon->setZOrder(1);
161+
this->addChildAtPosition(icon, geode::Anchor::Left, {15.f, 0.f});
162+
}
163+
164+
m_label = TranslatedLabel::create(name);
165+
m_label->limitLabelWidth(icon ? 75 : 100, 1.f, .2f);
166+
178167
m_bgSprite = cocos2d::extension::CCScale9Sprite::create("square02b_001.png", {0.0f, 0.0f, 80.0f, 80.0f});
179168
m_bgSprite->setContentSize({size.width, size.height + 8.F}); // minimum 36
180169
m_bgSprite->setScaleY(.75F);
170+
181171
this->addChildAtPosition(m_bgSprite, geode::Anchor::Center);
182-
this->addChildAtPosition(m_label, geode::Anchor::Center);
172+
this->addChildAtPosition(m_label, geode::Anchor::Center, { icon ? 12.5f : 0.f, 0.f });
183173
return true;
184174
}
185175

0 commit comments

Comments
 (0)