Frame:SetClampRectInsets()

From Wowpedia
Jump to: navigation, search

Controls how much of the frame may be moved off-screen.

Frame:SetClampRectInsets(left, right, top, bottom)

This method is available for any widget that inherits from Frame.

Arguments

left 
Number - Left clamp region offset. Controls collision with the left edge of the screen, positive values allow the frame to be moved off-screen, negative values enforce minimum distance to the edge.
right 
Number - Right clamp region offset. Controls collision with the right edge of the screen, negative values allow the frame to be moved off-screen, positive values enforce minimum distance to the edge.
top 
Number - Top clamp region offset. Controls collision with the top edge of the screen, negative values allow the frame to be moved off-screen, positive values enforce minimum distance to the edge.
bottom 
Number - Bottom clamp region offset. Controls collision with the bottom edge of the screen, positive values allow the frame to be moved off-screen, negative values enforce minimum distance to the edge.

Example

The following code creates a draggable frame that can be moved 42 size units off any edge of the screen, but can never entirely off-screen.

local frame = CreateFrame("FRAME", nil, UIParent)
frame:SetSize(200, 100)
frame:SetPoint("CENTER")
frame:SetMovable(true)
frame:SetScript("OnMouseDown", frame.StartMoving)
frame:SetScript("OnMouseUp", frame.StopMovingOrSizing)
frame:SetClampedToScreen(true)
frame:SetClampRectInsets(42, -42, -42, 42)
local tex = frame:CreateTexture()
tex:SetTexture(1,0,0)
tex:SetAllPoints()

Details

  • You must mark the frame as clamped to screen in order for this function to work. You can do so using Frame:SetClampedToScreen.

See also