mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-22 15:46:56 +00:00
api: combine movable functions and set anchors
This commit is contained in:
+47
-54
@@ -524,6 +524,52 @@ function pfUI.api.wipe(src)
|
||||
return src
|
||||
end
|
||||
|
||||
-- [ Load Movable ]
|
||||
-- Loads the positions of a Frame.
|
||||
-- 'frame' [frame] the frame that should be positioned.
|
||||
function pfUI.api.LoadMovable(frame)
|
||||
-- update position data
|
||||
if not frame.posdata or init then
|
||||
frame.posdata = { scale = frame:GetScale(), pos = {} }
|
||||
for i=1,frame:GetNumPoints() do
|
||||
frame.posdata.pos[i] = { frame:GetPoint(i) }
|
||||
end
|
||||
end
|
||||
|
||||
if pfUI_config["position"][frame:GetName()] then
|
||||
if pfUI_config["position"][frame:GetName()]["scale"] then
|
||||
frame:SetScale(pfUI_config["position"][frame:GetName()].scale)
|
||||
end
|
||||
|
||||
if pfUI_config["position"][frame:GetName()]["xpos"] then
|
||||
local anchor = pfUI_config["position"][frame:GetName()]["anchor"] or "TOPLEFT"
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint(anchor, pfUI_config["position"][frame:GetName()].xpos, pfUI_config["position"][frame:GetName()].ypos)
|
||||
end
|
||||
elseif frame.posdata and frame.posdata.pos[1] then
|
||||
frame:ClearAllPoints()
|
||||
frame:SetScale(frame.posdata.scale)
|
||||
|
||||
for id, point in pairs(frame.posdata.pos) do
|
||||
frame:SetPoint(unpack(point))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- [ Save Movable ]
|
||||
-- Save the positions of a Frame.
|
||||
-- 'frame' [frame] the frame that should be saved.
|
||||
function pfUI.api.SaveMovable(frame)
|
||||
local anchor, _, _, xpos, ypos = frame:GetPoint()
|
||||
if not C.position[frame:GetName()] then
|
||||
C.position[frame:GetName()] = {}
|
||||
end
|
||||
|
||||
C.position[frame:GetName()]["xpos"] = round(xpos)
|
||||
C.position[frame:GetName()]["ypos"] = round(ypos)
|
||||
C.position[frame:GetName()]["anchor"] = anchor
|
||||
end
|
||||
|
||||
-- [ Update Movable ]
|
||||
-- Loads and update the configured position of the specified frame.
|
||||
-- It also creates an entry in the movables table.
|
||||
@@ -540,31 +586,7 @@ function pfUI.api.UpdateMovable(frame, init)
|
||||
pfUI.movables[name] = frame
|
||||
end
|
||||
|
||||
-- update position data
|
||||
if not frame.posdata or init then
|
||||
frame.posdata = { scale = frame:GetScale(), pos = {} }
|
||||
for i=1,frame:GetNumPoints() do
|
||||
frame.posdata.pos[i] = { frame:GetPoint(i) }
|
||||
end
|
||||
end
|
||||
|
||||
if pfUI_config["position"][frame:GetName()] then
|
||||
if pfUI_config["position"][frame:GetName()]["scale"] then
|
||||
frame:SetScale(pfUI_config["position"][frame:GetName()].scale)
|
||||
end
|
||||
|
||||
if pfUI_config["position"][frame:GetName()]["xpos"] then
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint("TOPLEFT", pfUI_config["position"][frame:GetName()].xpos, pfUI_config["position"][frame:GetName()].ypos)
|
||||
end
|
||||
elseif frame.posdata and frame.posdata.pos[1] then
|
||||
frame:ClearAllPoints()
|
||||
frame:SetScale(frame.posdata.scale)
|
||||
|
||||
for id, point in pairs(frame.posdata.pos) do
|
||||
frame:SetPoint(unpack(point))
|
||||
end
|
||||
end
|
||||
LoadMovable(frame)
|
||||
end
|
||||
|
||||
-- [ Remove Movable ]
|
||||
@@ -575,35 +597,6 @@ function pfUI.api.RemoveMovable(frame)
|
||||
pfUI.movables[name] = nil
|
||||
end
|
||||
|
||||
-- [ Load Movable ]
|
||||
-- Loads the positions of a Frame.
|
||||
-- 'frame' [frame] the frame that should be positioned.
|
||||
function pfUI.api.LoadMovable(frame)
|
||||
if pfUI_config["position"][frame:GetName()] then
|
||||
if pfUI_config["position"][frame:GetName()]["scale"] then
|
||||
frame:SetScale(pfUI_config["position"][frame:GetName()].scale)
|
||||
end
|
||||
|
||||
if pfUI_config["position"][frame:GetName()]["xpos"] then
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint("TOPLEFT", pfUI_config["position"][frame:GetName()].xpos, pfUI_config["position"][frame:GetName()].ypos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- [ Save Movable ]
|
||||
-- Save the positions of a Frame.
|
||||
-- 'frame' [frame] the frame that should be saved.
|
||||
function pfUI.api.SaveMovable(frame)
|
||||
local _, _, _, xpos, ypos = frame:GetPoint()
|
||||
if not C.position[frame:GetName()] then
|
||||
C.position[frame:GetName()] = {}
|
||||
end
|
||||
|
||||
C.position[frame:GetName()]["xpos"] = round(xpos)
|
||||
C.position[frame:GetName()]["ypos"] = round(ypos)
|
||||
end
|
||||
|
||||
-- [ SetAutoPoint ]
|
||||
-- Automatically places the frame according to screen position of the parent.
|
||||
-- 'frame' [frame] the frame that should be moved.
|
||||
|
||||
Reference in New Issue
Block a user