Skip to content

Commit b329eb1

Browse files
committed
Change way of updating fonts in View.
This makes the whole process more easy to follow. It also fixes a crash bug that was occuring when Wayland output scale changed.
1 parent bdfcc5b commit b329eb1

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

profiler/src/Fonts.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ImFont* s_bigFont;
1414
ImFont* s_smallFont;
1515
ImFont* s_fixedWidth;
1616

17-
void LoadFonts( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigFont, ImFont*& cb_smallFont )
17+
void LoadFonts( float scale )
1818
{
1919
static const ImWchar rangesBasic[] = {
2020
0x0020, 0x00FF, // Basic Latin + Latin Supplement
@@ -49,10 +49,10 @@ void LoadFonts( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigFont, ImFont
4949
io.Fonts->Clear();
5050
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 15.0f * scale ), &configBasic, rangesBasic );
5151
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, round( 14.0f * scale ), &configMerge, rangesIcons );
52-
s_fixedWidth = cb_fixedWidth = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FiraCodeRetina_compressed_data, tracy::FiraCodeRetina_compressed_size, round( 15.0f * scale ), &configFixed, rangesFixed );
53-
s_bigFont = cb_bigFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 21.0f * scale ), &configBasic );
52+
s_fixedWidth = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FiraCodeRetina_compressed_data, tracy::FiraCodeRetina_compressed_size, round( 15.0f * scale ), &configFixed, rangesFixed );
53+
s_bigFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 21.0f * scale ), &configBasic );
5454
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, round( 20.0f * scale ), &configMerge, rangesIcons );
55-
s_smallFont = cb_smallFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 10.0f * scale ), &configBasic );
55+
s_smallFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 10.0f * scale ), &configBasic );
5656

5757
ImGui_ImplOpenGL3_DestroyFontsTexture();
5858
ImGui_ImplOpenGL3_CreateFontsTexture();

profiler/src/Fonts.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ extern ImFont* s_bigFont;
77
extern ImFont* s_smallFont;
88
extern ImFont* s_fixedWidth;
99

10-
void LoadFonts( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigFont, ImFont*& cb_smallFont );
10+
void LoadFonts( float scale );
1111

1212
#endif

profiler/src/main.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ static void RunOnMainThread( const std::function<void()>& cb, bool forceDelay =
133133
mainThreadTasks.Queue( cb, forceDelay );
134134
}
135135

136-
static void SetupDPIScale( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigFont, ImFont*& cb_smallFont )
136+
static void SetupDPIScale( float scale )
137137
{
138-
LoadFonts( scale, cb_fixedWidth, cb_bigFont, cb_smallFont );
138+
LoadFonts( scale );
139+
if( view ) view->UpdateFont( s_fixedWidth, s_smallFont, s_bigFont );
139140

140141
#ifdef __APPLE__
141142
// No need to upscale the style on macOS, but we need to downscale the fonts.
@@ -164,9 +165,9 @@ static void SetupDPIScale( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigF
164165
delete[] scaleIcon;
165166
}
166167

167-
static void SetupScaleCallback( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigFont, ImFont*& cb_smallFont )
168+
static void SetupScaleCallback( float scale )
168169
{
169-
RunOnMainThread( [scale, &cb_fixedWidth, &cb_bigFont, &cb_smallFont] { SetupDPIScale( scale * dpiScale, cb_fixedWidth, cb_bigFont, cb_smallFont ); }, true );
170+
RunOnMainThread( [scale] { SetupDPIScale( scale * dpiScale ); }, true );
170171
}
171172

172173
static void LoadConfig()
@@ -204,7 +205,7 @@ static void ScaleChanged( float scale )
204205
if ( dpiScale == scale ) return;
205206

206207
dpiScale = scale;
207-
SetupDPIScale( dpiScale, s_fixedWidth, s_bigFont, s_smallFont );
208+
SetupDPIScale( dpiScale );
208209
}
209210

210211
int main( int argc, char** argv )
@@ -327,7 +328,7 @@ int main( int argc, char** argv )
327328
}
328329
}
329330

330-
SetupDPIScale( dpiScale, s_fixedWidth, s_bigFont, s_smallFont );
331+
SetupDPIScale( dpiScale );
331332

332333
tracy::UpdateTextureRGBAMips( zigzagTex, (void**)zigzagPx, zigzagX, zigzagY, 6 );
333334
for( auto& v : zigzagPx ) free( v );

server/TracyView.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -892,19 +892,19 @@ bool View::DrawImpl()
892892
if( ImGui::Button( ICON_FA_MAGNIFYING_GLASS_PLUS ) ) ImGui::OpenPopup( "ZoomPopup" );
893893
if( ImGui::BeginPopup( "ZoomPopup" ) )
894894
{
895-
if( ImGui::Button( "50%" ) ) m_sscb( 1.f/2, m_fixedFont, m_bigFont, m_smallFont );
896-
if( ImGui::Button( "57%" ) ) m_sscb( 1.f/1.75f, m_fixedFont, m_bigFont, m_smallFont );
897-
if( ImGui::Button( "66%" ) ) m_sscb( 1.f/1.5f, m_fixedFont, m_bigFont, m_smallFont );
898-
if( ImGui::Button( "80%" ) ) m_sscb( 1.f/1.25f, m_fixedFont, m_bigFont, m_smallFont );
899-
if( ImGui::Button( "100%" ) ) m_sscb( 1.f, m_fixedFont, m_bigFont, m_smallFont );
900-
if( ImGui::Button( "125%" ) ) m_sscb( 1.25f, m_fixedFont, m_bigFont, m_smallFont );
901-
if( ImGui::Button( "150%" ) ) m_sscb( 1.5f, m_fixedFont, m_bigFont, m_smallFont );
902-
if( ImGui::Button( "175%" ) ) m_sscb( 1.75f, m_fixedFont, m_bigFont, m_smallFont );
903-
if( ImGui::Button( "200%" ) ) m_sscb( 2.f, m_fixedFont, m_bigFont, m_smallFont );
904-
if( ImGui::Button( "225%" ) ) m_sscb( 2.25f, m_fixedFont, m_bigFont, m_smallFont );
905-
if( ImGui::Button( "250%" ) ) m_sscb( 2.5f, m_fixedFont, m_bigFont, m_smallFont );
906-
if( ImGui::Button( "275%" ) ) m_sscb( 2.75f, m_fixedFont, m_bigFont, m_smallFont );
907-
if( ImGui::Button( "300%" ) ) m_sscb( 3.f, m_fixedFont, m_bigFont, m_smallFont );
895+
if( ImGui::Button( "50%" ) ) m_sscb( 1.f/2 );
896+
if( ImGui::Button( "57%" ) ) m_sscb( 1.f/1.75f );
897+
if( ImGui::Button( "66%" ) ) m_sscb( 1.f/1.5f );
898+
if( ImGui::Button( "80%" ) ) m_sscb( 1.f/1.25f );
899+
if( ImGui::Button( "100%" ) ) m_sscb( 1.f );
900+
if( ImGui::Button( "125%" ) ) m_sscb( 1.25f );
901+
if( ImGui::Button( "150%" ) ) m_sscb( 1.5f );
902+
if( ImGui::Button( "175%" ) ) m_sscb( 1.75f );
903+
if( ImGui::Button( "200%" ) ) m_sscb( 2.f );
904+
if( ImGui::Button( "225%" ) ) m_sscb( 2.25f );
905+
if( ImGui::Button( "250%" ) ) m_sscb( 2.5f );
906+
if( ImGui::Button( "275%" ) ) m_sscb( 2.75f );
907+
if( ImGui::Button( "300%" ) ) m_sscb( 3.f );
908908
ImGui::EndPopup();
909909
}
910910
}

server/TracyView.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class View
100100
};
101101

102102
using SetTitleCallback = void(*)( const char* );
103-
using SetScaleCallback = void(*)( float, ImFont*&, ImFont*&, ImFont*& );
103+
using SetScaleCallback = void(*)( float );
104104
using AttentionCallback = void(*)();
105105

106106
View( void(*cbMainThread)(const std::function<void()>&, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config );
@@ -110,6 +110,8 @@ class View
110110
bool Draw();
111111
bool WasActive() const;
112112

113+
void UpdateFont( ImFont* fixed, ImFont* small, ImFont* big ) { m_fixedFont = fixed; m_smallFont = small; m_bigFont = big; }
114+
113115
void NotifyRootWindowSize( float w, float h ) { m_rootWidth = w; m_rootHeight = h; }
114116
void ViewSource( const char* fileName, int line );
115117
void ViewSource( const char* fileName, int line, const char* functionName );

0 commit comments

Comments
 (0)