1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-08 23:44:19 +00:00

Examples: Android: update for consistency (untested).

This commit is contained in:
ocornut 2025-12-23 17:57:01 +01:00
parent 05581da183
commit b7b8f52437

View file

@ -156,37 +156,46 @@ void Init(struct android_app* app)
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
// - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author! // - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author!
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
// - Android: The TTF files have to be placed into the assets/ directory (android/app/src/main/assets), we use our GetAssetData() helper to retrieve them.
// We load the default font with increased size to improve readability on many devices with "high" DPI. // Setup scaling
// FIXME: Put some effort into DPI awareness. float main_scale = 2.0f;
ImGuiStyle& style = ImGui::GetStyle();
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
style.FontScaleDpi = main_scale; // Set initial font scale.
// Load Fonts
// - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap().
// This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold.
// - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
// - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit).
// - Read 'docs/FONTS.md' for more instructions and details.
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use FreeType for higher quality font rendering.
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
// - Android: The TTF files have to be placed into the assets/ directory (android/app/src/main/assets), we use our GetAssetData() helper to retrieve them.
//style.FontSizeBase = 20.0f;
//io.Fonts->AddFontDefaultVector();
//io.Fonts->AddFontDefaultBitmap();
// Important: when calling AddFontFromMemoryTTF(), ownership of font_data is transferred by Dear ImGui by default (deleted is handled by Dear ImGui), unless we set FontDataOwnedByAtlas=false in ImFontConfig // Important: when calling AddFontFromMemoryTTF(), ownership of font_data is transferred by Dear ImGui by default (deleted is handled by Dear ImGui), unless we set FontDataOwnedByAtlas=false in ImFontConfig
ImFontConfig font_cfg; //void* font_data;
font_cfg.SizePixels = 22.0f; //int font_data_size;
io.Fonts->AddFontDefault(&font_cfg);
//void* font_data;
//int font_data_size;
//ImFont* font; //ImFont* font;
//font_data_size = GetAssetData("segoeui.ttf", &font_data); //font_data_size = GetAssetData("segoeui.ttf", &font_data);
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 16.0f); //font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size);
//IM_ASSERT(font != nullptr); //IM_ASSERT(font != nullptr);
//font_data_size = GetAssetData("DroidSans.ttf", &font_data); //font_data_size = GetAssetData("DroidSans.ttf", &font_data);
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 16.0f); //font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size);
//IM_ASSERT(font != nullptr); //IM_ASSERT(font != nullptr);
//font_data_size = GetAssetData("Roboto-Medium.ttf", &font_data); //font_data_size = GetAssetData("Roboto-Medium.ttf", &font_data);
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 16.0f); //font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size);
//IM_ASSERT(font != nullptr); //IM_ASSERT(font != nullptr);
//font_data_size = GetAssetData("Cousine-Regular.ttf", &font_data); //font_data_size = GetAssetData("Cousine-Regular.ttf", &font_data);
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 15.0f); //font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size);
//IM_ASSERT(font != nullptr); //IM_ASSERT(font != nullptr);
//font_data_size = GetAssetData("ArialUni.ttf", &font_data); //font_data_size = GetAssetData("ArialUni.ttf", &font_data);
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 18.0f); //font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size);
//IM_ASSERT(font != nullptr); //IM_ASSERT(font != nullptr);
// Arbitrary scale-up
// FIXME: Put some effort into DPI awareness
ImGui::GetStyle().ScaleAllSizes(3.0f);
g_Initialized = true; g_Initialized = true;
} }