Mechanical, behavior-preserving consolidations from the audit. Rendering extractions were kept byte-equivalent; sites that couldn't be made identical were left as-is (noted below). Shared helpers: - util::truncateMiddle(s,maxLen) / (s,front,back) in text_format.h — replaces 6 file-local middle-ellipsis truncators + several inline substr sites (send/receive/transactions/balance_recent_tx/explorer + app.cpp + 3 dialogs). Carries the maxLen<=3 guard, fixing the latent unsigned-underflow copies. - material::LoadingDots() in draw_helpers.h — one animated-ellipsis source for 8 copy-pasted spinner sites (identical GetTime()*3 phase preserved). - Reuse the existing FormatHashrate() in explorer_tab + peers_tab (dropped two inline hashrate ladders). - material::DrawButtonGlassOverlay() — the glass-fill/rim/tactile overlay block shared by TactileButton / TactileSmallButton / schema TactileButton. - material::CollapsibleHeader() — the invisible-button + label + chevron idiom (3 of 5 settings_page sites; RPC/Debug headers skipped — non-identical). - material::GlassCardScope (RAII) — the ChannelsSplit/Indent/DrawGlassPanel/ ChannelsMerge card scaffold (5 settings_page cards; About/send/receive skipped — different padding / logo interleaving). - material::DialogWarningHeader()/DialogConfirmFooter() — warning header + 50/50 Cancel/danger footer across the confirm dialogs; button height moved from a hardcoded 40px into ui.toml (components.overlay-dialog.confirm-btn-height). - File-local enterLowSpec()/exitLowSpec() collapse the 3 low-spec snapshot copies. i18n: wrapped hardcoded English in the shared balance render paths and the whole Lite lifecycle/security section in TR(), with English defaults added to loadBuiltinEnglish() (res/lang/*.json left for the translation tooling — TR falls back to English, so output is unchanged). Full-node + Lite build clean; ctest 1/1; hygiene clean. These are rendering changes — the Settings page (cards/headers/confirm dialogs), all tactile buttons, and the Lite settings section warrant a screenshot check. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
38 lines
1.6 KiB
C++
38 lines
1.6 KiB
C++
// DragonX Wallet - ImGui Edition
|
|
// Copyright 2024-2026 The Hush Developers
|
|
// Released under the GPLv3
|
|
//
|
|
// Small shared text helpers used across the immediate-mode UI. Centralised here so the per-frame
|
|
// hot paths use one allocation-free implementation instead of several copies.
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace dragonx {
|
|
namespace util {
|
|
|
|
// Localized relative time, e.g. "5 minutes ago" (via i18n). Empty when timestamp <= 0.
|
|
std::string formatTimeAgo(std::int64_t timestamp);
|
|
|
|
// Compact, non-localized relative time for tight UI: "5s ago" / "3m ago" / "2h ago" / "4d ago".
|
|
std::string formatTimeAgoShort(std::int64_t timestamp);
|
|
|
|
// Case-insensitive substring test that does NOT allocate (unlike lower-casing copies + find).
|
|
// An empty needle matches everything. Safe for per-frame filtering of large lists.
|
|
bool containsIgnoreCase(std::string_view haystack, std::string_view needle);
|
|
|
|
// Middle-ellipsis truncation, half/half form: "prefix...suffix" so the total (including "...")
|
|
// is at most maxLen. Guards maxLen <= 3 (returns s unchanged) to avoid unsigned underflow on the
|
|
// (maxLen - 3) split. Strings already at/under maxLen are returned unchanged.
|
|
std::string truncateMiddle(const std::string& s, int maxLen);
|
|
|
|
// Middle-ellipsis truncation with explicit prefix/suffix lengths: "<front chars>...<back chars>".
|
|
// Returns s unchanged when it is no longer than front + back + 3 (the "..." would not save space).
|
|
std::string truncateMiddle(const std::string& s, int front, int back);
|
|
|
|
} // namespace util
|
|
} // namespace dragonx
|