Use vscroll_indicator in examples.

This commit is contained in:
ArthurSonzogni
2021-09-26 17:30:41 +02:00
committed by Arthur Sonzogni
parent 535974d291
commit 84287eb217
5 changed files with 35 additions and 27 deletions

View File

@@ -31,17 +31,20 @@ Element vscroll_indicator(Element child) {
const Box& stencil = screen.stencil;
float size_inner = box_.y_max - box_.y_min;
float size_outter = stencil.y_max - stencil.y_min;
float start_y = stencil.y_min +
(stencil.y_min - box_.y_min) * size_outter / size_inner;
float end_y = stencil.y_min +
(stencil.y_max - box_.y_min) * size_outter / size_inner;
int size_inner = box_.y_max - box_.y_min;
int size_outter = stencil.y_max - stencil.y_min;
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;
size = std::max(size, 1);
const int x = stencil.x_max;
for (int y = stencil.y_min; y <= stencil.y_max; ++y) {
bool up = (2 * y + -1 >= 2 * start_y) && (2 * y + -1 <= 2 * end_y);
bool down = (2 * y + 0 >= 2 * start_y) && (2 * y + 0 <= 2 * end_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);
const char* c = up ? (down ? "" : "") : (down ? "" : " ");
screen.PixelAt(x, y).character = c;