Chat frames lay out, page and scroll as 1.12.1's; panes aim as they open (#1799)

A ScrollingMessageFrame now lays out, pages and scrolls as the client's relayout does.

- A message that does not fit whole, past the anchored one, ends the layout (`0x7889b3`-`0x7889c5`). A half-fitting top line is hidden, not clipped, and the shown count that paging reads agrees.
- PageUp and PageDown take one line step per shown message, then one step back, and stop on a refusal (`0x7885b0`, `0x7885e0`). One shown message nets no move.
- ScrollUp is refused once the oldest message shows, and AtTop reads that flag (`0x78861c`, `0x7931b5`). It is nil on an empty frame (`0x787775`).

A character pane's camera takes its aimed pose with its spawn, so a pane is framed on the frame it opens.

Each change fails its test without it.

Fixes #1786
Fixes #1787

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sam Sung
2026-10-17 18:21:58 +07:00
committed by GitHub
parent c97fd03a57
commit 93098a0646
8 changed files with 393 additions and 111 deletions
+7 -13
View File
@@ -541,7 +541,7 @@ pub(super) fn sync_panes(
&source,
scene,
) {
aim(&mut cams, booth_pane, &anchors, aspect);
aim(&mut commands, booth_pane, &anchors, aspect);
booth_pane.built = Some(Built {
build: pane.builds,
look,
@@ -571,7 +571,7 @@ pub(super) fn sync_panes(
continue; // the engine holds no copy (`ClearModel`): nothing at `+0x318`
};
if booth_pane.aimed != Some(aspect) {
aim(&mut cams, booth_pane, &anchors, aspect);
aim(&mut commands, booth_pane, &anchors, aspect);
}
// The root, the widget's `T(pos)·R(facing)·S(s)` with `pos` at the origin; `s` is the 4:3
// renormalizer on the fixed camera ([`pane_root_scale`]).
@@ -1023,18 +1023,12 @@ fn build(
Some(anchors)
}
/// Aim a pane's camera through its copy's rig at the pane's aspect.
fn aim(
cams: &mut Query<(&mut Transform, &mut Projection, &mut RenderTarget), With<BoothCam>>,
pane: &mut PaneBooth,
anchors: &PortraitAnchors,
aspect: f32,
) {
/// Aim a pane's camera through its copy's rig at the pane's aspect. The pose goes in as a command,
/// so a camera spawned through `Commands` this pass takes it with its spawn and the pane's first
/// frame composites an aimed view; `try_insert` leaves a camera already despawned alone.
fn aim(commands: &mut Commands, pane: &mut PaneBooth, anchors: &PortraitAnchors, aspect: f32) {
let (tf, proj) = body_frame(anchors, aspect);
if let Ok((mut t, mut p, _)) = cams.get_mut(pane.camera) {
*t = tf;
*p = proj;
}
commands.entity(pane.camera).try_insert((tf, proj));
pane.aimed = Some(aspect);
}
@@ -626,6 +626,25 @@ fn each_pane_draws_its_own_subject_named_or_not() {
assert_eq!(h.drawn().len(), 2);
}
/// The camera spawns through `Commands` with the pane, and the pass that builds the copy aims it
/// with that spawn, so the frame the pane opens on already composites an aimed view, not the
/// spawn pose.
#[test]
fn a_pane_is_aimed_on_the_frame_it_opens() {
let mut h =
Harness::new(r#"m = CreateFrame("PlayerModel", "Doll", UIParent) m:SetUnit("player")"#);
let pane = h.handle(Some("Doll"));
h.pass();
let world = h.app.world_mut();
let booth = &world.resource::<PaneBooths>().panes[&pane];
let (entity, aimed) = (booth.camera, booth.aimed);
assert!(aimed.is_some(), "the opening pass records the aim");
assert!(
matches!(world.get::<Projection>(entity), Some(Projection::Custom(_))),
"the camera wears the body frame on the opening frame, not its spawn pose"
);
}
/// The hide hook drops the copy (`0x505ce0`) and the booth with it; the show hook builds again
/// from the stored GUID (`0x505d3c`).
#[test]
@@ -127,8 +127,12 @@ fn wheel_scroll_re_arms_the_fade_then_freezes_it() {
let mut s = chat_frame();
s.run("ChatFrame1:SetTimeVisible(0); ChatFrame1:SetFadeDuration(4)")
.unwrap();
for t in ["L0", "L1", "L2"] {
s.add_chat_message("ChatFrame1", t, 1.0, 1.0, 1.0);
// More lines than the window holds: a view that shows the oldest cannot scroll up (`0x78861c`).
for t in (0..20)
.map(|n| format!("F{n}"))
.chain(["L0", "L1", "L2"].map(String::from))
{
s.add_chat_message("ChatFrame1", &t, 1.0, 1.0, 1.0);
}
s.resolve();
s.tick(1.0);
@@ -797,8 +801,9 @@ fn hovering_the_dock_still_reveals_the_tabs() {
fn a_chat_view_at_the_bottom_stops_rewriting_the_flash() {
benilla_formats::wow_data_or_skip!();
let mut s = chat_frame();
for t in ["L0", "L1", "L2"] {
s.add_chat_message("ChatFrame1", t, 1.0, 1.0, 1.0);
// More lines than the window holds, so the view can scroll up (`0x78861c`).
for t in (0..20).map(|n| format!("L{n}")) {
s.add_chat_message("ChatFrame1", &t, 1.0, 1.0, 1.0);
}
for _ in 0..3 {
s.tick(0.016);
@@ -292,10 +292,12 @@ impl UiScript {
})
}
/// How many rows frame `fh`'s resolved rect holds at its font's pitch, the client's
/// `numLinesDisplayed`: the scrolling class's page size and the plain class's capacity. Both
/// the rect and the pitch are scaled (`0x785f0a`, `0x785f1f`); a pitch of 0 or less, which a
/// negative spacing can make on the plain class, holds nothing (`0x785f8f`).
/// How many rows frame `fh`'s resolved rect holds at its font's pitch: the plain class's
/// capacity (`+0x318`) and the height the scrolling class's layout spends in whole messages.
/// The plain class scales both the rect and the pitch (`0x785f0a`, `0x785f1f`) and holds
/// nothing at a pitch of 0 or less, which a negative spacing can make (`0x785f8f`). The
/// scrolling class divides the rect by the scale (`0x7887d4`) and charges each message its
/// height plus the snapped unscaled spacing (`0x78899e`-`0x7889ad`); scaled, that is this pitch.
pub(super) fn message_viewport_rows(model: &Model, fh: FrameHandle) -> usize {
let font = Self::message_frame_font(model, fh);
let Some(frame) = model.arena.frame(fh) else {
@@ -443,8 +445,10 @@ impl UiScript {
/// own pitch, the raw spacing included ([`MessageFont::plain_pitch`]). A scrolling frame stacks
/// up from the bottom, `scroll_offset` choosing the bottom message. A MessageFrame does too for `insertMode` BOTTOM, and for TOP hangs the newest off
/// the top edge (`UIErrorsFrame.xml:4`); the reference's anchor per mode is untraced, and this
/// reading reproduces both stock uses. A message that partly fits draws clipped; a faded
/// scrolling line keeps its rows, as the reference never re-packs chat.
/// reading reproduces both stock uses. The scrolling class draws the messages its layout
/// places ([`crate::widget::ScrollingMessageState::displayed_count`]): the anchored one, then
/// only those that fit whole. A faded one keeps its rows, as the reference never re-packs
/// chat. The plain class draws its bands as far as the frame reaches.
pub(super) fn emit_message_lines(
model: &Model,
fh: FrameHandle,
@@ -503,9 +507,15 @@ impl UiScript {
// one, the order its link rebuild walks them (`0x788c8d`-`0x788d7d`), so the spans reach
// [`super::hyperlink`] in the reference's placement order.
let first = out.len();
let reverse = matches!(frame.kind_state, KindState::ScrollingMessage(_));
for idx in (0..=top_index).rev() {
if used >= fr.top - fr.bottom {
let (reverse, shown) = match &frame.kind_state {
KindState::ScrollingMessage(smf) => (
true,
smf.displayed_count(Self::message_viewport_rows(model, fh)),
),
_ => (false, usize::MAX),
};
for idx in (0..=top_index).rev().take(shown) {
if !reverse && used >= fr.top - fr.bottom {
break; // the next band starts outside the frame
}
let line = &lines[idx];
@@ -34,13 +34,14 @@ fn with_smf<T>(
}
}
/// Run a scroll call with the viewport's row count, which every scroll needs: each re-arms the
/// fade of the lines on display ([`ScrollingMessageState::reset_all_fade_times`]).
fn scroll(
/// Run `f` over the state with the viewport's row count, which every scroll needs: each re-arms
/// the fade of the lines on display ([`ScrollingMessageState::reset_all_fade_times`]), and `AtTop`
/// reads the layout's flag.
fn with_viewport<T>(
lua: &Lua,
this: &Table,
op: impl FnOnce(&mut ScrollingMessageState, usize),
) -> mlua::Result<()> {
f: impl FnOnce(&mut ScrollingMessageState, usize) -> T,
) -> mlua::Result<T> {
let h = frame_handle_of(lua, this)?;
let mut model = lua.app_data_mut::<Model>().expect("model app_data");
let viewport_rows = UiScript::message_viewport_rows(&model, h);
@@ -49,14 +50,20 @@ fn scroll(
.frame_mut(h)
.ok_or_else(|| mlua::Error::runtime("stale frame handle"))?;
match &mut frame.kind_state {
KindState::ScrollingMessage(smf) => {
op(smf, viewport_rows);
Ok(())
}
KindState::ScrollingMessage(smf) => Ok(f(smf, viewport_rows)),
_ => Err(mlua::Error::runtime("not a ScrollingMessageFrame")),
}
}
/// Run a scroll call: [`with_viewport`] for an op with no answer.
fn scroll(
lua: &Lua,
this: &Table,
op: impl FnOnce(&mut ScrollingMessageState, usize),
) -> mlua::Result<()> {
with_viewport(lua, this, op)
}
pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
let m = lua.create_table()?;
@@ -159,8 +166,8 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
m.set(
"AtTop",
lua.create_function(|lua, this: Table| {
with_smf(lua, &this, |smf| {
crate::script::binding_abi::flag(smf.at_top())
with_viewport(lua, &this, |smf, rows| {
crate::script::binding_abi::flag(smf.at_top(rows))
})
})?,
)?;
@@ -466,11 +473,15 @@ mod tests {
assert!(s.at_bottom());
s.scroll_down(8); // already at the bottom: no move
assert!(s.at_bottom());
// 3 lines → max_scroll = 2; scroll past it clamps.
// A frame showing every line is at the top already (`+0x350`, `0x788a37`).
assert!(s.at_top(8));
s.scroll_up(8);
assert_eq!(s.scroll_offset, 0, "refused: the oldest is on screen");
// One row high, the oldest shows only at offset 2; scrolling past it is refused.
for _ in 0..10 {
s.scroll_up(8);
s.scroll_up(1);
}
assert!(s.at_top());
assert!(s.at_top(1));
assert_eq!(s.scroll_offset, 2);
s.scroll_to_bottom(8);
assert!(s.at_bottom());
@@ -485,7 +496,7 @@ mod tests {
for n in 0..4 {
s.add(format!("l{n}"), 1.0, 1.0, 1.0);
}
s.scroll_up(8); // viewing one line back (bottom row = l2)
s.scroll_up(1); // viewing one line back (bottom row = l2)
let off = s.scroll_offset;
s.add("l4".into(), 1.0, 1.0, 1.0);
assert_eq!(
@@ -505,78 +516,263 @@ mod tests {
s.add(format!("l{n}"), 1.0, 1.0, 1.0);
}
s.lines[1].rows = 3;
// 4 rows: the newest (1) and the middle (3) fill it; a partly fitting message counts.
// 4 rows: the newest (1) and the middle (3) fill it. A message that does not fit whole
// ends the walk (`0x7889c0`-`0x7889c5`) unless it is the anchored one.
assert_eq!(s.displayed_count(4), 2);
assert_eq!(s.displayed_count(3), 2, "partial middle line still counts");
assert_eq!(
s.displayed_count(3),
1,
"a partly fitting middle line is out"
);
assert_eq!(s.displayed_count(1), 1);
// A page is displayed − 1, one message of overlap, never 0.
s.page_up(4);
assert_eq!(s.displayed_count(0), 1, "the anchored message always shows");
// `PageUp` (`0x7885b0`) scrolls up once per displayed line and then down once, so a page
// is the displayed count less one, and one displayed line nets nothing.
s.page_up(4); // 2 displayed: up moves, the second up is refused (the oldest shows)
assert_eq!(s.scroll_offset, 1);
s.page_up(1); // displayed 1 → page clamps to 1 message
assert_eq!(s.scroll_offset, 2);
s.page_down(4);
assert_eq!(s.scroll_offset, 1);
s.page_down(4);
s.page_up(1); // 1 displayed: up, down
assert_eq!(s.scroll_offset, 1, "a page of one line nets 0");
// `PageDown` (`0x7885e0`): a step refused at the bottom ends the page with no step back.
s.page_down(4); // 2 displayed: down moves, down is refused
assert!(s.at_bottom());
s.page_down(4); // 2 displayed: both refused at the first
assert!(s.at_bottom());
}
/// A refused step ends the page where it stands (`0x7885ca`), with no step back; an empty
/// frame moves nothing and re-arms nothing (`0x788619`).
#[test]
fn emit_stacks_wrapped_rows_and_clips_partial_top() {
fn a_page_stopped_by_an_end_takes_no_step_back() {
let mut s = ScrollingMessageState {
max_lines: 8,
..Default::default()
};
assert!(!s.step_up(4), "an empty frame answers 0");
s.page_up(4);
s.page_down(4);
assert!(!s.links_dirty, "an empty frame is left alone");
for n in 0..4 {
s.add(format!("l{n}"), 1.0, 1.0, 1.0);
}
// Two rows high: the oldest shows from offset 2, where every step up is refused.
s.scroll_up(2);
s.scroll_up(2);
assert_eq!(s.scroll_offset, 2);
assert!(s.at_top(2));
// The first up is refused, so the page ends with no down after it.
s.page_up(2);
assert_eq!(s.scroll_offset, 2);
// One row high there, `PageDown` is a down and an up: it nets 0.
s.page_down(1);
assert_eq!(s.scroll_offset, 2, "down then up nets 0");
}
/// With two or more lines displayed and room to move, the page runs its whole loop and then
/// steps back: a page is the displayed count less one (`0x7885b0`, `0x7885e0`).
#[test]
fn a_page_with_room_runs_the_loop_and_steps_back() {
let mut s = ScrollingMessageState {
max_lines: 8,
..Default::default()
};
for n in 0..8 {
s.add(format!("l{n}"), 1.0, 1.0, 1.0);
}
s.page_up(3); // 3 displayed: up, up, up, down
assert_eq!(s.scroll_offset, 2);
s.page_up(3);
assert_eq!(s.scroll_offset, 4);
s.page_down(3); // down, down, down, up
assert_eq!(s.scroll_offset, 2);
}
/// `AtTop` answers nil on an empty frame: the constructor, `Clear` and `SetMaxLines` zero the
/// flag (`0x787775`, `0x7882ce`, `0x787eb1`).
#[test]
fn at_top_is_nil_on_an_empty_frame() {
let s = UiScript::new().unwrap();
s.run(
"CF = CreateFrame('ScrollingMessageFrame', 'CF')\n\
EMPTY = CF:AtTop()\n\
CF:AddMessage('a') CF:Clear()\n\
CLEARED = CF:AtTop()\n\
CF:AddMessage('a') CF:SetMaxLines(4)\n\
WIPED = CF:AtTop()",
)
.unwrap();
for name in ["EMPTY", "CLEARED", "WIPED"] {
assert!(
s.eval::<bool>(&format!("return {name} == nil")).unwrap(),
"{name}"
);
}
}
/// `ScrollToTop` on a single message anchors the newest (`0x788799`-`0x7887aa`); a frame
/// already at the bottom skips the re-arm (`0x788aff`), which two messages do not.
#[test]
fn scroll_to_top_with_one_message_skips_the_re_arm_at_the_bottom() {
let faded = |count: usize| {
let mut s = ScrollingMessageState {
time_visible: 0.0,
fade_duration: 4.0,
..Default::default()
};
for n in 0..count {
s.add(format!("l{n}"), 1.0, 1.0, 1.0);
}
s.tick(2.0);
s.links_dirty = false;
s.scroll_to_top(8);
s
};
let one = faded(1);
assert_eq!(one.lines[0].alpha, 127.0 / 255.0, "left as it was");
assert!(one.links_dirty, "the links still rebuild");
let two = faded(2);
assert_eq!(two.scroll_offset, 1);
assert_eq!(two.lines[0].alpha, 1.0, "the oldest was re-armed");
}
/// `ScrollUp` is refused once the oldest message is on screen (`0x78861c`-`0x788624`, the flag
/// the relayout sets at `0x788a3c`), not when it is the bottom row; `ScrollToTop` (`0x788690`)
/// anchors the oldest. `AtTop` (`0x793130`) reads the same flag.
#[test]
fn scroll_up_stops_when_the_oldest_message_shows() {
let mut s = ScrollingMessageState {
max_lines: 8,
..Default::default()
};
for n in 0..5 {
s.add(format!("l{n}"), 1.0, 1.0, 1.0);
}
// Three rows show 3 of 5: l4 l3 l2, then l3 l2 l1, then l2 l1 l0.
assert!(!s.at_top(3));
s.scroll_up(3);
s.scroll_up(3);
assert_eq!(s.scroll_offset, 2);
assert!(s.at_top(3), "l0 is on screen");
s.scroll_up(3);
assert_eq!(s.scroll_offset, 2, "refused");
s.scroll_to_top(3);
assert_eq!(s.scroll_offset, 4, "the oldest as the anchor");
}
/// The Lua `AtTop` follows the viewport the frame's rect gives.
#[test]
fn at_top_reads_the_layout_through_lua() {
let mut s = UiScript::new().unwrap();
s.set_screen_size(800.0, 600.0);
s.run(
"CF = CreateFrame('ScrollingMessageFrame', 'CF')\n\
CF:SetPoint('BOTTOMLEFT', 32, 90)\n\
CF:SetWidth(430)\n\
CF:SetHeight(44)\n\
for n = 1, 5 do CF:AddMessage('m' .. n) end",
)
.unwrap();
s.resolve();
// 44 px hold three rows of 14.
assert!(s.eval::<bool>("return CF:AtTop() == nil").unwrap());
s.run("CF:ScrollUp() CF:ScrollUp()").unwrap();
assert!(s.eval::<bool>("return CF:AtTop() == 1").unwrap());
// Shrunk to two rows, the oldest message no longer shows.
s.run("CF:SetHeight(30)").unwrap();
s.resolve();
assert!(
s.eval::<bool>("return CF:AtTop() == nil").unwrap(),
"a shorter frame places fewer messages, so the oldest drops off"
);
}
/// A scrolling frame `CF` of the given height holding `messages`, bottom left at (32, 90),
/// after the host answered each message's row count with `rows(index)`: what it draws as
/// `(text, bottom, top)` in draw order, and the count its layout reports.
fn laid_out(
height: u32,
messages: &[&str],
rows: impl Fn(u32) -> u16,
) -> (Vec<(String, f32, f32)>, usize) {
let mut s = UiScript::new().unwrap();
s.set_screen_size(800.0, 600.0);
s.run(&format!(
"local f = CreateFrame('ScrollingMessageFrame', 'CF')\n\
f:SetPoint('BOTTOMLEFT', 32, 90)\n\
f:SetWidth(430)\n\
f:SetHeight(34)",
)
f:SetHeight({height})"
))
.unwrap();
s.run("CF:AddMessage('old', 1, 1, 1)").unwrap();
s.run("CF:AddMessage('wrapped', 1, 1, 1)").unwrap();
s.run("CF:AddMessage('new', 1, 1, 1)").unwrap();
for m in messages {
s.run(&format!("CF:AddMessage('{m}', 1, 1, 1)")).unwrap();
}
s.resolve();
let reqs = s.message_lines_needing_measure();
assert_eq!(reqs.len(), 3);
assert!(reqs.iter().all(|r| (r.wrap_width - 430.0).abs() < 0.5));
let answers: Vec<(u32, u32, u16, u64)> = reqs
let answers: Vec<(u32, u32, u16, u64)> = s
.message_lines_needing_measure()
.iter()
.map(|r| (r.frame, r.index, if r.index == 1 { 2 } else { 1 }, r.key))
.map(|r| (r.frame, r.index, rows(r.index), r.key))
.collect();
s.set_message_line_rows(&answers);
assert!(
s.message_lines_needing_measure().is_empty(),
"answered keys satisfy the cache"
);
// Default font, pitch 14. Frame [90, 124): 'new' is [90, 104), 'wrapped' [104, 132)
// overflows and draws clipped, and 'old' would start at 132, outside, so does not draw.
let quads = s.extract();
let texts: Vec<(String, f32, f32)> = quads
let mut fh = None;
let texts = s
.extract()
.iter()
.filter_map(|q| match (&q.content, q.rect) {
(crate::script::QuadContent::Text { text: Some(t), .. }, Some(r)) => {
.filter_map(|q| match (&q.content, q.rect, q.target) {
(
crate::script::QuadContent::Text { text: Some(t), .. },
Some(r),
crate::order::ZTarget::Frame(h),
) => {
fh = Some(h);
Some((t.clone(), r.bottom, r.top))
}
_ => None,
})
.collect();
assert_eq!(
texts.len(),
2,
"partial top line draws, off-top line doesn't"
);
// Farthest displayed line first, the link rebuild's walk (`0x788c8d`-`0x788d7d`).
let model = s.model_mut();
let fh = fh.expect("a line drew");
let viewport = UiScript::message_viewport_rows(&model, fh);
let count = match &model.arena.frame(fh).expect("the frame").kind_state {
crate::widget::KindState::ScrollingMessage(smf) => smf.displayed_count(viewport),
_ => unreachable!("a scrolling frame"),
};
(texts, count)
}
/// The layout places the anchored message, then only what fits whole (`0x7889b3`-`0x7889c5`).
/// Default font, pitch 14: at 34 px (two rows and a bit) 'wrapped' starts inside the frame at 104
/// and runs to 132, past its top at 124, so it is neither drawn nor counted, and 'old' beyond it
/// is not either.
#[test]
fn emit_stacks_wrapped_rows_and_hides_a_partial_top() {
let rows = |i| if i == 1 { 2 } else { 1 };
let (texts, count) = laid_out(34, &["old", "wrapped", "new"], rows);
assert_eq!(texts.len(), 1, "only the anchored message: {texts:?}");
assert_eq!(texts[0].0, "new");
assert!((texts[0].1 - 90.0).abs() < 0.01 && (texts[0].2 - 104.0).abs() < 0.01);
assert_eq!(count, 1, "the displayed count agrees with the draw");
// 48 px (three rows and a bit) holds 'new' and 'wrapped' whole; 'old' would be the
// fraction at the top edge, so it stays out. Farthest displayed line first, the link
// rebuild's walk (`0x788c8d`-`0x788d7d`).
let (texts, count) = laid_out(48, &["old", "wrapped", "new"], rows);
assert_eq!(count, 2);
assert_eq!(texts.len(), 2, "{texts:?}");
assert_eq!(texts[0].0, "wrapped");
assert!((texts[0].1 - 104.0).abs() < 0.01 && (texts[0].2 - 132.0).abs() < 0.01);
assert_eq!(texts[1].0, "new");
assert!((texts[1].1 - 90.0).abs() < 0.01 && (texts[1].2 - 104.0).abs() < 0.01);
let clip = quads
.iter()
.find_map(|q| match &q.content {
crate::script::QuadContent::Text { text: Some(t), .. } if t == "wrapped" => q.clip,
_ => None,
})
.expect("wrapped line carries a clip");
assert!((clip.top - 124.0).abs() < 0.01 && (clip.bottom - 90.0).abs() < 0.01);
}
/// The anchored message shows even when it alone is taller than the frame (`0x7889c0`): the
/// frame's 20 px hold a row and a bit, the newest message wraps to three rows, and it draws
/// from the bottom edge while the older one does not.
#[test]
fn the_anchored_message_shows_though_taller_than_the_frame() {
let (texts, count) = laid_out(20, &["old", "tall"], |i| if i == 1 { 3 } else { 1 });
assert_eq!(texts.len(), 1, "{texts:?}");
assert_eq!(texts[0].0, "tall");
assert!((texts[0].1 - 90.0).abs() < 0.01 && (texts[0].2 - 132.0).abs() < 0.01);
assert_eq!(count, 1);
}
/// The lines draw at the frame's ARTWORK layer: a BACKGROUND texture, such as the chat
@@ -191,6 +191,9 @@ fn log_hover(s: &mut UiScript) {
fn a_relayout_with_the_same_spans_leaves_and_re_enters_the_hovered_link() {
let mut s = chat();
log_hover(&mut s);
// A scroll on an empty frame answers 0 at once (`0x788659`), so the frame holds a line.
s.run("CF:AddMessage('x')").unwrap();
set_link(&mut s, "CF");
s.mouse_move(130.0, 127.0);
set_link(&mut s, "CF");
assert_eq!(log_of(&s), format!("enter:{LINK}"), "no flag: no rebuild");
@@ -157,12 +157,22 @@ impl ScrollingMessageState {
self.scroll_offset == 0
}
/// Whether the view is scrolled as far back as the ring allows (`AtTop`).
pub fn at_top(&self) -> bool {
self.scroll_offset >= self.max_scroll()
/// `AtTop` (`0x793130`), which reads the flag `+0x350`: the relayout sets it when every older
/// message was placed (`0x788a37`-`0x788a3c`), so the oldest is on screen. An empty frame
/// answers false: the constructor, `Clear` after its relayout and `SetMaxLines` all zero it
/// (`0x787775`, `0x7882ce`, `0x787eb1`). This reads the layout live, while the reference caches
/// the flag per relayout, so the two differ on a hidden frame, whose relayout does nothing
/// (`0x78878e`), and after an `AddMessage` while scrolled up (`0x788220`-`0x78824a`).
pub fn at_top(&self, viewport_rows: usize) -> bool {
if self.lines.is_empty() {
return false;
}
let available = self.lines.len().saturating_sub(self.scroll_offset);
self.displayed_count(viewport_rows) == available
}
/// The furthest the view can scroll up: enough to bring the oldest line to the bottom row.
/// The furthest the view can scroll: the oldest line as the anchor, where `ScrollToTop`
/// relayouts (`0x788690`).
fn max_scroll(&self) -> usize {
self.lines.len().saturating_sub(1)
}
@@ -171,7 +181,7 @@ impl ScrollingMessageState {
self.scroll_offset = self.scroll_offset.min(self.max_scroll());
}
/// Re-arm the fade of the displayed lines only (`0x788b80`): full alpha and the frame's
/// Re-arm the fade of the displayed lines only, on a frame with lines (`0x788b80`): full alpha and the frame's
/// current `timeVisible`/`fadeDuration`, so even a fully faded line comes back (expiry frees
/// nothing, `0x788525`). Engine-only, not a 1.12 Lua verb; every scroll entry reaches it.
pub fn reset_all_fade_times(&mut self, viewport_rows: usize) {
@@ -204,14 +214,38 @@ impl ScrollingMessageState {
/// `ScrollUp` (`0x788610`): one line older, then re-arm.
pub fn scroll_up(&mut self, viewport_rows: usize) {
self.scroll_offset = (self.scroll_offset + 1).min(self.max_scroll());
self.reset_all_fade_times(viewport_rows);
self.step_up(viewport_rows);
}
/// `ScrollDown` (`0x788650`): one line newer, then re-arm.
pub fn scroll_down(&mut self, viewport_rows: usize) {
self.step_down(viewport_rows);
}
/// `0x788610`'s answer: whether the view moved. An empty frame answers 0 and touches nothing
/// (`0x788619`); one whose oldest message is on screen re-arms and answers 0 (`0x78861c`-
/// `0x788626`).
pub fn step_up(&mut self, viewport_rows: usize) -> bool {
if self.lines.is_empty() {
return false;
}
let moved = !self.at_top(viewport_rows);
if moved {
self.scroll_offset += 1;
}
self.reset_all_fade_times(viewport_rows);
moved
}
/// `0x788650`'s answer: the same, toward the newest line (`0x788659`, `0x788666`).
pub fn step_down(&mut self, viewport_rows: usize) -> bool {
if self.lines.is_empty() {
return false;
}
let moved = !self.at_bottom();
self.scroll_offset = self.scroll_offset.saturating_sub(1);
self.reset_all_fade_times(viewport_rows);
moved
}
/// `ScrollToBottom` (`0x7886d0`): to the newest line, then re-arm.
@@ -220,44 +254,65 @@ impl ScrollingMessageState {
self.reset_all_fade_times(viewport_rows);
}
/// `ScrollToTop` (`0x788690`): to the oldest line, then re-arm, as its relayout always lands
/// off the bottom.
/// `ScrollToTop` (`0x788690`): the oldest line as the anchor, then re-arm, as its relayout
/// lands off the bottom. With exactly one message the anchor is the newest (`0x788799`-
/// `0x7887aa`), and a frame already at the bottom skips the re-arm (`0x788aff`); the links
/// still rebuild (`0x788a8e`).
pub fn scroll_to_top(&mut self, viewport_rows: usize) {
let stays_at_bottom = self.at_bottom() && self.lines.len() == 1;
self.scroll_offset = self.max_scroll();
self.reset_all_fade_times(viewport_rows);
if stays_at_bottom {
self.links_dirty = true;
} else {
self.reset_all_fade_times(viewport_rows);
}
}
/// How many messages fit `viewport_rows` from the anchor, each costing its wrapped rows; a
/// partly fitting one counts, as in the draw's band walk (`emit_message_lines`).
/// How many messages the layout places for a frame `viewport_rows` tall, the client's lines
/// shown (`+0x34c`, which paging reads at `0x7885b4`). From the anchor outward each message
/// costs its wrapped rows (`0x7889ad`); one that does not fit whole ends the walk
/// (`0x7889b3`-`0x7889be`, `0x788a2f`) unless it is the anchored one (`0x7889c0`-`0x7889c5`),
/// which always shows. A faded message is placed all the same (`0x7889c7`-`0x7889ee` only
/// hides it), so it holds its rows. The draw (`emit_message_lines`) walks this many.
pub fn displayed_count(&self, viewport_rows: usize) -> usize {
if self.lines.is_empty() || viewport_rows == 0 {
if self.lines.is_empty() {
return 0;
}
let top_index = self.lines.len().saturating_sub(1 + self.scroll_offset);
let mut used = 0usize;
let mut left = viewport_rows;
let mut count = 0usize;
for idx in (0..=top_index).rev() {
if used >= viewport_rows {
let rows = usize::from(self.lines[idx].rows.max(1));
if count > 0 && rows > left {
break;
}
used += usize::from(self.lines[idx].rows.max(1));
left = left.saturating_sub(rows);
count += 1;
}
count.max(1)
count
}
/// `PageUp` (`0x7885b0`): back by the displayed count less one, then re-arm.
/// `PageUp` (`0x7885b0`): `ScrollUp` once per displayed line, the count read once up front
/// (`0x7885b4`); a step that cannot move ends the page there (`0x7885ca`), else one `ScrollDown`
/// follows (`0x7885d4`). A page is the displayed count less one, and one displayed line nets 0.
pub fn page_up(&mut self, viewport_rows: usize) {
let page = self.displayed_count(viewport_rows).saturating_sub(1).max(1);
self.scroll_offset = (self.scroll_offset + page).min(self.max_scroll());
self.reset_all_fade_times(viewport_rows);
for _ in 0..self.displayed_count(viewport_rows) {
if !self.step_up(viewport_rows) {
return;
}
}
self.step_down(viewport_rows);
}
/// `PageDown`: the same page toward the newest line, then re-arm.
/// `PageDown` (`0x7885e0`): the mirror, `ScrollDown` per displayed line (`0x7885f3`), a refusal
/// ending the page (`0x7885fa`), else one `ScrollUp` (`0x788604`).
pub fn page_down(&mut self, viewport_rows: usize) {
let page = self.displayed_count(viewport_rows).saturating_sub(1).max(1);
self.scroll_offset = self.scroll_offset.saturating_sub(page);
self.reset_all_fade_times(viewport_rows);
for _ in 0..self.displayed_count(viewport_rows) {
if !self.step_down(viewport_rows) {
return;
}
}
self.step_up(viewport_rows);
}
/// Advance the fade by `dt` (OnUpdate, `0x788460`), only at the bottom with fading on; the
+1 -1
View File
@@ -740,7 +740,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- The drag selects from its anchor, as every OS's own text fields do, where the reference's applies `0x77cd10` to each mouse move's whole delta (`0x77a8a1`). ([`src/widget/kinds/editbox.rs:997`](../crates/benilla-ui/src/widget/kinds/editbox.rs#L997))
- A code point past U+FFFF is no space, where the client tests its low 16 bits, so U+10020 counts as a space there. ([`src/widget/kinds/editbox.rs:1127`](../crates/benilla-ui/src/widget/kinds/editbox.rs#L1127))
- The reference has one field, the font's, but our font is read off the first `<FontString>` region (`message_frame_font`), which a `CreateFrame` frame lacks; so that FontString's own `GetJustifyH` does not see this. ([`src/widget/kinds/messageframe.rs:33`](../crates/benilla-ui/src/widget/kinds/messageframe.rs#L33))
- Kept apart from the font's, as `ScrollingMessageState::justify` is. ([`src/widget/kinds/messageframe.rs:331`](../crates/benilla-ui/src/widget/kinds/messageframe.rs#L331))
- Kept apart from the font's, as `ScrollingMessageState::justify` is. ([`src/widget/kinds/messageframe.rs:386`](../crates/benilla-ui/src/widget/kinds/messageframe.rs#L386))
- `None` until then, not the ctor's 0, so that an unset row takes nothing rather than slot 0. ([`src/widget/kinds/mod.rs:859`](../crates/benilla-ui/src/widget/kinds/mod.rs#L859))
- On the thumb it is the grabbed point, where `CSimpleSlider` (`0x789ba0`/`0x789ca0`) always centers it, because that feels less surprising and a stock-sized thumb hides the difference. ([`src/widget/kinds/mod.rs:1203`](../crates/benilla-ui/src/widget/kinds/mod.rs#L1203))
- Levels pack contiguously, because the reference's resuming cursor (`0x764fd3`/`0x764fd8`) leaves a hole past a wide gap ({0, 4, 6} at bound 7 gives {0, 1, 3} at bound 4). ([`src/widget/propagation.rs:180`](../crates/benilla-ui/src/widget/propagation.rs#L180))