-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomAnchors.lua
More file actions
156 lines (139 loc) · 4.83 KB
/
Copy pathCustomAnchors.lua
File metadata and controls
156 lines (139 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
---@class CUF
local CUF = select(2, ...)
---@class CUF.API
local API = CUF.API
--- Enables custom positioning for all unit frames.
--- If a specific unit or frame name is passed, only enables custom positioning for that frame.
---
--- Custom positioning prevents CUF from overriding the frame's position, allowing manual control.
---
--- Example usage:
--- ```
--- API:EnableCustomPositioningForUnitFrames("player")
---
--- or
---
--- API:EnableCustomPositioningForUnitFrames("CUF_Player")
---
--- or
---
--- API:EnableCustomPositioningForUnitFrames()
--- ```
---@param name string? Optional unit or frame name
function API:EnableCustomPositioningForUnitFrames(name)
if name ~= nil then
local unitFrame = API:GetUnitFrame(name)
if not unitFrame then return end
unitFrame.__customPositioning = true
return
end
for _, unitFrame in pairs(CUF.unitButtons) do
unitFrame.__customPositioning = true
end
end
--- Disables custom positioning for all unit frames.
--- If a specific unit or frame name is passed, only disables custom positioning for that frame.
---
--- This function resets positioning back to the current layout managed by CUF.
---
--- Example usage:
--- ```
--- API:DisableCustomPositioningForUnitFrames("player")
---
--- or
---
--- API:DisableCustomPositioningForUnitFrames("CUF_Player")
---
--- or
---
--- API:DisableCustomPositioningForUnitFrames()
--- ```
---@param name string? Optional unit or frame name
function API:DisableCustomPositioningForUnitFrames(name)
if name ~= nil then
local unitFrame, unitName = API:GetUnitFrame(name)
if not unitFrame then return end
unitFrame.__customPositioning = false
CUF:Fire("UpdateLayout", CUF.vars.selectedLayout, "position", unitName)
return
end
for _, unitFrame in pairs(CUF.unitButtons) do
unitFrame.__customPositioning = false
end
CUF:Fire("UpdateLayout", CUF.vars.selectedLayout, "position")
end
--- Returns the custom positioning status for a specific unit or frame.
--- If custom positioning is enabled, the function returns `true`. Otherwise, it returns `false`.
---
--- Example usage:
--- ```
--- local isCustomEnabled = API:GetCustomPositioningStatusForUnit("player")
---
--- or
---
--- local isCustomEnabled = API:GetCustomPositioningStatusForUnit("CUF_Player")
--- ```
---@param name string Unit or frame name
---@return boolean|nil status if custom positioning is enabled, otherwise false or nil if not found
function API:GetCustomPositioningStatusForUnit(name)
local unitFrame = API:GetUnitFrame(name)
if not unitFrame then return end
return unitFrame.__customPositioning or false
end
--- Sets a custom position for a unit frame.
--- Automatically enables custom positioning, preventing CUF from overriding it.
---
--- Example usage:
--- ```
--- API:SetCustomUnitFramePoint("player", "TOPLEFT", MyFrame, "TOPLEFT", 0, 0)
---
--- or
---
--- API:SetCustomUnitFramePoint("CUF_Player", "TOPLEFT", MyFrame, "TOPLEFT", 0, 0)
--- ```
---@param name string Unit or frame name
---@param point string The point on the unit frame to anchor
---@param anchor Frame The frame to anchor the unit frame to
---@param relativePoint string The point on the anchor frame to which the unit frame is anchored
---@param offsetX number X offset relative to the anchor
---@param offsetY number Y offset relative to the anchor
function API:SetCustomUnitFramePoint(name, point, anchor, relativePoint, offsetX, offsetY)
local params = {
{ point, "FramePoint", "point" },
{ relativePoint, "FramePoint", "relativePoint" },
{ anchor, "Frame", "anchor" },
{ offsetX, "number", "offsetX" },
{ offsetY, "number", "offsetY" },
}
if not API:ValidateParms("SetCustomUnitFramePoint", params) then return end
local unitFrame = API:GetUnitFrame(name)
if not unitFrame then return end
API:EnableCustomPositioningForUnitFrames(name)
unitFrame:ClearAllPoints()
unitFrame:SetPoint(point, anchor, relativePoint, offsetX, offsetY)
end
--- Sets a custom size for a unit frame.
--- Automatically enables custom sizing, preventing CUF from overriding it.
---
--- Example usage:
--- ```
--- API:SetCustomUnitFrameSize("player", 200, 200)
---
--- or
---
--- API:SetCustomUnitFrameSize("CUF_Player", 200, 200)
--- ```
---@param name string Unit or frame name
---@param width number The desired width for the frame
---@param height number The desired height for the frame
function API:SetCustomUnitFrameSize(name, width, height)
local params = {
{ width, "number", "width" },
{ height, "number", "height" },
}
if not API:ValidateParms("SetCustomUnitFrameSize", params) then return end
local unitFrame = API:GetUnitFrame(name)
if not unitFrame then return end
unitFrame.__customSize = true
unitFrame:SetSize(width, height)
end