diff --git a/api/api.lua b/api/api.lua index cffac804..e8844b0b 100644 --- a/api/api.lua +++ b/api/api.lua @@ -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.