mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-11 00:04:24 +00:00
AddFontDefault() now automatically selects an embedded font between AddFontDefaultVector() and AddFontDefaultBitmap).
This commit is contained in:
parent
f006400f05
commit
05581da183
35 changed files with 295 additions and 189 deletions
|
|
@ -51,6 +51,12 @@ Breaking Changes:
|
|||
that are using the "###" operators. (#713, #1698)
|
||||
- Renamed helper macro IM_ARRAYSIZE() -> IM_COUNTOF(). Kept redirection/legacy name.
|
||||
- Fonts:
|
||||
- AddFontDefault() now automatically selects an embedded font between:
|
||||
- AddFontDefaultVector(): new scalable font. Recommended at any higher size.
|
||||
- AddFontDefaultBitmap(): classic pixel-clean font. Recommended at Size 13px with no scaling.
|
||||
- The default selection is based on (style.FontSizeBase * FontScaleMain * FontScaleDpi)
|
||||
reaching a small threshold. Prefer calling either based on your own logic.
|
||||
And you can call AddFontDefaultBitmap() to ensure legacy behavior.
|
||||
- Fixed handling of `ImFontConfig::FontDataOwnedByAtlas = false` which
|
||||
did erroneously make a copy of the font data, essentially defeating the purpose
|
||||
of this flag and wasting memory (undetected since July 2015 and now spotted
|
||||
|
|
@ -76,6 +82,8 @@ Other Changes:
|
|||
be easily and readily used in all contexts, even without file system access.
|
||||
As always you can opt-out of the embedded font data if desired. A sizing tweak
|
||||
was also applied to ensure the new font is a closer match to the classic font.
|
||||
- AddFontDefault() now automatically selects an embedded font between
|
||||
the classic pixel-looking one and the new scalable one.
|
||||
- Fixed an issue related to EllipsisChar handling, while changing
|
||||
font loader or font loader flags dynamically in Style->Fonts menus.
|
||||
- imgui_freetype: fixed overwriting ImFontConfig::PixelSnapH when hinting
|
||||
|
|
|
|||
20
docs/FAQ.md
20
docs/FAQ.md
|
|
@ -658,22 +658,28 @@ Since 1.92 (June 2025) fonts may be dynamically used at any size.
|
|||
|
||||
**Scaling fonts**
|
||||
|
||||
Select default size:
|
||||
```cpp
|
||||
style.FontSizeBase = 20.0f;
|
||||
```
|
||||
Scale all fonts:
|
||||
```cpp
|
||||
style.FontScaleDpi = 2.0f;
|
||||
```
|
||||
|
||||
To change font size:
|
||||
```cpp
|
||||
ImGui::PushFont(NULL, 42.0f);
|
||||
ImGui::PushFont(NULL, 42.0f); // This will be multiplied by style.FontScaleDpi
|
||||
```
|
||||
To change font and font size:
|
||||
```cpp
|
||||
ImGui::PushFont(new_font, 42.0f);
|
||||
```
|
||||
To scale all fonts:
|
||||
```cpp
|
||||
style.FontScaleDpi = 2.0f;
|
||||
```
|
||||
|
||||
In `docking` branch or with multi-viewports:
|
||||
```cpp
|
||||
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||
io.ConfigDpiScaleFonts = true; // Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
|
||||
io.ConfigDpiScaleViewports = true; // Scale Dear ImGui and Platform Windows when Monitor DPI changes.
|
||||
```
|
||||
|
||||
**Scaling style** (paddings, spacings, thicknesses)
|
||||
|
|
|
|||
|
|
@ -89,7 +89,10 @@ See [#8465](https://github.com/ocornut/imgui/issues/8465) for more details.
|
|||
|
||||
## How should I handle DPI in my application?
|
||||
|
||||
See [FAQ entry](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-should-i-handle-dpi-in-my-application).
|
||||
Since 1.92, with an updated backend, you can set `style.FontScaleDpi = your_content_scale;` to scale all fonts.
|
||||
<BR>You can call `style.ScaleAllSizes(xxx)` at init time or every frame at the beginning of your main loop to scale sizes/paddings.
|
||||
<BR>Since 1.92, with an updated backend, macOS style pixel/backing style scale is automatically handled.
|
||||
<BR>See [FAQ entry](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-should-i-handle-dpi-in-my-application) for more details.
|
||||
|
||||
##### [Return to Index](#index)
|
||||
|
||||
|
|
@ -97,10 +100,22 @@ See [FAQ entry](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-s
|
|||
|
||||
## Fonts Loading Instructions
|
||||
|
||||
**Select base size**
|
||||
```cpp
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.FontSizeBase = 20.0f;
|
||||
```
|
||||
|
||||
**Load default font:**
|
||||
```cpp
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->AddFontDefault();
|
||||
io.Fonts->AddFontDefault(); // Load embedded font (auto-selected).
|
||||
```
|
||||
```cpp
|
||||
io.Fonts->AddFontDefaultVector(); // Load embedded scalable font.
|
||||
```
|
||||
```cpp
|
||||
io.Fonts->AddFontDefaultBitmap(); // Load embedded bitmap font (legacy).
|
||||
```
|
||||
|
||||
**Load .TTF/.OTF file with:**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue