Pull the auto-scroll concern out of ConsoleTab into a focused, ImGui-free
ConsoleScrollController (console_scroll_controller.{h,cpp}). It owns the three
coupled fields that were loose on the god-class — auto_scroll_, the wheel-up
cooldown, and the new-lines-while-scrolled-up backlog count — and the state
machine tying them together: wheel-up detaches + starts a cooldown, the cooldown
gates the at-bottom re-enable check, backlog counting happens only while
detached, and re-pinning (checkbox / jump pill / reaching the bottom) clears it.
The view keeps only what needs ImGui: it measures scroll position, hands the
controller a plain `atBottom` bool + frame delta, and issues the actual
SetScrollHereY. ConsoleTab loses three more members and all the scattered
auto-scroll bookkeeping collapses to scroll_.* calls.
Adds testConsoleScrollController: pinned start ignores backlog, wheel-up detach +
cooldown gating, re-enable only when at bottom, checkbox toggle semantics, and
the jump-to-bottom pill. Full-node + lite build clean; ctest green; source
hygiene clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
40 lines
864 B
C++
40 lines
864 B
C++
// DragonX Wallet - ImGui Edition
|
|
// Copyright 2024-2026 The Hush Developers
|
|
// Released under the GPLv3
|
|
|
|
#include "console_scroll_controller.h"
|
|
|
|
namespace dragonx {
|
|
namespace ui {
|
|
|
|
void ConsoleScrollController::setAutoScroll(bool on)
|
|
{
|
|
auto_scroll_ = on;
|
|
if (on) new_lines_ = 0; // re-pinning to the bottom clears the backlog counter
|
|
}
|
|
|
|
void ConsoleScrollController::onUserScrolledUp()
|
|
{
|
|
auto_scroll_ = false;
|
|
cooldown_ = kScrollUpCooldownSeconds;
|
|
}
|
|
|
|
void ConsoleScrollController::tickCooldown(float dt)
|
|
{
|
|
if (cooldown_ > 0.0f) cooldown_ -= dt;
|
|
}
|
|
|
|
void ConsoleScrollController::considerReenable(bool atBottom)
|
|
{
|
|
if (!auto_scroll_ && cooldown_ <= 0.0f && atBottom)
|
|
pinToBottom();
|
|
}
|
|
|
|
void ConsoleScrollController::onLinesAdded(int n)
|
|
{
|
|
if (!auto_scroll_ && n > 0) new_lines_ += n;
|
|
}
|
|
|
|
} // namespace ui
|
|
} // namespace dragonx
|