View Single Post
02-20-24, 12:31 AM   #5
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
Originally Posted by Fizzlemizz View Post
I missed the CreateFrame code for btn in the original post

For Blizz to save the position, the frame has to have a unique name.
Lua Code:
  1. local btn = CreateFrame("Button", addonName.."MovingButton", UIParent, "UIPanelButtonTemplate")
And it didn't work again. The button after /reload returned to the center

Lua Code:
  1. local btn = CreateFrame("Button", addonName.."MovingButton", UIParent, "UIPanelButtonTemplate")
  2. btn:SetPoint("CENTER")
  3. btn:SetSize(100, 40)
  4. btn:SetText("Click me")
  5. btn:SetScript("OnClick", function(self, button, ...)
  6. btn:SetMovable(true)
  7. btn:RegisterForDrag('LeftButton')
  8. btn:SetUserPlaced(true) -- Only works if the frame is created before the PLAYER_LOGIN event
  9. btn:SetScript('OnDragStart', btn.StartMoving)
  10. btn:SetScript('OnDragStop', btn.StopMovingOrSizing)
  11.     if (button == "RightButton" and btn:IsVisible()) then
  12.         btn:Hide()
  13.     end
  14.  
  15.     updateData()
  16.     updateList()
  17.     f:Show()
  18. end)
  19. btn:RegisterForClicks("AnyUp")
  Reply With Quote