From 9b83205b3e738ceda751386da17255fa011d1aee Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Mon, 14 Feb 2022 02:44:57 +0100 Subject: [PATCH] Fix vscroll-indicator size and offset. (#334) --- CHANGELOG.md | 3 +-- src/ftxui/dom/scroll_indicator.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6a040b..d1eb006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,6 @@ Changelog current (development) --------------------- -### Features: - #### DOM: - The `inverted` decorator now toggle in the inverted attribute. - Add `gauge` for the 4 directions. Expose the following API: @@ -20,6 +18,7 @@ Element gaugeDirection(float ratio, GaugeDirection); - Add the `automerge` decorator. This makes separator characters to be merged with others nearby. - Fix the `Table` rendering function, to allow automerging characters. +- Bugfix: The `vscroll_indicator` now computes its offset and size correctly. #### Component - Support SIGTSTP. (ctrl+z). diff --git a/src/ftxui/dom/scroll_indicator.cpp b/src/ftxui/dom/scroll_indicator.cpp index 541deda..11001f5 100644 --- a/src/ftxui/dom/scroll_indicator.cpp +++ b/src/ftxui/dom/scroll_indicator.cpp @@ -39,24 +39,26 @@ Element vscroll_indicator(Element child) { const Box& stencil = screen.stencil; int size_inner = box_.y_max - box_.y_min; - int size_outter = stencil.y_max - stencil.y_min; + int size_outter = stencil.y_max - stencil.y_min + 1; if (size_outter >= size_inner) return; - int start_y = 2 * stencil.y_min + 2 * float(stencil.y_min - box_.y_min) * - (size_outter - 1) / size_inner; - int size = 2 * float(size_outter) * (size_outter - 1) / size_inner + 2; + int size = 2 * size_outter * size_outter / size_inner; size = std::max(size, 1); + int start_y = 2 * stencil.y_min + // + 2 * (stencil.y_min - box_.y_min) * size_outter / size_inner; + const int x = stencil.x_max; for (int y = stencil.y_min; y <= stencil.y_max; ++y) { - bool up = (2 * y + -1 >= start_y) && (2 * y - 1 <= start_y + size); - bool down = (2 * y - 0 >= start_y) && (2 * y - 0 <= start_y + size); + int y_up = 2 * y + 0; + int y_down = 2 * y + 1; + bool up = (start_y <= y_up) && (y_up <= start_y + size); + bool down = (start_y <= y_down) && (y_down <= start_y + size); const char* c = up ? (down ? "┃" : "╹") : (down ? "╻" : " "); screen.PixelAt(x, y) = Pixel(); screen.PixelAt(x, y).character = c; - screen.PixelAt(x, y).inverted = true; } }; };