2021-10-16 05:04:11 +08:00
|
|
|
#include <algorithm> // for max
|
|
|
|
#include <memory> // for make_shared, __shared_ptr_access
|
|
|
|
#include <string> // for string
|
|
|
|
#include <utility> // for move
|
|
|
|
#include <vector> // for __alloc_traits<>::value_type
|
2021-10-12 17:36:19 +08:00
|
|
|
|
2021-10-16 05:04:11 +08:00
|
|
|
#include "ftxui/dom/elements.hpp" // for Element, vscroll_indicator
|
|
|
|
#include "ftxui/dom/node.hpp" // for Node, Elements
|
2021-09-26 21:19:17 +08:00
|
|
|
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
2021-10-16 05:04:11 +08:00
|
|
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
|
|
|
#include "ftxui/screen/box.hpp" // for Box
|
|
|
|
#include "ftxui/screen/screen.hpp" // for Screen, Pixel
|
2021-09-26 21:19:17 +08:00
|
|
|
|
|
|
|
namespace ftxui {
|
|
|
|
|
|
|
|
/// @brief Add a filter that will invert the foreground and the background
|
|
|
|
/// colors.
|
|
|
|
/// @ingroup dom
|
|
|
|
Element vscroll_indicator(Element child) {
|
|
|
|
class Impl : public NodeDecorator {
|
|
|
|
using NodeDecorator::NodeDecorator;
|
|
|
|
|
2021-09-26 21:32:40 +08:00
|
|
|
void ComputeRequirement() override {
|
|
|
|
Node::ComputeRequirement();
|
|
|
|
requirement_ = children_[0]->requirement();
|
|
|
|
requirement_.min_x++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetBox(Box box) override {
|
|
|
|
Node::SetBox(box);
|
|
|
|
if (box_.x_min > box_.x_max)
|
|
|
|
box_.x_max--;
|
|
|
|
children_[0]->SetBox(box);
|
|
|
|
}
|
|
|
|
|
2021-09-26 21:19:17 +08:00
|
|
|
void Render(Screen& screen) final {
|
|
|
|
Node::Render(screen);
|
|
|
|
|
|
|
|
const Box& stencil = screen.stencil;
|
|
|
|
|
2021-09-26 23:30:41 +08:00
|
|
|
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);
|
2021-09-26 21:19:17 +08:00
|
|
|
|
|
|
|
const int x = stencil.x_max;
|
|
|
|
for (int y = stencil.y_min; y <= stencil.y_max; ++y) {
|
2021-09-26 23:30:41 +08:00
|
|
|
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);
|
2021-09-26 21:19:17 +08:00
|
|
|
|
2021-09-26 21:32:40 +08:00
|
|
|
const char* c = up ? (down ? "┃" : "╹") : (down ? "╻" : " ");
|
2022-01-05 19:04:03 +08:00
|
|
|
screen.PixelAt(x, y) = Pixel();
|
2021-09-26 21:32:40 +08:00
|
|
|
screen.PixelAt(x, y).character = c;
|
|
|
|
screen.PixelAt(x, y).inverted = true;
|
2021-09-26 21:19:17 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return std::make_shared<Impl>(std::move(child));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ftxui
|
2021-10-16 05:04:11 +08:00
|
|
|
|
|
|
|
// Copyright 2021 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|