Handle window title setter callback in View.

This commit is contained in:
Bartosz Taudul 2018-08-17 17:24:18 +02:00
parent b24d9fa044
commit 2b3490e6f7
2 changed files with 24 additions and 11 deletions

View File

@ -294,7 +294,7 @@ enum { MinFrameSize = 5 };
static View* s_instance = nullptr; static View* s_instance = nullptr;
View::View( const char* addr, ImFont* fixedWidth ) View::View( const char* addr, ImFont* fixedWidth, SetTitleCallback stcb )
: m_worker( addr ) : m_worker( addr )
, m_staticView( false ) , m_staticView( false )
, m_frameScale( 0 ) , m_frameScale( 0 )
@ -331,6 +331,8 @@ View::View( const char* addr, ImFont* fixedWidth )
, m_statSelf( false ) , m_statSelf( false )
, m_namespace( Namespace::Full ) , m_namespace( Namespace::Full )
, m_textEditorFont( fixedWidth ) , m_textEditorFont( fixedWidth )
, m_stcb( stcb )
, m_titleSet( false )
{ {
assert( s_instance == nullptr ); assert( s_instance == nullptr );
s_instance = this; s_instance = this;
@ -341,7 +343,7 @@ View::View( const char* addr, ImFont* fixedWidth )
InitTextEditor(); InitTextEditor();
} }
View::View( FileRead& f, ImFont* fixedWidth ) View::View( FileRead& f, ImFont* fixedWidth, SetTitleCallback stcb )
: m_worker( f ) : m_worker( f )
, m_staticView( true ) , m_staticView( true )
, m_frameScale( 0 ) , m_frameScale( 0 )
@ -377,6 +379,8 @@ View::View( FileRead& f, ImFont* fixedWidth )
, m_statSelf( false ) , m_statSelf( false )
, m_namespace( Namespace::Full ) , m_namespace( Namespace::Full )
, m_textEditorFont( fixedWidth ) , m_textEditorFont( fixedWidth )
, m_stcb( stcb )
, m_titleSet( false )
{ {
assert( s_instance == nullptr ); assert( s_instance == nullptr );
s_instance = this; s_instance = this;
@ -517,12 +521,13 @@ bool View::DrawImpl()
keepOpenPtr = &keepOpen; keepOpenPtr = &keepOpen;
} }
std::lock_guard<TracyMutex> lock( m_worker.GetDataLock() );
char tmp[2048];
sprintf( tmp, "%s###Profiler", m_worker.GetCaptureName().c_str() );
ImGui::SetNextWindowSize( ImVec2( 1550, 800 ), ImGuiCond_FirstUseEver );
#ifdef TRACY_ROOT_WINDOW #ifdef TRACY_ROOT_WINDOW
if( !m_titleSet && m_stcb )
{
m_titleSet = true;
m_stcb( m_worker.GetCaptureName().c_str() );
}
auto& style = ImGui::GetStyle(); auto& style = ImGui::GetStyle();
const auto wrPrev = style.WindowRounding; const auto wrPrev = style.WindowRounding;
const auto wbsPrev = style.WindowBorderSize; const auto wbsPrev = style.WindowBorderSize;
@ -533,15 +538,19 @@ bool View::DrawImpl()
ImGui::SetNextWindowPos( ImVec2( 0, 0 ) ); ImGui::SetNextWindowPos( ImVec2( 0, 0 ) );
ImGui::SetNextWindowSize( ImVec2( m_rootWidth, m_rootHeight ) ); ImGui::SetNextWindowSize( ImVec2( m_rootWidth, m_rootHeight ) );
ImGui::Begin( tmp, nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoMove ); ImGui::Begin( "###Profiler", nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoMove );
style.WindowRounding = wrPrev; style.WindowRounding = wrPrev;
style.WindowBorderSize = wbsPrev; style.WindowBorderSize = wbsPrev;
style.WindowPadding = wpPrev; style.WindowPadding = wpPrev;
#else #else
char tmp[2048];
sprintf( tmp, "%s###Profiler", m_worker.GetCaptureName().c_str() );
ImGui::SetNextWindowSize( ImVec2( 1550, 800 ), ImGuiCond_FirstUseEver );
ImGui::Begin( tmp, keepOpenPtr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoBringToFrontOnFocus ); ImGui::Begin( tmp, keepOpenPtr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoBringToFrontOnFocus );
#endif #endif
std::lock_guard<TracyMutex> lock( m_worker.GetDataLock() );
if( !m_worker.IsDataStatic() ) if( !m_worker.IsDataStatic() )
{ {
if( ImGui::Button( m_pause ? MainWindowButtons[0] : MainWindowButtons[1], ImVec2( bw, 0 ) ) ) m_pause = !m_pause; if( ImGui::Button( m_pause ? MainWindowButtons[0] : MainWindowButtons[1], ImVec2( bw, 0 ) ) ) m_pause = !m_pause;

View File

@ -43,9 +43,11 @@ class View
}; };
public: public:
View( ImFont* fixedWidth = nullptr ) : View( "127.0.0.1", fixedWidth ) {} using SetTitleCallback = void(*)( const char* );
View( const char* addr, ImFont* fixedWidth = nullptr );
View( FileRead& f, ImFont* fixedWidth = nullptr ); View( ImFont* fixedWidth = nullptr, SetTitleCallback stcb = nullptr ) : View( "127.0.0.1", fixedWidth, stcb ) {}
View( const char* addr, ImFont* fixedWidth = nullptr, SetTitleCallback stcb = nullptr );
View( FileRead& f, ImFont* fixedWidth = nullptr, SetTitleCallback stcb = nullptr );
~View(); ~View();
static bool Draw(); static bool Draw();
@ -243,6 +245,8 @@ private:
ImFont* m_textEditorFont; ImFont* m_textEditorFont;
float m_rootWidth, m_rootHeight; float m_rootWidth, m_rootHeight;
SetTitleCallback m_stcb;
bool m_titleSet;
struct FindZone { struct FindZone {
enum : uint64_t { Unselected = std::numeric_limits<uint64_t>::max() - 1 }; enum : uint64_t { Unselected = std::numeric_limits<uint64_t>::max() - 1 };