[feat] load different size fonts in initialization

This commit is contained in:
dijunkun
2024-11-15 18:19:54 +08:00
parent 84194188f8
commit 59b1208321
2 changed files with 36 additions and 19 deletions

View File

@@ -504,11 +504,9 @@ int Render::DestroyStreamWindow() {
return 0;
}
int Render::SetupFontAndStyle() {
int Render::SetupFontAndStyle(bool is_main_window) {
// Setup Dear ImGui style
ImGuiIO& io = ImGui::GetIO();
// Master keyboard navigation enable flag. Enable full Tabbing + directional
// arrows + space/enter to activate.
io.ConfigFlags |=
ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |=
@@ -518,23 +516,29 @@ int Render::SetupFontAndStyle() {
// Load Fonts
ImFontConfig config;
config.FontDataOwnedByAtlas = false;
io.Fonts->AddFontFromMemoryTTF(OPPOSans_Regular_ttf,
sizeof(OPPOSans_Regular_ttf), 32.0f, &config,
io.Fonts->GetGlyphRangesChineseFull());
(is_main_window ? font_size_32_main_ : font_size_32_sub_) =
io.Fonts->AddFontFromMemoryTTF(
OPPOSans_Regular_ttf, sizeof(OPPOSans_Regular_ttf), 32.0f, &config,
io.Fonts->GetGlyphRangesChineseFull());
config.MergeMode = true;
config.GlyphMinAdvanceX =
13.0f; // Use if you want to make the icon monospaced
(is_main_window ? font_size_25_main_ : font_size_25_sub_) =
io.Fonts->AddFontFromMemoryTTF(
OPPOSans_Regular_ttf, sizeof(OPPOSans_Regular_ttf), 25.0f, &config,
io.Fonts->GetGlyphRangesChineseFull());
(is_main_window ? font_size_16_main_ : font_size_16_sub_) =
io.Fonts->AddFontFromMemoryTTF(
OPPOSans_Regular_ttf, sizeof(OPPOSans_Regular_ttf), 16.0f, &config,
io.Fonts->GetGlyphRangesChineseFull());
static const ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
// io.Fonts->AddFontFromMemoryTTF(fa_regular_400_ttf,
// sizeof(fa_regular_400_ttf),
// 30.0f, &config, icon_ranges);
io.Fonts->AddFontFromMemoryTTF(fa_solid_900_ttf, sizeof(fa_solid_900_ttf),
30.0f, &config, icon_ranges);
(is_main_window ? icon_size_30_main_ : icon_size_30_sub_) =
io.Fonts->AddFontFromMemoryTTF(fa_solid_900_ttf, fa_solid_900_ttf_len,
30.0f, &config, icon_ranges);
(is_main_window ? icon_size_15_main_ : icon_size_15_sub_) =
io.Fonts->AddFontFromMemoryTTF(fa_solid_900_ttf, fa_solid_900_ttf_len,
15.0f, &config, icon_ranges);
io.Fonts->Build();
// Setup Dear ImGui style
// ImGui::StyleColorsDark();
ImGui::StyleColorsLight();
return 0;
@@ -548,7 +552,7 @@ int Render::SetupMainWindow() {
ImGui::SetCurrentContext(main_ctx_);
SetupFontAndStyle();
SetupFontAndStyle(true);
SDL_GL_GetDrawableSize(main_window_, &main_window_width_real_,
&main_window_height_real_);
@@ -588,7 +592,7 @@ int Render::SetupStreamWindow() {
ImGui::SetCurrentContext(stream_ctx_);
SetupFontAndStyle();
SetupFontAndStyle(false);
SDL_GL_GetDrawableSize(stream_window_, &stream_window_width_real_,
&stream_window_height_real_);