mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-10-01 17:29:07 +08:00
Add Graph.
This commit is contained in:
@@ -17,7 +17,7 @@ class CheckBox : public Component {
|
||||
|
||||
//std::wstring checked = L"[X] ";
|
||||
//std::wstring unchecked = L"[ ] ";
|
||||
std::wstring checked = L"☑ ";
|
||||
std::wstring checked = L"▣ ";
|
||||
std::wstring unchecked = L"☐ ";
|
||||
|
||||
Decorator focused_style = inverted;
|
||||
|
@@ -10,7 +10,7 @@ class Component;
|
||||
|
||||
class ScreenInteractive : public Screen {
|
||||
public:
|
||||
static ScreenInteractive FixedSize(size_t dimx, size_t dimy);
|
||||
static ScreenInteractive FixedSize(int dimx, int dimy);
|
||||
static ScreenInteractive Fullscreen();
|
||||
static ScreenInteractive FitComponent();
|
||||
static ScreenInteractive TerminalOutput();
|
||||
@@ -30,7 +30,7 @@ class ScreenInteractive : public Screen {
|
||||
TerminalOutput,
|
||||
};
|
||||
Dimension dimension_ = Dimension::Fixed;
|
||||
ScreenInteractive(size_t dimx, size_t dimy, Dimension dimension);
|
||||
ScreenInteractive(int dimx, int dimy, Dimension dimension);
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "ftxui/dom/graph.hpp"
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/screen/color.hpp"
|
||||
|
||||
@@ -20,6 +21,7 @@ Element border(Element);
|
||||
Element window(Element title, Element content);
|
||||
Element spinner(int charset_index, size_t image_index);
|
||||
Elements paragraph(std::wstring text); // Use inside hflow(). Split by space.
|
||||
Element graph(GraphFunction&); // See graph.hpp
|
||||
|
||||
// -- Decorator ---
|
||||
Element bold(Element);
|
||||
@@ -68,6 +70,7 @@ Element nothing(Element element);
|
||||
// Pipe elements into decorator togethers.
|
||||
// Examples: text("ftxui") | bold | underlined;
|
||||
Element operator|(Element, Decorator);
|
||||
Elements operator|(Elements, Decorator);
|
||||
Decorator operator|(Decorator, Decorator);
|
||||
|
||||
// Make container able to take any number of children as input.
|
||||
|
15
ftxui/include/ftxui/dom/graph.hpp
Normal file
15
ftxui/include/ftxui/dom/graph.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef FTXUI_DOM_GRAPH_HPP
|
||||
#define FTXUI_DOM_GRAPH_HPP
|
||||
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
class GraphFunction {
|
||||
public:
|
||||
virtual std::vector<int> operator()(int width, int height) = 0;
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_DOM_GRAPH_HPP */
|
@@ -25,26 +25,32 @@ struct Pixel {
|
||||
Color foreground_color = Color::Default;
|
||||
};
|
||||
|
||||
struct Dimension {
|
||||
static Dimension Fixed(int);
|
||||
static Dimension Fit(std::unique_ptr<Node>&);
|
||||
static Dimension Full();
|
||||
|
||||
int dimx;
|
||||
int dimy;
|
||||
};
|
||||
|
||||
class Screen {
|
||||
public:
|
||||
// Constructor.
|
||||
Screen(size_t dimx, size_t dimy);
|
||||
|
||||
// Constructor using the terminal.
|
||||
static Screen TerminalFullscreen();
|
||||
static Screen TerminalOutput(std::unique_ptr<Node>& element);
|
||||
static Screen FitDocument(std::unique_ptr<Node>& element);
|
||||
Screen(int dimx, int dimy);
|
||||
static Screen Create(Dimension dimension);
|
||||
static Screen Create(Dimension width, Dimension height);
|
||||
|
||||
// Node write into the screen using Screen::at.
|
||||
wchar_t& at(size_t x, size_t y);
|
||||
Pixel& PixelAt(size_t x, size_t y);
|
||||
wchar_t& at(int x, int y);
|
||||
Pixel& PixelAt(int x, int y);
|
||||
|
||||
// Convert the screen into a printable string in the terminal.
|
||||
std::string ToString();
|
||||
|
||||
// Get screen dimensions.
|
||||
size_t dimx() { return dimx_;}
|
||||
size_t dimy() { return dimy_;}
|
||||
int dimx() { return dimx_;}
|
||||
int dimy() { return dimy_;}
|
||||
|
||||
// Move the terminal cursor n-lines up with n = dimy().
|
||||
std::string ResetPosition();
|
||||
@@ -56,8 +62,8 @@ class Screen {
|
||||
Box stencil;
|
||||
|
||||
protected:
|
||||
size_t dimx_;
|
||||
size_t dimy_;
|
||||
int dimx_;
|
||||
int dimy_;
|
||||
std::vector<std::vector<Pixel>> pixels_;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user