Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically collapse tabs #119

Merged
merged 4 commits into from
Aug 26, 2024
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
49 changes: 41 additions & 8 deletions src/AIAC/LayerUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ namespace AIAC
m_LogoLightClr = AIAC::Image(AIAC_LOGO_COLOR);

// Set panes UI for layers
// Label Collapse PaneContent
StackPane(PaneUI("Camera", false, AIAC_BIND_EVENT_FN(SetPaneUICamera) ));
StackPane(PaneUI("Mapping", false, AIAC_BIND_EVENT_FN(SetPaneUISlam) ));
StackPane(PaneUI("ACIM (Execution model)", false, AIAC_BIND_EVENT_FN(SetPaneUIACIM) ));
StackPane(PaneUI("Toolhead", false, AIAC_BIND_EVENT_FN(SetPaneUIToolhead), AIAC_BIND_EVENT_FN(OnCollapsingPaneUIToolhead)));
StackPane(PaneUI("Utils", false, AIAC_BIND_EVENT_FN(SetPaneUIUtils) ));
// Label Collapse PaneContent
StackPane(PaneUI("Camera", false, AIAC_BIND_EVENT_FN(SetPaneUICamera) ));
StackPane(PaneUI("Mapping", false, AIAC_BIND_EVENT_FN(SetPaneUISlam) ));
StackPane(PaneUI("ACIM (Execution model)", false, AIAC_BIND_EVENT_FN(SetPaneUIACIM) ));
StackPane(PaneUI("Toolhead", false, AIAC_BIND_EVENT_FN(SetPaneUIToolhead), AIAC_BIND_EVENT_FN(OnCollapsingPaneUIToolhead)));
StackPane(PaneUI("Utils", false, AIAC_BIND_EVENT_FN(SetPaneUIUtils) ));

m_IsOpen = new bool(true);
}
Expand Down Expand Up @@ -174,6 +174,39 @@ namespace AIAC
ImGui::DestroyContext();
}

template<typename... Args>
void PaneUI::Show(Args &&... args) {
bool isOpened = ImGui::CollapsingHeader(m_Label, m_IsCollapsed ? ImGuiTreeNodeFlags_DefaultOpen : 0);
if (isOpened) {
// if this one is not opened yet, close the previously opened one
if (m_CollapseState != CollapseState::OPEN) {
auto lastOpenedPaneUI = AIAC_APP.GetLayer<LayerUI>()->GetOpenedPaneUI();
if (lastOpenedPaneUI != nullptr && lastOpenedPaneUI->m_Label != m_Label) {
ImGui::GetStateStorage()->SetInt(ImGui::GetID(lastOpenedPaneUI->m_Label), 0);
lastOpenedPaneUI->Show();
}
AIAC_APP.GetLayer<LayerUI>()->SetOpenedPaneUI(this);
}
m_CollapseState = CollapseState::OPEN;
m_func(std::forward<Args>(args)...);
}

// check if it's just collapsed
if (!isOpened) {
if (m_CollapseState == CollapseState::OPEN) {
m_CollapseState = CollapseState::ON_COLLAPSING;
}
}
}

template<typename... Args>
void PaneUI::CheckOnCollapsing(Args &&... args) {
if (m_CollapseState == CollapseState::ON_COLLAPSING) {
m_onCollapseCallback(std::forward<Args>(args)...);
m_CollapseState = CollapseState::COLLAPSE;
}
}

void LayerUI::ShowMenuBar()
{
if (ImGui::BeginMainMenuBar())
Expand Down Expand Up @@ -204,8 +237,8 @@ namespace AIAC
#endif

for (auto& pane : m_PaneUIStack) {
pane->Show();
pane->CheckOnCollapsing();
pane.Show();
pane.CheckOnCollapsing();
}

ImGui::End();
Expand Down
29 changes: 7 additions & 22 deletions src/AIAC/LayerUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,10 @@ namespace AIAC {
}

template<typename... Args>
void Show(Args &&... args) {
bool isOpened = ImGui::CollapsingHeader(m_Label, m_IsCollapsed ? ImGuiTreeNodeFlags_DefaultOpen : 0);
if (isOpened) {
m_CollapseState = CollapseState::OPEN;
m_func(std::forward<Args>(args)...);
}

// check if it's just collapsed
if (!isOpened) {
if (m_CollapseState == CollapseState::OPEN) {
m_CollapseState = CollapseState::ON_COLLAPSING;
}
}
}
void Show(Args &&... args);

template<typename... Args>
void CheckOnCollapsing(Args &&... args) {
if (m_CollapseState == CollapseState::ON_COLLAPSING) {
m_onCollapseCallback();
m_CollapseState = CollapseState::COLLAPSE;
}
}
void CheckOnCollapsing(Args &&... args);

private:
CollapseState m_CollapseState;
Expand Down Expand Up @@ -95,13 +77,15 @@ namespace AIAC {

void ShowLogRecorderUI();

inline void StackPane(PaneUI pane) { m_PaneUIStack.push_back(std::make_shared<PaneUI>(pane)); }
inline void StackPane(PaneUI pane) { m_PaneUIStack.emplace_back(std::move(pane)); }
void SetPaneUICamera();
void SetPaneUISlam();
void SetPaneUIToolhead();
void OnCollapsingPaneUIToolhead();
void SetPaneUIACIM();
void SetPaneUIUtils();
PaneUI* GetOpenedPaneUI() { return m_OpenedPaneUI; }
void SetOpenedPaneUI(PaneUI* paneUI) { m_OpenedPaneUI = paneUI; }

private:
void SetGlobalViewUI(ImVec2 viewportSize);
Expand All @@ -125,7 +109,8 @@ namespace AIAC {

bool *m_IsOpen = nullptr;

std::vector<std::shared_ptr<PaneUI>> m_PaneUIStack;
std::vector<PaneUI> m_PaneUIStack;
PaneUI* m_OpenedPaneUI = nullptr;

// UI File Selection
std::string m_FileSelectDefaultPath = ".";
Expand Down
Loading