From f0c77b4ef4801496682a3566db9178f60d2fdec1 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 14 Oct 2019 20:37:24 +0200 Subject: [PATCH] Add annotation list window. --- server/TracyView.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++ server/TracyView.hpp | 2 ++ 2 files changed, 83 insertions(+) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 5f4f7ad4..98f35fb1 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -582,6 +582,15 @@ bool View::DrawImpl() { m_showCpuDataWindow = true; } + const auto anncnt = m_annotations.size(); +#ifdef TRACY_EXTENDED_FONT + if( ButtonDisablable( ICON_FA_STICKY_NOTE " Annotations", anncnt == 0 ) ) +#else + if( ButtonDisablable( "Annotations", , anncnt == 0) ) +#endif + { + m_showAnnotationList = true; + } ImGui::EndPopup(); } ImGui::SameLine(); @@ -693,6 +702,7 @@ bool View::DrawImpl() if( m_showPlayback ) DrawPlayback(); if( m_showCpuDataWindow ) DrawCpuDataWindow(); if( m_selectedAnnotation ) DrawSelectedAnnotation(); + if( m_showAnnotationList ) DrawAnnotationList(); if( m_zoomAnim.active ) { @@ -11593,6 +11603,77 @@ void View::DrawSelectedAnnotation() if( !show ) m_selectedAnnotation = nullptr; } +void View::DrawAnnotationList() +{ + ImGui::SetNextWindowSize( ImVec2( 500, 300 ), ImGuiCond_FirstUseEver ); + ImGui::Begin( "Annotation list", &m_showAnnotationList ); + if( m_annotations.empty() ) + { + ImGui::TextWrapped( "No annotations." ); + ImGui::End(); + return; + } + + TextFocused( "Annotations:", RealToString( m_annotations.size(), true ) ); + ImGui::SameLine(); + DrawHelpMarker( "Press ctrl to unlock removal" ); + ImGui::Separator(); + ImGui::BeginChild( "##annotationList" ); + const bool ctrl = ImGui::GetIO().KeyCtrl; + int remove = -1; + int idx = 0; + for( auto& ann : m_annotations ) + { + ImGui::PushID( idx ); +#ifdef TRACY_EXTENDED_FONT + if( ImGui::Button( ICON_FA_EDIT ) ) +#else + if( ImGui::Button( "Edit" ) ) +#endif + { + m_selectedAnnotation = ann.get(); + } + ImGui::SameLine(); +#ifdef TRACY_EXTENDED_FONT + if( ImGui::Button( ICON_FA_MICROSCOPE ) ) +#else + if( ImGui::Button( "Zoom" ) ) +#endif + { + ZoomToRange( ann->start, ann->end ); + } + ImGui::SameLine(); +#ifdef TRACY_EXTENDED_FONT + if( ButtonDisablable( ICON_FA_TRASH_ALT, !ctrl ) ) +#else + if( ButtonDisablable( "Remove", !ctrl ) ) +#endif + { + remove = idx; + } + ImGui::SameLine(); + ImGui::ColorButton( "c", ImGui::ColorConvertU32ToFloat4( ann->color ), ImGuiColorEditFlags_NoTooltip ); + ImGui::SameLine(); + if( ann->text.empty() ) + { + TextDisabledUnformatted( "Empty annotation" ); + } + else + { + ImGui::TextUnformatted( ann->text.c_str() ); + } + ImGui::PopID(); + idx++; + } + if( remove >= 0 ) + { + if( m_annotations[remove].get() == m_selectedAnnotation ) m_selectedAnnotation = nullptr; + m_annotations.erase( m_annotations.begin() + remove ); + } + ImGui::EndChild(); + ImGui::End(); +} + template void View::ListMemData( T ptr, T end, std::function DrawAddress, const char* id, int64_t startTime ) { diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 7ae4bbfd..6d5345a5 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -140,6 +140,7 @@ private: void DrawPlayback(); void DrawCpuDataWindow(); void DrawSelectedAnnotation(); + void DrawAnnotationList(); template void ListMemData( T ptr, T end, std::function DrawAddress, const char* id = nullptr, int64_t startTime = -1 ); @@ -299,6 +300,7 @@ private: bool m_showPlayback = false; bool m_showCpuDataWindow = false; bool m_goToFrame = false; + bool m_showAnnotationList = false; enum class CpuDataSortBy {