Frame:CreateTitleRegion

From Warcraft Wiki
Jump to navigation Jump to search

Creates a title region on a Frame that allows dragging of the frame with no other code.

      titleRegion = myFrame:CreateTitleRegion()

Example usage

myFrame.titleRegion = myFrame:CreateTitleRegion()
myFrame.titleRegion:SetSize(600, 24) -- 600 wide x 24 tall
myFrame.titleRegion:SetPoint("TOPLEFT") -- anchor the titleRegion to top left of myFrame
-- this is the drag bar texture
myFrame.titleTexture = myFrame:CreateTexture("myFrame_titleTexture", "ARTWORK")
myFrame.titleTexture:SetSize(600, 24)  -- texture is the same size as the title drag bar
myFrame.titleTexture:SetPoint("TOPLEFT")
myFrame.titleTexture:SetColorTexture( .3, .3 , .3, .5) -- give it a light grey color

note: If the frame is hidden, dragging will not function when it is shown, so implement a function to re-enable dragging when shown

 --
 -- toggle the frame shown and hidden
 --
function MyAddOn:Frame_Toggle()
   myFrame.titleRegion:ClearAllPoints()
   
   if ( myFrame:IsVisible() ) then --hide the frame if it's visible
       myFrame:Hide()
   else --show the frame if it's hidden
       myFrame:Show()
       myFrame.titleRegion:SetPoint("TOPLEFT")
   end
end