This commit is contained in:
Isuru Samarathunga
2025-11-11 09:24:14 +05:30
parent 67cb23d589
commit 9d6f525b81
33 changed files with 654 additions and 285 deletions

View File

@ -0,0 +1,108 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <UI/TabContainer.hpp>
namespace ia::iae
{
INT32 g_tabContainerCount{0};
TabContainer::TabContainer() : m_containerID(BuildString("TabContainer##", g_tabContainerCount++)), m_tabBarID(BuildString("TabBar##", g_tabContainerCount++))
{
}
VOID TabContainer::Initialize()
{
}
VOID TabContainer::Terminate()
{
for (const auto &t : m_tabViews)
RemoveTab(t->Key);
}
VOID TabContainer::Draw(IN ImVec2 position, IN ImVec2 size)
{
ImGui::Begin(m_containerID.c_str(), nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoTitleBar);
ImGui::SetWindowPos(position);
ImGui::SetWindowSize(size);
ImGui::BeginTabBar(m_tabBarID.c_str());
for (const auto &v : m_tabViews)
{
ImGuiTabItemFlags flags{};
if (m_pendingActiveTabName && m_pendingActiveTabName == v->Key)
{
flags |= ImGuiTabItemFlags_SetSelected;
m_pendingActiveTabName = nullptr;
}
if (ImGui::BeginTabItem(v->Value->IconAndName().c_str(), nullptr, flags))
{
v->Value->Render();
ImGui::EndTabItem();
m_activeTabName = v->Key.c_str();
}
}
ImGui::EndTabBar();
ImGui::End();
}
VOID TabContainer::Update()
{
for (const auto &t : m_tabViews)
t->Value->Update();
}
VOID TabContainer::ProcessEvent(IN SDL_Event *event)
{
for (const auto &t : m_tabViews)
t->Value->ProcessEvent(event);
}
VOID TabContainer::AddTab(IN CONST String &name, IN IView *view)
{
RemoveTab(name);
view->Initialize();
m_tabViews[name] = view;
if (!m_activeTabName)
m_activeTabName = name.c_str();
}
VOID TabContainer::RemoveTab(IN CONST String &name)
{
if (!m_tabViews.contains(name))
return;
if (m_tabViews[name])
m_tabViews[name]->Terminate();
delete m_tabViews[name];
m_tabViews[name] = nullptr;
}
VOID TabContainer::ChangeActiveTab(IN PCCHAR name)
{
m_pendingActiveTabName = name;
}
IView *TabContainer::GetTab(IN CONST String &name)
{
return m_tabViews[name];
}
} // namespace ia::iae