patlefort

ftxui big text example

Jul 17th, 2026
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | Source Code | 0 0
  1. #include <ftxui/component/app.hpp>
  2. #include <ftxui/component/component.hpp>
  3. //#include <string_view>
  4. #include <string>
  5. #include <ranges>
  6.  
  7. using namespace ftxui;
  8. using namespace std::literals::string_literals;
  9. //using namespace std::literals::string_view_literals;
  10.  
  11. int main() {
  12.     float scroll_x = 0.1f;
  13.     float scroll_y = 0.1f;
  14.  
  15.     auto scrollable_content = [&]{
  16.         auto bigtext = std::ranges::to<std::string>(
  17.             std::ranges::views::indices(1000000)
  18.                 | std::ranges::views::transform([](const auto i) { return "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "s + std::to_string(i); })
  19.                 | std::ranges::views::join_with("\n"s)
  20.         );
  21.  
  22.         return Renderer([&, content = text(bigtext)] {
  23.             return content | focusPositionRelative(scroll_x, scroll_y) |
  24.                    frame | flex;
  25.             });
  26.     }();
  27.  
  28.     SliderOption<float> option_x;
  29.     option_x.value = &scroll_x;
  30.     option_x.min = 0.f;
  31.     option_x.max = 1.f;
  32.     option_x.increment = 0.1f;
  33.     option_x.direction = Direction::Right;
  34.     option_x.color_active = Color::Blue;
  35.     option_x.color_inactive = Color::BlueLight;
  36.     auto scrollbar_x = Slider(option_x);
  37.  
  38.     SliderOption<float> option_y;
  39.     option_y.value = &scroll_y;
  40.     option_y.min = 0.f;
  41.     option_y.max = 1.f;
  42.     option_y.increment = 0.1f;
  43.     option_y.direction = Direction::Down;
  44.     option_y.color_active = Color::Yellow;
  45.     option_y.color_inactive = Color::YellowLight;
  46.     auto scrollbar_y = Slider(option_y);
  47.  
  48.     auto root = Container::Vertical({
  49.         Container::Horizontal({
  50.             scrollable_content,
  51.             scrollbar_y,
  52.         }) | flex,
  53.         Container::Horizontal({
  54.             scrollbar_x,
  55.             Renderer([] { return text(L"x"); }),
  56.         }),
  57.     });
  58.  
  59.     auto screen = App::Fullscreen();
  60.     screen.Loop(root);
  61.  
  62.     return EXIT_SUCCESS;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment