Reorder threads by drag and drop.

This commit is contained in:
Bartosz Taudul 2019-07-11 20:28:04 +02:00
parent 29d8911c6b
commit 689f4999e3
2 changed files with 51 additions and 29 deletions

View File

@ -5543,37 +5543,26 @@ void View::DrawOptions()
} }
} }
int idIdx = 0; const auto wposx = ImGui::GetCursorScreenPos().x;
m_threadDnd.clear();
int idx = 0; int idx = 0;
int upIdx = -1;
int downIdx = -1;
for( const auto& t : m_threadOrder ) for( const auto& t : m_threadOrder )
{ {
ImGui::PushID( idIdx++ ); m_threadDnd.push_back( ImGui::GetCursorScreenPos().y );
#ifdef TRACY_EXTENDED_FONT ImGui::PushID( idx );
if( ImGui::SmallButton( ICON_FA_CARET_UP ) ) const auto threadName = m_worker.GetThreadString( t->id );
#else SmallCheckbox( threadName, &Vis( t ).visible );
if( ImGui::SmallButton( "^" ) ) if( ImGui::BeginDragDropSource( ImGuiDragDropFlags_SourceNoHoldToOpenOthers ) )
#endif
{ {
upIdx = idx; ImGui::SetDragDropPayload( "ThreadOrder", &idx, sizeof(int) );
}
ImGui::PopID();
ImGui::SameLine();
ImGui::PushID( idIdx++ );
#ifdef TRACY_EXTENDED_FONT #ifdef TRACY_EXTENDED_FONT
if( ImGui::SmallButton( ICON_FA_CARET_DOWN ) ) ImGui::TextUnformatted( ICON_FA_RANDOM );
#else ImGui::SameLine();
if( ImGui::SmallButton( "v" ) )
#endif #endif
{ ImGui::TextUnformatted( threadName );
downIdx = idx; ImGui::EndDragDropSource();
} }
ImGui::PopID(); ImGui::PopID();
ImGui::SameLine();
ImGui::PushID( idIdx++ );
SmallCheckbox( m_worker.GetThreadString( t->id ), &Vis( t ).visible );
ImGui::PopID();
if( crash.thread == t->id ) if( crash.thread == t->id )
{ {
ImGui::SameLine(); ImGui::SameLine();
@ -5601,13 +5590,45 @@ void View::DrawOptions()
ImGui::TextDisabled( "%s top level zones", RealToString( t->timeline.size(), true ) ); ImGui::TextDisabled( "%s top level zones", RealToString( t->timeline.size(), true ) );
idx++; idx++;
} }
if( upIdx > 0 ) if( m_threadDnd.size() > 1 )
{ {
std::swap( m_threadOrder[upIdx], m_threadOrder[upIdx-1] ); const auto w = ImGui::GetContentRegionAvail().x;
} const auto dist = m_threadDnd[1] - m_threadDnd[0];
if( downIdx >= 0 && (size_t)downIdx < m_threadOrder.size() - 1 ) const auto half = dist * 0.5f;
{ m_threadDnd.push_back( m_threadDnd.back() + dist );
std::swap( m_threadOrder[downIdx], m_threadOrder[downIdx+1] );
int target = -1;
int source;
for( size_t i=0; i<m_threadDnd.size(); i++ )
{
if( ImGui::BeginDragDropTargetCustom( ImRect( wposx, m_threadDnd[i] - half, wposx + w, m_threadDnd[i] + half ), i+1 ) )
{
auto draw = ImGui::GetWindowDrawList();
draw->AddLine( ImVec2( wposx, m_threadDnd[i] ), ImVec2( wposx + w, m_threadDnd[i] ), ImGui::GetColorU32(ImGuiCol_DragDropTarget), 2.f );
if( auto payload = ImGui::AcceptDragDropPayload( "ThreadOrder", ImGuiDragDropFlags_AcceptNoDrawDefaultRect ) )
{
target = (int)i;
source = *(int*)payload->Data;
}
ImGui::EndDragDropTarget();
}
}
if( target >= 0 && target != source )
{
const auto srcval = m_threadOrder[source];
if( target < source )
{
assert( source < m_threadOrder.size() );
m_threadOrder.erase( m_threadOrder.begin() + source );
m_threadOrder.insert( m_threadOrder.begin() + target, srcval );
}
else
{
assert( target <= m_threadOrder.size() );
m_threadOrder.insert( m_threadOrder.begin() + target, srcval );
m_threadOrder.erase( m_threadOrder.begin() + source );
}
}
} }
ImGui::TreePop(); ImGui::TreePop();
} }

View File

@ -202,6 +202,7 @@ private:
flat_hash_map<const void*, int, nohash<const void*>> m_gpuDrift; flat_hash_map<const void*, int, nohash<const void*>> m_gpuDrift;
flat_hash_map<const PlotData*, PlotView, nohash<const PlotData*>> m_plotView; flat_hash_map<const PlotData*, PlotView, nohash<const PlotData*>> m_plotView;
Vector<const ThreadData*> m_threadOrder; Vector<const ThreadData*> m_threadOrder;
Vector<float> m_threadDnd;
tracy_force_inline VisData& Vis( const void* ptr ) tracy_force_inline VisData& Vis( const void* ptr )
{ {