Wowpedia
Advertisement

Regions, abstract rectangular areas on the screen to position user interface elements, provide two methods to determine the current scale affecting the region's size and position:

  • GetScale() returns the scale relative to the region's immediate parent; this is the same value defined using Region:SetScale(scale)
  • GetEffectiveScale() returns the net scaling that is the product of the region's scale and that of its parents
scale= region:GetScale()
effectiveScale = region:GetEffectiveScale()

Returns

scale 
Number - The region's scale relative to its immediate parent (if it has one)
effectiveScale 
Number - The region's net scale, inclusive of its parent's effective scale

Example

The following example shows

local frame1 = CreateFrame("Frame")
local frame2 = CreateFrame("Frame", nil, frame1)  -- frame2 is a child of frame1
frame1:SetScale(0.5)
frame2:SetScale(0.5)
print(frame2:GetScale())                          -- 0.5
print(frame2:GetEffectiveScale())                 -- 0.25

It is possible, albeit inefficient and unnecessary, to compute the effective scale using GetScale() alone

function ComputeEffectiveScale(region)
  local scale = 1
  while region do                       
    scale = scale * region:GetScale()
    if (region:IsIgnoringParentScale()) then
      return scale
    end
    region = region:GetParent()
  end
  return scale
end

Details

  • Effective scale affects a region's placement and size, by multipling the cooridnate space used by many of its properties. These include (non-exhaustive list):
    • Region:SetPoint - Affects the optional xOff and yOff arguments, positioning the frame nearer or further from an anchor point
    • Region:SetSize - Affects the width and height dimensions, if these were not already defined using fixed anchor points
  • Notwithstanding, Region:SetIgnoreParentScale(true) will cause a region's effective scale to only be its own scale

Patch changes

  • Battle for Azeroth Patch 8.0.1 / API (2018-07-17): Moved to Region:GetScale() and Region:GetEffectiveScale()[1]
    Previously Frame:GetScale() and Frame:GetEffectiveScale

See also

  • Region:GetScaledRect - Provides the location and size of a region in a standardized coordinate space as if effective scale were always 1

References

 
  1. ^ Blizzard Entertainment Aerythlea 2018-11-14. Battle for Azeroth Addon Changes.
Advertisement