Skip to content

Commit

Permalink
Publish GetDpiAwareParams() / use in _LoadFontImpl()
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jul 7, 2024
1 parent 13ad8ad commit 0f5e9cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/hello_imgui/doc_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ ImVec2 EmToVec2(ImVec2 v);
float EmSize();
// __HelloImGui::EmSize(nbLines)__ returns a size corresponding to nbLines text lines
float EmSize(float nbLines);

// __HelloImGui::PixelToEm()__ converts a Vec2 in pixels coord to a Vec2 in em units
ImVec2 PixelsToEm(ImVec2 pixels);

// __HelloImGui::PixelSizeToEm()__ converts a size in pixels coord to a size in em units
float PixelSizeToEm(float pixelSize);

```
----
Expand Down
7 changes: 6 additions & 1 deletion src/hello_imgui/dpi_aware.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ ImVec2 EmToVec2(ImVec2 v);
float EmSize();
// __HelloImGui::EmSize(nbLines)__ returns a size corresponding to nbLines text lines
float EmSize(float nbLines);
// @@md

// __HelloImGui::PixelToEm()__ converts a Vec2 in pixels coord to a Vec2 in em units
ImVec2 PixelsToEm(ImVec2 pixels);

// __HelloImGui::PixelSizeToEm()__ converts a size in pixels coord to a size in em units
float PixelSizeToEm(float pixelSize);

// @@md

// Returns the current DpiAwareParams, which are used
// for font loading and window size scaling
DpiAwareParams* GetDpiAwareParams();

} // namespace HelloImGui


Expand Down
10 changes: 5 additions & 5 deletions src/hello_imgui/impl/hello_imgui_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ namespace HelloImGui

// Font oversampling (set by dpiAwareParams)
{
const auto& dpiAwareParams = HelloImGui::GetRunnerParams()->dpiAwareParams;
if (dpiAwareParams.fontOversampleH > 0)
params.fontConfig.OversampleH = dpiAwareParams.fontOversampleH;
if (dpiAwareParams.fontOversampleV > 0)
params.fontConfig.OversampleV = dpiAwareParams.fontOversampleV;
const auto& dpiAwareParams = HelloImGui::GetDpiAwareParams();
if (dpiAwareParams->fontOversampleH > 0)
params.fontConfig.OversampleH = dpiAwareParams->fontOversampleH;
if (dpiAwareParams->fontOversampleV > 0)
params.fontConfig.OversampleV = dpiAwareParams->fontOversampleV;
}

float fontSize = fontSize_;
Expand Down

0 comments on commit 0f5e9cb

Please sign in to comment.