Skip to content

Commit 9c4d2ed

Browse files
committed
fix: font loading order .ttc first, remove Build() calls, status bar rendering
1 parent e574c94 commit 9c4d2ed

1 file changed

Lines changed: 55 additions & 12 deletions

File tree

src/editor_app.cpp

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -768,28 +768,69 @@ void EditorApp::clear_change_history() {
768768
void EditorApp::load_fonts() {
769769
ImGuiIO& io = ImGui::GetIO();
770770

771-
// Just add default font - we'll control size via FontGlobalScale
772-
io.Fonts->AddFontDefault();
771+
// Clear existing fonts first
772+
io.Fonts->Clear();
773773

774-
// Store font size temp
775-
font_size_temp_ = settings_.font_size;
774+
ImFont* font = nullptr;
776775

777-
// Font texture is built automatically by the renderer on first use
776+
// Try to load user-selected font
777+
if (!settings_.font_name.empty()) {
778+
#ifdef _WIN32
779+
std::vector<std::string> exts = {".ttc", ".ttf", ".otf"}; // Try .ttc first
780+
for (const auto& ext : exts) {
781+
std::string path = "C:/Windows/Fonts/" + settings_.font_name + ext;
782+
font = io.Fonts->AddFontFromFileTTF(path.c_str(), (float)settings_.font_size);
783+
if (font) break;
784+
}
785+
#endif
786+
}
778787

779-
// Apply initial font scale
788+
// Fallback to default
789+
if (!font) {
790+
font = io.Fonts->AddFontDefault();
791+
}
792+
793+
font_size_temp_ = settings_.font_size;
794+
font_name_temp_ = settings_.font_name;
795+
796+
// Don't call Build() - the backend handles it automatically on first render
797+
// Just set the global scale
780798
float scale = (float)settings_.font_size / 16.0f;
781799
io.FontGlobalScale = scale;
782800
}
783801

784802
void EditorApp::rebuild_fonts() {
785-
// Use font global scale to adjust font size - more stable than rebuilding
786803
ImGuiIO& io = ImGui::GetIO();
787804

788-
// Get the base font size from settings
789-
float base_size = (float)settings_.font_size;
805+
// Update font size
806+
settings_.font_size = font_size_temp_;
807+
settings_.font_name = font_name_temp_;
808+
809+
// Clear and rebuild fonts
810+
io.Fonts->Clear();
811+
812+
ImFont* font = nullptr;
790813

791-
// Calculate scale relative to default 16px
792-
float scale = base_size / 16.0f;
814+
// Try to load user-selected font
815+
if (!settings_.font_name.empty()) {
816+
#ifdef _WIN32
817+
std::vector<std::string> exts = {".ttc", ".ttf", ".otf"}; // Try .ttc first
818+
for (const auto& ext : exts) {
819+
std::string path = "C:/Windows/Fonts/" + settings_.font_name + ext;
820+
font = io.Fonts->AddFontFromFileTTF(path.c_str(), (float)settings_.font_size);
821+
if (font) break;
822+
}
823+
#endif
824+
}
825+
826+
// Fallback to default
827+
if (!font) {
828+
font = io.Fonts->AddFontDefault();
829+
}
830+
831+
// Don't call Build() - the backend handles it automatically
832+
// Just apply scale
833+
float scale = (float)settings_.font_size / 16.0f;
793834
io.FontGlobalScale = scale;
794835
}
795836

@@ -897,7 +938,6 @@ void EditorApp::render() {
897938

898939
render_menu_bar();
899940
render_editor_area();
900-
if (settings_.show_status_bar) render_status_bar();
901941

902942
// Dialogs
903943
if (show_find_) render_find_dialog();
@@ -908,6 +948,9 @@ void EditorApp::render() {
908948
if (show_cmd_palette_) render_command_palette();
909949

910950
ImGui::End();
951+
952+
// Render status bar AFTER DockSpace ends to avoid nesting issues
953+
if (settings_.show_status_bar) render_status_bar();
911954
}
912955

913956
// ============================================================================

0 commit comments

Comments
 (0)