Skip to content

Instantly share code, notes, and snippets.

@rokups

rokups/HDPI.md Secret

Last active August 31, 2020 10:37
Show Gist options
  • Select an option

  • Save rokups/a322dff8ee885f75ee8326207ea0bf75 to your computer and use it in GitHub Desktop.

Select an option

Save rokups/a322dff8ee885f75ee8326207ea0bf75 to your computer and use it in GitHub Desktop.

Problem 1: PushStyleVar() inconsistency. It must take unscaled values.

PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5, 5));      // 1. ImVec2() must be DPI-agnostic (1x scale)
Begin(...);                                                   // 2. DPI scale may change here, g.Style would be rescaled. Window padding above may change to ImVec2(7, 7) at DPI scale 1.5 for exmaple.

Problem 2: PushStyleVar() confusing use when style values are relative to other style values.

ImVec2 pad = g.StyleTemplate.WindowPadding;
PushStyleVar(ImGuiStyleVar_WindowPadding, pad * 2);           // 1. g.StyleTemplate (1x style variant, not g.Style) must be used to create style values relative to current style values.
Begin(...);                                                   // 2. DPI scale may change here, g.Style would be rescaled. Window padding above may change to ImVec2(7, 7) at DPI scale 1.5 for exmaple.

Problem 3: SetNextWindow*() functions take arguments in absolute coordinates. This might be a problem if user wanted values relative to g.Style which is not scaled to DPI of target window when SetNextWindow*() functions are being called. Solution: SetNextWindowSize(g.StyleTemplate.WindowMinSize * next_window->Viewport->DpiScale * 2). Should be a very rate case.

Problem 4: GetFontSize() is no longer usable with PushStyleVar() Solution: Introduced GetFontSize1x(). Also added g.FontBaseSize1x for internal use. Need of it is debatable.

Non-problematic functions which take arguments in absolute coordinates, g.Style (not g.StyleTemplate!) should be used for sizes relative to the style.

  • SetNextItemWidht()
  • PushItemWidth()
  • PushTextWrapPos()
  • SameLine()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment