Files
benilla-octo/crates/benilla-ui/src/script/clip.rs
T
Sam SungandClaude Opus 5.5 5b92f94d5c Comments in benilla-ui: one line of fact each, no history, no record numbers (#143)
Part of #41: the comments of `benilla-ui` (the Lua UI engine, its FrameXML loader and its widgets) are rewritten to the rule in `docs/METHOD.md`, which is what the code does and the reference fact behind it, in a line. 43,140 comment lines become 15,161.

- **The mechanical strip.** The citations that were only a private record number go first, and each edit is shown to be a pure removal.
- **Wrong facts corrected.** The rewrite corrects the comments that stated wrong facts. Among them:
  - `0x64a480` is the case-sensitive compare (a byte `repz cmpsb`), and `0x64a4c0` the case-insensitive one.
  - A frame's id sits at `+0xb0`, not `+0xb4`. `EnableKeyboard`/`IsKeyboardEnabled` are `0x776ec0`/`0x776f90`.
  - A region's unpinned edge has no fallback to its owner's rect: the owner supplies only the scale.
  - `$parent` expands to the nearest named ancestor, or "Top" when none is named (`0x76c5b0`), not simply to the parent.
  - A StatusBar fills from its internal normalised fraction, not from `GetValue()`.
  - The addresses of `StartDuel` and `StartDuelUnit` were swapped.
  - Many "untraced" notes now give the traced reference fact: the drag threshold, the per-grip sizing edges, the empty-`autoFocus` skip, and `SetTexCoordModifiesRect`'s default.
  - Stock FrameXML line citations are checked against the stock 1.12 files and corrected. `ref-` file names become the stock file names.
- **Deviation labels.** "Deviation:" now marks only a choice with a reason. A surface that exists only for the retired Era addon target says so plainly: it is not 1.12.
- **Verification.** Every file strips to identical code, and `cargo fmt --check` is clean. Nine second readers compared every file old against new, restored the facts the rewrite had dropped, and checked each new citation against the code, the stock files, vmangos and the reference.

Behaviour differences the rewrite surfaced are filed as their own issues (#131–#142), and more are being validated. The comments here state what the code does. String literals are untouched; they are #92.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 01:58:49 +07:00

66 lines
2.1 KiB
Rust

//! The ScrollFrame clip, shared by `extract` and the pointer hit-test so drawing and hitting agree.
use std::collections::HashMap;
use crate::layout::Rect;
use crate::widget::{FrameKind, KindState};
use super::model::Model;
use super::FrameHandle;
/// Scroll child → its ScrollFrame's resolved rect, for every live ScrollFrame with a rect and a
/// live child. Rebuilt per call and never cached, so no scroll change needs invalidating.
pub(super) fn scroll_clip_sources(model: &Model) -> HashMap<FrameHandle, Rect> {
let mut sources = HashMap::new();
for (h, frame) in model.arena.iter_frames() {
if frame.kind != FrameKind::ScrollFrame {
continue;
}
let KindState::Scroll(state) = &frame.kind_state else {
continue;
};
let Some(child) = state.child else { continue };
if model.arena.frame(child).is_none() {
continue; // stale child handle
}
if let Some(&rect) = model.resolved.get(&h) {
sources.insert(child, rect);
}
}
sources
}
/// The clip `h` draws and hits within: the intersection of every ScrollFrame rect whose scroll
/// child is `h` or an ancestor of it, so nested ScrollFrames intersect; `None` is unclipped.
pub(super) fn effective_clip(
model: &Model,
sources: &HashMap<FrameHandle, Rect>,
mut h: FrameHandle,
) -> Option<Rect> {
let mut clip: Option<Rect> = None;
loop {
if let Some(&r) = sources.get(&h) {
clip = Some(match clip {
Some(c) => intersect_rect(c, r),
None => r,
});
}
match model.arena.frame(h).and_then(|f| f.parent) {
Some(p) => h = p,
None => break,
}
}
clip
}
/// Rect intersection, y-up. Disjoint rects give an inverted rect, which the pointer never hits
/// and the app's `clip_quad` draws nothing in.
pub(super) fn intersect_rect(a: Rect, b: Rect) -> Rect {
Rect::new(
a.bottom.max(b.bottom),
a.left.max(b.left),
a.top.min(b.top),
a.right.min(b.right),
)
}