// DragonX Wallet - ImGui Edition // Copyright 2024-2026 The Hush Developers // Released under the GPLv3 // // Pure maths of ApplyScrollEdgeMask (draw_helpers.h), split out so it is unit-testable without ImGui. #pragma once #include namespace dragonx { namespace ui { namespace material { struct ScrollEdgeFade { bool top = false; // content scrolled off the top edge bool bottom = false; // more content below the bottom edge bool any() const { return top || bottom; } }; inline ScrollEdgeFade ComputeScrollEdgeFade(float scrollY, float scrollMaxY) { ScrollEdgeFade f; f.top = scrollY > 1.0f; // only when scrolled down f.bottom = scrollMaxY > 0 && scrollY < scrollMaxY - 1.0f; // only when not at the scroll bottom return f; } // Alpha multiplier (0..1) for a vertex at screen-y `posY`. Same maths as the former inline loop. inline float ScrollEdgeAlpha(const ScrollEdgeFade& f, float posY, float topEdge, float bottomEdge, float fadeZone) { float alpha = 1.0f; if (f.top) { float d = posY - topEdge; if (d < fadeZone) alpha = std::min(alpha, std::max(0.0f, d / fadeZone)); } if (f.bottom) { float d = bottomEdge - posY; if (d < fadeZone) alpha = std::min(alpha, std::max(0.0f, d / fadeZone)); } return alpha; } } // namespace material } // namespace ui } // namespace dragonx