fix(frame): keep a scroll child clipped when its ScrollFrame moves (#60)

* fix(frame): keep a scroll child clipped when its ScrollFrame moves

A frame a ScrollFrame draws carries a "scrolled" flag (0x2000 at +0xB4):
the strata pass skips it and the ScrollFrame draws it inside a viewport
cut to its rect. SetScrollChild sets the flag through the setter at
0x0076A400, which also marks the scroll child (0x4000) and recurses into
child frames. SetParent sets a moved frame's flag from its new parent
through the same setter, and the recursion doesn't stop at a ScrollFrame,
so moving a frame that holds a ScrollFrame under an unscrolled parent
cleared the flag on the scroll child and everything in it. The strata
pass then drew them whole, past the ScrollFrame's edges.

AceGUI-3.0 builds each widget under UIParent and then moves it into its
container, so every AceGUI ScrollFrame spilled: AceConfigDialog-3.0's
pages drew below the Interface Options window (61 frames under Zygor
Guides Viewer 2.0's "Display" scroll child had lost the flag).

Hook the setter to keep a frame marked as a scroll child scrolled when a
value is only being passed down (third argument -1). SetScrollChild's
own calls are unchanged.

Verified in-game (1.12.1 client via VanillaFixes, Zygor Guides Viewer 2.0):
AceConfigDialog-3.0's Interface Options pages clip and scroll inside
their box; on the "Display" page no frame under the scroll child lacks
the flag any more (61 did before), and a ScrollFrame built under
UIParent and then moved keeps its content, its content's children and
a child added afterwards scrolled.

* docs(frame): describe ScrollFrame clipping without version history

State what stays clipped and when, with AceGUI-3.0 as the case it
serves. Remove the vanilla comparison and the engine flag explanation;
the comment in src/frame/ScrollChildren.cpp already records them.

* fix(frame): skip scroll children the way 3.3.5's setter does

3.3.5's CSimpleFrame::SetBeingScrolled (0x00490F60) does not pass the
scrolled value into a child frame marked as the scroll child, and its
direct call is not gated: a scroll child that is itself given a new
parent takes the new parent's value. The hook forced any scroll child
scrolled on a pass-down call, which also kept a directly reparented
scroll child clipped to its old ScrollFrame.

Skip a scroll child only inside the setter's own recursion, told apart
by a depth counter (the setter is its only nested caller). SetParent's
and SetScrollChild's direct calls run unchanged.

---------

Co-authored-by: Brues <5278969+brues-code@users.noreply.github.com>
This commit is contained in:
Skeewirt
2026-10-17 20:40:56 -05:00
committed by GitHub
co-authored by Brues
parent 721f32ac77
commit a68fb0a6be
3 changed files with 121 additions and 0 deletions
+17
View File
@@ -228,6 +228,7 @@ build instructions.
- [`GetMouseFoci()`](#getmousefoci)
- [`frame:SetShown(shown)`](#framesetshownshown)
- [A frame moved to a new parent takes its children along](#a-frame-moved-to-a-new-parent-takes-its-children-along)
- [A ScrollFrame keeps clipping its content when it moves](#a-scrollframe-keeps-clipping-its-content-when-it-moves)
- [`fontstring:GetStringHeight()`](#fontstringgetstringheight)
- [`fontstring:GetUnboundedStringWidth()`](#fontstringgetunboundedstringwidth)
- [`fontstring:GetWrappedWidth()`](#fontstringgetwrappedwidth)
@@ -5647,6 +5648,22 @@ child:GetFrameLevel() -- 22
`frame:SetFrameLevel(level)` moves only `frame`. The frames under it keep
the levels they have.
### A ScrollFrame keeps clipping its content when it moves
A ScrollFrame's scroll child, and all the frames in it, stay clipped to the
ScrollFrame. This is also true when the ScrollFrame, or a frame above it,
gets a new parent. As a result, a ScrollFrame that an addon builds in one
place and then moves into a window still clips its content to its edges.
AceGUI-3.0 widgets work this way.
```lua
local holder = CreateFrame("Frame", nil, UIParent)
local scroll = CreateFrame("ScrollFrame", nil, holder)
local content = CreateFrame("Frame", nil, scroll)
scroll:SetScrollChild(content)
holder:SetParent(SomeWindow) -- content stays clipped to scroll
```
### `fontstring:GetStringHeight()`
This is the companion to `GetStringWidth`. It returns the height of the
+26
View File
@@ -2869,6 +2869,32 @@ enum Offsets {
// 0x0076AAB0, never through SetParent or the alpha setter. `Frame::Alpha`
// hooks it to forget the frame's own alpha.
FUN_FRAME_DESTRUCTOR = 0x007693B0,
// Scroll clipping. A frame a ScrollFrame draws carries FRAME_FLAG_SCROLLED
// in its flags (OFF_FRAME_FLAGS): the strata pass leaves it out when it
// builds a level's layers (`test ah, 0x20` at 0x007659DF), and the
// ScrollFrame draws it instead, from the render callback it queues after
// its last layer (0x007871C0 -> 0x00787220). That callback narrows the
// viewport to the ScrollFrame's rect and calls the scroll child's
// vtable+0x40 (0x0076B3F0), which draws the frame's layers and then each
// shown child frame without FRAME_FLAG_SCROLL_CHILD, recursively.
//
// FUN_FRAME_SET_SCROLLED — `void __thiscall(frame, int scrolled, int
// scrollChild)`, `ret 8` — sets or clears FRAME_FLAG_SCROLLED, sets or
// clears FRAME_FLAG_SCROLL_CHILD when `scrollChild` >= 0, marks the
// frame's five layers for a rebuild when scrolled (0x0076B530), and calls
// itself on each child frame with (scrolled, -1). Its only callers:
// SetScrollChild (0x00786CE0: the old child (0, 0), the new one (1, 1)),
// SetParent (0x0076ABCB: the new parent's FRAME_FLAG_SCROLLED bit, or 0
// with no parent, and -1) and its own recursion (0x0076A45F). So a value
// SetParent passes down reaches a scroll child and everything in it.
// 3.3.5's setter (0x00490F60) skips child frames that carry
// FRAME_FLAG_SCROLL_CHILD; `Frame::ScrollChildren` hooks this one to do
// the same.
FUN_FRAME_SET_SCROLLED = 0x0076A400,
OFF_FRAME_FLAGS = 0xB4,
FRAME_FLAG_SCROLLED = 0x2000,
FRAME_FLAG_SCROLL_CHILD = 0x4000,
FUN_SCRIPT_TEXTURE_SHOW = 0x0079B770,
FUN_SCRIPT_TEXTURE_HIDE = 0x0079B830,
FUN_SCRIPT_FONTSTRING_SHOW = 0x0079CDB0,
+78
View File
@@ -0,0 +1,78 @@
// This file is part of ClassicAPI.
//
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
// A ScrollFrame keeps clipping its scroll child when the ScrollFrame, or any
// frame above it, moves to a new parent.
//
// A frame a ScrollFrame draws carries a "scrolled" flag: the strata pass
// leaves it out, and the ScrollFrame draws it inside a viewport cut to its
// own rect. SetScrollChild sets the flag on the child and everything under
// it, and marks the child itself as the scroll child. SetParent sets a moved
// frame's flag from its new parent through the same setter, which passes the
// value on down to every child frame. It doesn't stop at a ScrollFrame, so a
// frame holding a ScrollFrame, moved under a parent that isn't scrolled,
// clears the flag on the ScrollFrame's scroll child and everything in it.
// The strata pass then draws them whole, past the ScrollFrame's edges.
//
// AceGUI-3.0 builds each widget under UIParent and then moves it into its
// container, so the content of every AceGUI ScrollFrame lost its clipping
// the moment it was used. AceConfigDialog-3.0's option pages in the
// Interface Options window drew their widgets below the window, off the
// bottom of the screen: on Zygor Guides Viewer 2.0's "Display" page, 61
// frames under the scroll child had lost the flag. 3.3.5 draws the same
// pages clipped to their box.
//
// 3.3.5's setter (CSimpleFrame::SetBeingScrolled, 0x00490F60) doesn't pass
// the value into a child frame marked as the scroll child, so a scroll child
// and everything in it keep the flag their ScrollFrame gave them. The direct
// call is not gated there: a scroll child that is itself given a new parent
// takes the new parent's value. The hook mirrors that. It skips a scroll
// child only when the setter reaches it through its own recursion, which
// comes back through the hooked entry, so a scroll child at any depth is
// skipped. SetParent's and SetScrollChild's direct calls go through
// unchanged.
#include "Game.h"
#include "Offsets.h"
#include <cstdint>
namespace Frame::ScrollChildren {
namespace {
// `scrollChild`: 1 / 0 set or clear the scroll-child mark (SetScrollChild);
// -1 leaves it as it is (SetParent and the recursion).
using SetScrolled_t = void(__thiscall *)(void *frame, int scrolled, int scrollChild);
SetScrolled_t g_origSetScrolled = nullptr;
// Nonzero while the original runs, so a nested call is the setter's own
// recursion into a child frame (its only caller from inside).
int g_depth = 0;
void __fastcall SetScrolled_h(void *frame, void * /*edx*/, int scrolled, int scrollChild) {
if (g_depth > 0 &&
(Game::Read<uint32_t>(frame, Offsets::OFF_FRAME_FLAGS) & Offsets::FRAME_FLAG_SCROLL_CHILD) != 0)
return; // its ScrollFrame draws it, whatever its ancestors are
++g_depth;
g_origSetScrolled(frame, scrolled, scrollChild);
--g_depth;
}
const Game::HookAutoRegister _hook{Offsets::FUN_FRAME_SET_SCROLLED,
reinterpret_cast<void *>(&SetScrolled_h),
reinterpret_cast<void **>(&g_origSetScrolled)};
} // namespace
} // namespace Frame::ScrollChildren