Skip to content

Instantly share code, notes, and snippets.

@thennequin
Last active August 12, 2021 02:04
Show Gist options
  • Save thennequin/3482a9b71bcbc42292c2e6b126f4a7fb to your computer and use it in GitHub Desktop.
Save thennequin/3482a9b71bcbc42292c2e6b126f4a7fb to your computer and use it in GitHub Desktop.
ImGui scrollable columns with header
///////////////////////////////
// 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();
///////////////////////////////
// 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();
}
///////////////////////////////
// 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