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>
95 lines
3.8 KiB
Rust
95 lines
3.8 KiB
Rust
//! The synchronous text measure: the host's font engine installed into the VM, so
|
|
//! `GetStringWidth` answers inside the Lua call that asked, as the reference's does (`0x79e510`
|
|
//! calls its font engine, `0x772890`). UI code measures in the tick it sets text
|
|
//! (`MoneyFrame.lua:202`). With no measurer installed, metrics stay 0 until the
|
|
//! [`MeasureRequest`](super::MeasureRequest) round-trip fills them a frame later.
|
|
|
|
use mlua::Lua;
|
|
|
|
use super::{MeasureRequest, MeasuredText, Model};
|
|
use crate::widget::RegionHandle;
|
|
|
|
/// The host's font engine as the VM sees it. It must answer with the same code as the batch
|
|
/// round-trip, or a string's width depends on when it was asked for.
|
|
pub trait TextMeasure {
|
|
/// `(laid_out_w, laid_out_h, natural_w)` for `req` in frame-local units; `natural_w`, the
|
|
/// unwrapped width, is what `GetStringWidth` reports. It runs with the model mutably borrowed,
|
|
/// so it must not re-enter Lua.
|
|
fn measure(&mut self, req: &MeasureRequest) -> (f32, f32, f32);
|
|
}
|
|
|
|
/// Measure region `rh` now if a measurer is installed and its stored measure is stale; a current
|
|
/// one is left alone, so a per-frame poll does not re-measure.
|
|
pub(super) fn ensure_measured(lua: &Lua, rh: RegionHandle) {
|
|
let mut model = lua.app_data_mut::<Model>().expect("model app_data");
|
|
if model.measurer.is_none() {
|
|
return;
|
|
}
|
|
let Some(req) = super::layout::measure_request_for(&mut model, rh) else {
|
|
return; // not a FontString, no text, or already current
|
|
};
|
|
// Taken out and put back: the measurer needs `&mut self` while the model is borrowed, and it
|
|
// cannot re-enter the VM, so nothing sees the gap.
|
|
let mut engine = model.measurer.take().expect("checked above");
|
|
let (w, h, natural_w) = engine.measure(&req);
|
|
model.measurer = Some(engine);
|
|
let new = MeasuredText {
|
|
w,
|
|
h,
|
|
natural_w,
|
|
key: req.key,
|
|
};
|
|
let mut moved = false;
|
|
if let Some(d) = model.region_data.get_mut(&rh) {
|
|
moved = super::types::MeasuredText::layout_moved(d.measured, new);
|
|
// The key always lands: a stale key re-requests forever.
|
|
d.measured = Some(new);
|
|
}
|
|
if moved {
|
|
// Only a box that moved touches the layout, as in `set_measured_text`: a same-width
|
|
// re-measure (a countdown tick) must not cost a whole-roster hash.
|
|
model.touch_layout_region(rh);
|
|
}
|
|
}
|
|
|
|
impl super::UiScript {
|
|
/// Install the host's font engine, so metric reads answer inside the tick that asked. Replace
|
|
/// it whenever the window size or `uiScale` changes: glyph advances snap to whole physical
|
|
/// pixels.
|
|
pub fn set_text_measurer(&mut self, measurer: Box<dyn TextMeasure>) {
|
|
self.model_mut().measurer = Some(measurer);
|
|
}
|
|
|
|
/// Whether a [`TextMeasure`] is installed; the host then skips its batch measure pass.
|
|
pub fn has_text_measurer(&self) -> bool {
|
|
self.model_mut().measurer.is_some()
|
|
}
|
|
|
|
/// Answer every pending FontString measure inline, so a box is right in the frame its text
|
|
/// was set; returns whether anything changed.
|
|
pub(super) fn fill_measures(&mut self) -> bool {
|
|
if !self.has_text_measurer() {
|
|
return false;
|
|
}
|
|
let requests = self.fontstrings_needing_measure();
|
|
if requests.is_empty() {
|
|
return false;
|
|
}
|
|
let answers: Vec<(u32, f32, f32, f32, u64)> = {
|
|
let mut model = self.model_mut();
|
|
let mut engine = model.measurer.take().expect("checked above");
|
|
let answers = requests
|
|
.iter()
|
|
.map(|r| {
|
|
let (w, h, natural_w) = engine.measure(r);
|
|
(r.id, w, h, natural_w, r.key)
|
|
})
|
|
.collect();
|
|
model.measurer = Some(engine);
|
|
answers
|
|
};
|
|
self.set_measured_text(&answers);
|
|
true
|
|
}
|
|
}
|