Last active
August 12, 2021 02:04
-
-
Save thennequin/3482a9b71bcbc42292c2e6b126f4a7fb to your computer and use it in GitHub Desktop.
ImGui scrollable columns with header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////// | |
// Exemple | |
/////////////////////////////// | |
Core::ImGuiPlus::StackId oStackId( "Columns" ); | |
ImGui::Columns( 3 ); | |
ImGui::Text( "Header1" ); | |
ImGui::NextColumn(); | |
ImGui::Text( "Header2" ); | |
ImGui::NextColumn(); | |
ImGui::Text( "Header3" ); | |
ImGui::NextColumn(); | |
ImGui::Columns(); | |
oStackId.Pop(); | |
ImGui::Separator(); | |
ImGui::BeginChild( "Columns", ImGui::GetContentRegionAvail() ); | |
oStackId.Push(); | |
ImGui::Columns( 3 ); | |
for( int I = 0; I < 150; ++I ) | |
{ | |
ImGui::Text( "Test1" ); | |
ImGui::NextColumn(); | |
ImGui::Text( "Test2" ); | |
ImGui::NextColumn(); | |
ImGui::Text( "Test3" ); | |
ImGui::NextColumn(); | |
} | |
ImGui::Columns(); | |
oStackId.Pop(); | |
ImGui::EndChild(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////// | |
// Source | |
/////////////////////////////// | |
StackId::StackId( const char* pString ) | |
{ | |
m_bPushed = false; | |
m_iId = ImGui::GetID( pString ); | |
Push(); | |
} | |
StackId::StackId( void* pData ) | |
{ | |
m_bPushed = false; | |
m_iId = ImGui::GetID( pData ); | |
Push(); | |
} | |
StackId::StackId( int iId ) | |
{ | |
m_bPushed = false; | |
m_iId = ImGui::GetID( (const void*)iId ); | |
Push(); | |
} | |
StackId::~StackId() | |
{ | |
if( m_bPushed ) | |
Pop(); | |
} | |
void StackId::Push() | |
{ | |
IM_ASSERT( m_bPushed == false ); | |
m_bPushed = true; | |
ImGuiWindow* pWindow = ImGui::GetCurrentWindow(); | |
pWindow->IDStack.push_back( m_iId ); | |
} | |
void StackId::Pop() | |
{ | |
IM_ASSERT( m_bPushed == true ); | |
m_bPushed = false; | |
ImGuiWindow* pWindow = ImGui::GetCurrentWindow(); | |
pWindow->IDStack.pop_back(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////// | |
// Header | |
/////////////////////////////// | |
class StackId | |
{ | |
public: | |
StackId( const char* pString ); | |
StackId( void* pData ); | |
StackId( int iId ); | |
~StackId(); | |
void Push(); | |
void Pop(); | |
protected: | |
ImGuiID m_iId; | |
bool m_bPushed; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment