mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 10:40:00 +08:00
Use vscroll_indicator in examples.
This commit is contained in:
parent
535974d291
commit
84287eb217
@ -24,7 +24,8 @@ int main(int argc, const char* argv[]) {
|
||||
}
|
||||
|
||||
auto renderer = Renderer(container, [&] {
|
||||
return container->Render() | frame | size(HEIGHT, LESS_THAN, 10) | border;
|
||||
return container->Render() | vscroll_indicator | frame |
|
||||
size(HEIGHT, LESS_THAN, 10) | border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
|
@ -214,23 +214,25 @@ int main(int argc, const char* argv[]) {
|
||||
};
|
||||
|
||||
auto compiler_renderer = Renderer(compiler_component, [&] {
|
||||
auto compiler_win = window(text("Compiler"), compiler->Render() | frame);
|
||||
auto flags_win = window(text("Flags"), flags->Render() | frame);
|
||||
auto compiler_win = window(text("Compiler"),
|
||||
compiler->Render() | vscroll_indicator | frame);
|
||||
auto flags_win =
|
||||
window(text("Flags"), flags->Render() | vscroll_indicator | frame);
|
||||
auto executable_win = window(text("Executable:"), executable_->Render());
|
||||
auto input_win =
|
||||
window(text("Input"),
|
||||
hbox({
|
||||
vbox({
|
||||
hbox({
|
||||
text("Add: "),
|
||||
input_add->Render(),
|
||||
}) | size(WIDTH, EQUAL, 20) |
|
||||
size(HEIGHT, EQUAL, 1),
|
||||
filler(),
|
||||
}),
|
||||
separator(),
|
||||
input->Render() | frame | size(HEIGHT, EQUAL, 3) | flex,
|
||||
}));
|
||||
window(text("Input"), hbox({
|
||||
vbox({
|
||||
hbox({
|
||||
text("Add: "),
|
||||
input_add->Render(),
|
||||
}) | size(WIDTH, EQUAL, 20) |
|
||||
size(HEIGHT, EQUAL, 1),
|
||||
filler(),
|
||||
}),
|
||||
separator(),
|
||||
input->Render() | vscroll_indicator | frame |
|
||||
size(HEIGHT, EQUAL, 3) | flex,
|
||||
}));
|
||||
return vbox({
|
||||
hbox({
|
||||
compiler_win,
|
||||
@ -240,7 +242,7 @@ int main(int argc, const char* argv[]) {
|
||||
input_win | size(WIDTH, EQUAL, 60),
|
||||
}),
|
||||
filler(),
|
||||
}) | size(HEIGHT, LESS_THAN, 6),
|
||||
}) | size(HEIGHT, LESS_THAN, 8),
|
||||
hflow(render_command()) | flex_grow,
|
||||
}) |
|
||||
flex_grow | border;
|
||||
|
@ -18,7 +18,8 @@ int main(int argc, const char* argv[]) {
|
||||
entries.push_back("Entry " + std::to_string(i));
|
||||
auto radiobox = Menu(&entries, &selected);
|
||||
auto renderer = Renderer(radiobox, [&] {
|
||||
return radiobox->Render() | frame | size(HEIGHT, LESS_THAN, 10) | border;
|
||||
return radiobox->Render() | vscroll_indicator | frame |
|
||||
size(HEIGHT, LESS_THAN, 10) | border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
|
@ -18,7 +18,8 @@ int main(int argc, const char* argv[]) {
|
||||
entries.push_back("RadioBox " + std::to_string(i));
|
||||
auto radiobox = Radiobox(&entries, &selected);
|
||||
auto renderer = Renderer(radiobox, [&] {
|
||||
return radiobox->Render() | frame | size(HEIGHT, LESS_THAN, 10) | border;
|
||||
return radiobox->Render() | vscroll_indicator | frame |
|
||||
size(HEIGHT, LESS_THAN, 10) | border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user