Fix vscroll-indicator size and offset. (#334)

This commit is contained in:
Arthur Sonzogni 2022-02-14 02:44:57 +01:00 committed by GitHub
parent 5da7b8a59a
commit 9b83205b3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View File

@ -4,8 +4,6 @@ Changelog
current (development) current (development)
--------------------- ---------------------
### Features:
#### DOM: #### DOM:
- The `inverted` decorator now toggle in the inverted attribute. - The `inverted` decorator now toggle in the inverted attribute.
- Add `gauge` for the 4 directions. Expose the following API: - 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 - Add the `automerge` decorator. This makes separator characters to be merged
with others nearby. with others nearby.
- Fix the `Table` rendering function, to allow automerging characters. - Fix the `Table` rendering function, to allow automerging characters.
- Bugfix: The `vscroll_indicator` now computes its offset and size correctly.
#### Component #### Component
- Support SIGTSTP. (ctrl+z). - Support SIGTSTP. (ctrl+z).

View File

@ -39,24 +39,26 @@ Element vscroll_indicator(Element child) {
const Box& stencil = screen.stencil; const Box& stencil = screen.stencil;
int size_inner = box_.y_max - box_.y_min; 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) if (size_outter >= size_inner)
return; return;
int start_y = 2 * stencil.y_min + 2 * float(stencil.y_min - box_.y_min) * int size = 2 * size_outter * size_outter / size_inner;
(size_outter - 1) / size_inner;
int size = 2 * float(size_outter) * (size_outter - 1) / size_inner + 2;
size = std::max(size, 1); 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; const int x = stencil.x_max;
for (int y = stencil.y_min; y <= stencil.y_max; ++y) { for (int y = stencil.y_min; y <= stencil.y_max; ++y) {
bool up = (2 * y + -1 >= start_y) && (2 * y - 1 <= start_y + size); int y_up = 2 * y + 0;
bool down = (2 * y - 0 >= start_y) && (2 * y - 0 <= start_y + size); 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 ? "" : " "); const char* c = up ? (down ? "" : "") : (down ? "" : " ");
screen.PixelAt(x, y) = Pixel(); screen.PixelAt(x, y) = Pixel();
screen.PixelAt(x, y).character = c; screen.PixelAt(x, y).character = c;
screen.PixelAt(x, y).inverted = true;
} }
}; };
}; };