File: nested_screen.cpp

package info (click to toggle)
ftxui 5.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,084 kB
  • sloc: cpp: 23,669; xml: 211; sh: 25; javascript: 20; python: 16; makefile: 15
file content (50 lines) | stat: -rw-r--r-- 1,770 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// 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 allocator, shared_ptr, __shared_ptr_access
#include <string>  // for operator+, string, char_traits, basic_string

#include "ftxui/component/captured_mouse.hpp"  // for ftxui
#include "ftxui/component/component.hpp"       // for Button, Vertical, Renderer
#include "ftxui/component/component_base.hpp"  // for ComponentBase
#include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive
#include "ftxui/dom/elements.hpp"  // for separator, text, Element, operator|, vbox, border

using namespace ftxui;

void Nested(std::string path) {
  auto screen = ScreenInteractive::FitComponent();
  auto back_button = Button("Back", screen.ExitLoopClosure());
  auto goto_1 = Button("Goto /1", [path] { Nested(path + "/1"); });
  auto goto_2 = Button("Goto /2", [path] { Nested(path + "/2"); });
  auto goto_3 = Button("Goto /3", [path] { Nested(path + "/3"); });
  auto layout = Container::Vertical({
      back_button,
      goto_1,
      goto_2,
      goto_3,
  });
  auto renderer = Renderer(layout, [&] {
    return vbox({
               text("path: " + path),
               separator(),
               back_button->Render(),
               goto_1->Render(),
               goto_2->Render(),
               goto_3->Render(),
           }) |
           border;
  });
  screen.Loop(renderer);
}

int main() {
  auto screen = ScreenInteractive::FitComponent();
  auto button_quit = Button("Quit", screen.ExitLoopClosure());
  auto button_nested = Button("Nested", [] { Nested(""); });
  screen.Loop(Container::Vertical({
      button_quit,
      button_nested,
  }));
  return 0;
}