WoW:USERAPI GetUIParentAnchor: Difference between revisions
(New page: {{userfunc}} Returns SetPoint args for the frame, anchor is relative to the nearest corner of the screen. local function GetUIParentAnchor(frame) local x, y, w, h = frame:GetCenter(),...) |
m (Move page script moved page USERAPI GetUIParentAnchor to USERAPI GetUIParentAnchor without leaving a redirect) |
||
| (2 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{userfunc}} | ||
Returns SetPoint args for the frame, anchor is relative to the nearest corner of the screen. | Returns SetPoint args for the frame, anchor is relative to the nearest corner of the screen. | ||
Latest revision as of 04:49, 15 August 2023
This page documents a <i>user-defined function</i> that you can copy and paste into your addon. Replace PREFIX with your addon or lib prefix to avoid conflicts between different versions of these functions.
Returns SetPoint args for the frame, anchor is relative to the nearest corner of the screen.
local function GetUIParentAnchor(frame) local w, h, x, y = UIParent:GetWidth(), UIParent:GetHeight(), frame:GetCenter() local hhalf, vhalf = (x > w/2) and "RIGHT" or "LEFT", (y > h/2) and "TOP" or "BOTTOM" local dx = hhalf == "RIGHT" and math.floor(frame:GetRight() + 0.5) - w or math.floor(frame:GetLeft() + 0.5) local dy = vhalf == "TOP" and math.floor(frame:GetTop() + 0.5) - h or math.floor(frame:GetBottom() + 0.5) return vhalf..hhalf, dx, dy end