FTXUI  0.8.1
C++ functional terminal UI.
separator.cpp
Go to the documentation of this file.
1 #include <memory> // for make_shared
2 #include <string> // for string
3 
4 #include "ftxui/dom/elements.hpp" // for Element, separator
5 #include "ftxui/dom/node.hpp" // for Node
6 #include "ftxui/dom/requirement.hpp" // for Requirement
7 #include "ftxui/screen/box.hpp" // for Box
8 #include "ftxui/screen/screen.hpp" // for Pixel, Screen
9 
10 namespace ftxui {
11 
12 using ftxui::Screen;
13 
14 class Separator : public Node {
15  public:
16  void ComputeRequirement() override {
17  requirement_.min_x = 1;
18  requirement_.min_y = 1;
19  }
20 
21  void Render(Screen& screen) override {
22  bool is_column = (box_.x_max == box_.x_min);
23  bool is_line = (box_.y_min == box_.y_max);
24 
25  std::string c = "+";
26  if (is_line && !is_column)
27  c = "─";
28  else
29  c = "│";
30 
31  for (int y = box_.y_min; y <= box_.y_max; ++y) {
32  for (int x = box_.x_min; x <= box_.x_max; ++x) {
33  screen.PixelAt(x, y).character = c;
34  }
35  }
36  }
37 };
38 
39 class SeparatorWithPixel : public Separator {
40  public:
41  SeparatorWithPixel(Pixel pixel) : pixel_(pixel) {}
42  void Render(Screen& screen) override {
43  for (int y = box_.y_min; y <= box_.y_max; ++y) {
44  for (int x = box_.x_min; x <= box_.x_max; ++x) {
45  screen.PixelAt(x, y) = pixel_;
46  }
47  }
48  }
49 
50  private:
51  Pixel pixel_;
52 };
53 
55  return std::make_shared<Separator>();
56 }
57 
59  return std::make_shared<SeparatorWithPixel>(pixel);
60 }
61 
62 } // namespace ftxui
63 
64 // Copyright 2020 Arthur Sonzogni. All rights reserved.
65 // Use of this source code is governed by the MIT license that can be found in
66 // the LICENSE file.
ftxui::Requirement::min_x
int min_x
Definition: requirement.hpp:10
ftxui::Box::x_min
int x_min
Definition: box.hpp:7
ftxui::Node::box_
Box box_
Definition: node.hpp:41
ftxui::Box::y_max
int y_max
Definition: box.hpp:10
ftxui
Definition: captured_mouse.hpp:6
node.hpp
box.hpp
requirement.hpp
ftxui::separator
Element separator(void)
Definition: separator.cpp:54
ftxui::Box::x_max
int x_max
Definition: box.hpp:8
elements.hpp
ftxui::Element
std::shared_ptr< Node > Element
Definition: elements.hpp:15
ftxui::Box::y_min
int y_min
Definition: box.hpp:9
ftxui::Screen
A rectangular grid of Pixel.
Definition: screen.hpp:49
ftxui::Requirement::min_y
int min_y
Definition: requirement.hpp:11
ftxui::Render
void Render(Screen &screen, const Element &node)
Display an element on a ftxui::Screen.
Definition: node.cpp:34
ftxui::Node::requirement_
Requirement requirement_
Definition: node.hpp:40
ftxui::Pixel
A unicode character and its associated style.
Definition: screen.hpp:16
screen.hpp