ScrollFrame is how a large body of content can be displayed through a small window. The ScrollFrame is the size of the "window" through which you want to see the larger content, and it has another frame set as a "ScrollChild" containing the full content. The proportion by which the ScrollChild is larger than the ScrollFrame automatically determines the horizontal and vertical scroll range of the ScrollFrame. You can get these ranges or position the ScrollChild "behind" the ScrollFrame within those ranges using ScrollFrame's methods. It also allows you to set a new frame as the ScrollChild.
When a ScrollFrame is used for repetitive content, such as the buttons for assigning key bindings or the friends in your social frame, it is often implemented as a "FauxScrollFrame," which contains enough of these subframes in the ScrollChild to fill the ScrollFrame, plus one. It then saves an offset and maps which of the elements in an internal list are displayed.
To create a ScrollFrame's ScrollChild in XML, include a <ScrollChild>
element as a direct child of the <ScrollFrame>
element. The <ScrollChild>
element should have one child, of any type descended from <Frame>
. To create the scroll child in Lua, create the frame using CreateFrame()
, and then attach the child to the scroll frame using ScrollFrame:SetScrollChild(child)
. The child frame must always have an absolute size set with <AbsDimension>
in XML or using both SetWidth()
and SetHeight()
in Lua.
A ScrollFrame does not automatically include an element that sets the scroll range. Typically, you add a Slider as a child of a ScrollFrame, with an OnValueChanged handler that sets the scroll value.
ScrollFrames are common throughout the UI, used for quest text, readable items, lists of friends and guild members, and similar applications.
Defined Methods
- scroll = ScrollFrame:GetHorizontalScroll() - Returns the scroll frame's current horizontal scroll position
- maxScroll = ScrollFrame:GetHorizontalScrollRange() - Returns the scroll frame's maximum horizontal (rightmost) scroll position
- scrollChild = ScrollFrame:GetScrollChild() - Returns the frame scrolled by the scroll frame
- scroll = ScrollFrame:GetVerticalScroll() - Returns the scroll frame's current vertical scroll position
- maxScroll = ScrollFrame:GetVerticalScrollRange() - Returns the scroll frame's maximum vertical (bottom) scroll position
- ScrollFrame:SetHorizontalScroll(scroll) - Sets the scroll frame's horizontal scroll position
- ScrollFrame:SetScrollChild(frame) - Sets the scroll child for the scroll frame
- ScrollFrame:SetVerticalScroll(scroll) - Sets the scroll frame's vertical scroll position
- ScrollFrame:UpdateScrollChildRect() - Updates the position of the scroll frame's child
Inherited Methods
- ScrollFrame:GetPropagateKeyboardInput() - This function is not yet documented
- ScrollFrame:IsForbidden() - This function is not yet documented
- ScrollFrame:RegisterUnitEvent() - This function is not yet documented
- ScrollFrame:SetDontSavePosition() - This function is not yet documented
- ScrollFrame:SetPropagateKeyboardInput() - This function is not yet documented
- ScrollFrame:SetShown() - This function is not yet documented
- ScrollFrame:SetSize(width, height) - Sets the size of the region to the specified values
- ScrollFrame:SetToplevel(enable) - Sets whether the frame should automatically come to the front when clicked
- ScrollFrame:SetUserPlaced(enable) - Flags the frame for automatic saving and restoration of position and dimensions
- ScrollFrame:SetWidth(width) - Sets the region's width
- ScrollFrame:Show() - Shows the region
- ScrollFrame:StartMoving() - Begins repositioning the frame via mouse movement
- ScrollFrame:StartSizing() - Begins resizing the frame via mouse movement
- ScrollFrame:StopAnimating() - Stops any active animations involving the region or its children
- ScrollFrame:StopMovingOrSizing() - Ends movement or resizing of the frame initiated with [[docs/widgets/Frame/StartMoving|`:StartMoving()`]] or [[docs/widgets/Frame/StartSizing|`:StartSizing()`]]
- ScrollFrame:UnregisterAllEvents() - Unregisters the frame from any [[docs/events|events]] for which it is registered
- ScrollFrame:UnregisterEvent("event") - Unregisters the frame for an event
Script Handlers
- OnAttributeChanged(self, "name", value) - Run when a frame attribute is changed
- OnChar(self, "text") - Run for each text character typed in the frame
- OnDisable(self) - Run when the frame is disabled
- OnDragStart(self, "button") - Run when the mouse is dragged starting in the frame
- OnDragStop(self) - Run when the mouse button is released after a drag started in the frame
- OnEnable(self) - Run when the frame is enabled
- OnEnter(self, motion) - Run when the mouse cursor enters the frame's interactive area
- OnEvent(self, "event", ...) - Run whenever an [[docs/events|event]] fires for which the frame is registered
- OnHide(self) - Run when the frame's visbility changes to hidden
- OnHorizontalScroll(self, offset) - Run when the scroll frame's horizontal scroll position changes
- OnKeyDown(self, "key") - Run when a keyboard key is pressed if the frame is keyboard enabled
- OnKeyUp(self, "key") - Run when a keyboard key is released if the frame is keyboard enabled
- OnLeave(self, motion) - Run when the mouse cursor leaves the frame's interactive area
- OnLoad(self) - Run when the frame is created
- OnMouseDown(self, "button") - Run when a mouse button is pressed while the cursor is over the frame
- OnMouseUp(self, "button") - Run when the mouse button is released following a mouse down action in the frame
- OnMouseWheel(self, delta) - Run when the frame receives a mouse wheel scrolling action
- OnReceiveDrag(self) - Run when the mouse button is released after dragging into the frame
- OnScrollRangeChanged(self, xOffset, yOffset) - Run when the scroll frame's scroll position is changed
- OnShow(self) - Run when the frame becomes visible
- OnSizeChanged(self, width, height) - Run when a frame's size changes
- OnUpdate(self, elapsed) - Run each time the screen is drawn by the game engine
- OnVerticalScroll(self, offset) - Run when the scroll frame's vertical scroll position changes