Feature: hscroll_indicator (#753)

This is the symetrical of `vscroll_indicator`.

Requested by @ibrahimnasson.

Fixed:https://github.com/ArthurSonzogni/FTXUI/issues/752
This commit is contained in:
Arthur Sonzogni
2023-09-26 23:08:42 +02:00
committed by GitHub
parent 20d4be286b
commit c24a274292
16 changed files with 185 additions and 22 deletions

View File

@@ -25,6 +25,7 @@ example(menu2)
example(menu_entries)
example(menu_entries_animated)
example(menu_in_frame)
example(menu_in_frame_horizontal)
example(menu_multiple)
example(menu_style)
example(menu_underline_animated_gallery)

View File

@@ -33,19 +33,21 @@ ButtonOption ButtonStyle() {
int main() {
int value = 50;
// The tree of components. This defines how to navigate using the keyboard.
auto buttons =
Container::Vertical({
auto buttons = Container::Vertical({
Container::Horizontal({
Button("-1", [&] { value--; }, ButtonStyle()),
Button("+1", [&] { value++; }, ButtonStyle()),
Button(
"-1", [&] { value--; }, ButtonStyle()),
Button(
"+1", [&] { value++; }, ButtonStyle()),
}) | flex,
Container::Horizontal({
Button("-10", [&] { value -= 10; }, ButtonStyle()),
Button("+10", [&] { value += 10; }, ButtonStyle()),
Button(
"-10", [&] { value -= 10; }, ButtonStyle()),
Button(
"+10", [&] { value += 10; }, ButtonStyle()),
}) | flex,
});
});
// Modify the way to render them on screen:
auto component = Renderer(buttons, [&] {
@@ -53,7 +55,8 @@ int main() {
text("value = " + std::to_string(value)),
separator(),
buttons->Render() | flex,
}) | flex | border;
}) |
flex | border;
});
auto screen = ScreenInteractive::Fullscreen();

View File

@@ -0,0 +1,30 @@
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <memory> // for shared_ptr, __shared_ptr_access
#include <string> // for string, basic_string, operator+, to_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Radiobox, Renderer
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, HEIGHT, LESS_THAN
using namespace ftxui;
int main() {
std::vector<std::string> entries;
int selected = 0;
for (int i = 0; i < 100; ++i)
entries.push_back(std::to_string(i));
auto radiobox = Menu(&entries, &selected, MenuOption::Horizontal());
auto renderer = Renderer(
radiobox, [&] { return radiobox->Render() | hscroll_indicator | frame; });
auto screen = ScreenInteractive::FitComponent();
screen.Loop(renderer);
return 0;
}