Skip to content

Commit

Permalink
Add PixelsToEm
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Apr 28, 2024
1 parent b8b6e68 commit bed77bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/hello_imgui/dpi_aware.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ float EmSize();
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);

} // namespace HelloImGui


Expand Down
14 changes: 14 additions & 0 deletions src/hello_imgui/impl/dpi_aware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ namespace HelloImGui
return ImVec2(k * v.x, k * v.y);
}

ImVec2 PixelsToEm(ImVec2 pixels)
{
IM_ASSERT(GImGui != NULL);
float k = ImGui::GetFontSize();
return ImVec2(pixels.x / k, pixels.y / k);
}

float PixelSizeToEm(float pixelSize)
{
IM_ASSERT(GImGui != NULL);
float k = ImGui::GetFontSize();
return pixelSize / k;
}


float DpiWindowSizeFactor()
{
Expand Down

0 comments on commit bed77bd

Please sign in to comment.