Refactor directory structure.

The goal is to increase the separation in between:

 * ftxui::screen
 * ftxui::dom
 * ftxui::component
This commit is contained in:
Arthur Sonzogni
2019-01-06 17:10:35 +01:00
parent 1d29645cf5
commit 5887114793
70 changed files with 324 additions and 361 deletions

View File

@@ -1,11 +0,0 @@
#ifndef FTX_UI_CORE_BOX
#define FTX_UI_CORE_BOX
struct Box {
int left;
int right;
int top;
int bottom;
};
#endif /* end of include guard: FTX_UI_CORE_BOX */

View File

@@ -2,11 +2,10 @@
#define FTXUI_COMPONENT_COMPONENT_HPP
#include "ftxui/component/delegate.hpp"
#include "ftxui/component/event.hpp"
#include "ftxui/dom/elements.hpp"
#include "ftxui/event.hpp"
namespace ftxui {
namespace component {
namespace ftxui::component {
class Delegate;
class Focus;
@@ -39,7 +38,6 @@ class Component {
Delegate* delegate_;
};
} // namespace component
} // namespace ftxui
} // namespace ftxui::component
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HPP */

View File

@@ -3,8 +3,7 @@
#include "ftxui/component/component_direction.hpp"
namespace ftxui {
namespace component {
namespace ftxui::component {
// A component where focus and events are automatically handled for you.
// It assumes its children are put in the horizontal direction.
@@ -14,7 +13,6 @@ class ComponentHorizontal : public ComponentDirection {
bool HandleDirection(Event) override;
};
} // namespace component
} // namespace ftxui
} // namespace ftxui::component
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HORIZONTAL_H_ */

View File

@@ -3,8 +3,7 @@
#include "ftxui/component/component_direction.hpp"
namespace ftxui {
namespace component {
namespace ftxui::component {
// A component where focus and events are automatically handled for you.
// It assumes its children are put in the vertical direction.
@@ -14,7 +13,6 @@ class ComponentVertical : public ComponentDirection {
bool HandleDirection(Event) override;
};
} // namespace component
} // namespace ftxui
} // namespace ftxui::component
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_VERTICAL_H_ */

View File

@@ -3,8 +3,7 @@
#include "ftxui/dom/elements.hpp"
namespace ftxui {
namespace component {
namespace ftxui::component {
class Component;
@@ -28,7 +27,6 @@ class Delegate {
virtual Delegate* Root() = 0;
};
} // namespace component
} // namespace ftxui
} // namespace ftxui::component
#endif /* end of include guard: FTXUI_COMPONENT_DELEGATE_HPP */

View File

@@ -1,10 +1,10 @@
#ifndef FTXUI_EVENT_H_
#define FTXUI_EVENT_H_
#ifndef FTXUI_COMPONENT_EVENT_HPP
#define FTXUI_COMPONENT_EVENT_HPP
#include <vector>
#include <array>
namespace ftxui {
namespace ftxui::component {
struct Event{
public:
@@ -31,7 +31,7 @@ struct Event{
};
} // namespace ftxui
} // namespace ftxui::component
#endif /* end of include guard: FTXUI_EVENT_H_ */
#endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */

View File

@@ -4,8 +4,7 @@
#include "ftxui/component/component.hpp"
#include <functional>
namespace ftxui {
namespace component {
namespace ftxui::component {
class Input : public Component {
public:
@@ -29,7 +28,6 @@ class Input : public Component {
int cursor_position = 0;
};
} // namespace component
} // namespace ftxui
} // namespace ftxui::component
#endif /* end of include guard: FTXUI_COMPONENT_INPUT_H_ */

View File

@@ -5,8 +5,7 @@
#include "ftxui/dom/elements.hpp"
#include <functional>
namespace ftxui {
namespace component {
namespace ftxui::component {
class Menu : public Component {
public:
@@ -30,7 +29,6 @@ class Menu : public Component {
bool OnEvent(Event) override;
};
} // namespace component
} // namespace ftxui
} // namespace ftxui::Component
#endif /* end of include guard: FTXUI_COMPONENT_MENU */

View File

@@ -1,18 +1,16 @@
#ifndef FTXUI_SCREEN_INTERACTIVE
#define FTXUI_SCREEN_INTERACTIVE
#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
#include "ftxui/screen.hpp"
#include "ftxui/screen/screen.hpp"
#include <functional>
#include <memory>
namespace ftxui {
namespace ftxui::component {
namespace component {
class Delegate;
class Component;
} // namespace component
class Delegate;
class Component;
class ScreenInteractive : public Screen {
class ScreenInteractive : public ftxui::screen::Screen {
public:
static ScreenInteractive FixedSize(size_t dimx, size_t dimy);
static ScreenInteractive Fullscreen();
@@ -21,15 +19,15 @@ class ScreenInteractive : public Screen {
~ScreenInteractive();
component::Delegate* delegate();
void Loop();
std::function<void()> ExitLoopClosure();
std::function<void()> ExitLoopClosure();
private:
class Delegate;
std::unique_ptr<Delegate> delegate_;
void Clear();
void Draw();
bool quit_ = false;
void Clear();
void Draw();
bool quit_ = false;
enum class Dimension {
Fixed,
@@ -41,6 +39,6 @@ class ScreenInteractive : public Screen {
ScreenInteractive(size_t dimx, size_t dimy, Dimension dimension);
};
} // namespace ftxui
} // namespace ftxui::component
#endif /* end of include guard: FTXUI_SCREEN_INTERACTIVE */
#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */

View File

@@ -5,8 +5,7 @@
#include <functional>
#include <string>
namespace ftxui {
namespace component {
namespace ftxui::component {
class Toggle : public Component {
public:
@@ -25,7 +24,6 @@ class Toggle : public Component {
bool OnEvent(Event) override;
};
} // namespace component
} // namespace ftxui
} // namespace ftxui::Component
#endif /* end of include guard: FTXUI_COMPONENT_TOGGLE_H_ */

View File

@@ -0,0 +1,15 @@
#ifndef FTXUI_DOM_BOX_HPP
#define FTXUI_DOM_BOX_HPP
namespace ftxui::dom {
struct Box {
int left;
int right;
int top;
int bottom;
};
}; // namespace ftxui::dom
#endif /* end of include guard: FTXUI_DOM_BOX_HPP */

View File

@@ -3,16 +3,16 @@
#include <functional>
#include "ftxui/color.hpp"
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/color.hpp"
namespace ftxui {
namespace dom {
namespace ftxui::dom {
using Element = std::unique_ptr<Node>;
using Decorator = std::function<Element(Element)>;
using Child = std::unique_ptr<Node>;
using Children = std::vector<Child>;
using Color = ftxui::screen::Color;
// --- Layout ----
Element vbox(Children);
@@ -58,7 +58,6 @@ TAKE_ANY_ARGS(vbox)
TAKE_ANY_ARGS(hbox)
TAKE_ANY_ARGS(dbox)
}; // namespace dom
}; // namespace ftxui
}; // namespace ftxui::dom
#endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */

View File

@@ -1,15 +1,14 @@
#ifndef DOM_NODE_HPP
#define DOM_NODE_HPP
#ifndef FTXUI_DOM_NODE_HPP
#define FTXUI_DOM_NODE_HPP
#include <memory>
#include <vector>
#include "ftxui/requirement.hpp"
#include "ftxui/screen.hpp"
#include "ftxui/box.hpp"
#include "ftxui/dom/box.hpp"
#include "ftxui/dom/requirement.hpp"
#include "ftxui/screen/screen.hpp"
namespace ftxui {
namespace dom {
namespace ftxui::dom {
class Node {
public:
@@ -28,7 +27,7 @@ class Node {
virtual void SetBox(Box box);
// Step 3: Draw this element.
virtual void Render(Screen& screen);
virtual void Render(screen::Screen& screen);
std::vector<std::unique_ptr<Node>> children;
protected:
@@ -36,9 +35,8 @@ class Node {
Box box_;
};
void Render(Screen& screen, Node* node);
void Render(screen::Screen& screen, Node* node);
}; // namespace dom
}; // namespace ftxui
}; // namespace ftxui::dom
#endif /* end of include guard: DOM_NODE_HPP */
#endif /* end of include guard: FTXUI_DOM_NODE_HPP */

View File

@@ -1,7 +1,7 @@
#ifndef FTXUI_REQUIREMENT_HPP
#define FTXUI_REQUIREMENT_HPP
#ifndef FTXUI_DOM_REQUIREMENT_HPP
#define FTXUI_DOM_REQUIREMENT_HPP
namespace ftxui {
namespace ftxui::dom {
struct Requirement {
// The required size to fully draw the element.
@@ -11,6 +11,6 @@ struct Requirement {
struct { int x = 0; int y = 0; } flex;
};
}; // namespace ftxui
}; // namespace ftxui::dom
#endif /* end of include guard: FTXUI_REQUIREMENT_HPP */

View File

@@ -1,9 +1,9 @@
#ifndef FTXUI_COLOR_H_
#define FTXUI_COLOR_H_
#ifndef FTXUI_SCREEN_COLOR
#define FTXUI_SCREEN_COLOR
#include <cstdint>
namespace ftxui {
namespace ftxui::screen {
enum class Color : uint8_t {
// --- Transparent -----
@@ -35,6 +35,6 @@ enum class Color : uint8_t {
YellowLight = 93,
};
}; // namespace ftxui
}; // namespace ftxui::screen
#endif /* end of include guard: FTXUI_COLOR_H_ */

View File

@@ -1,17 +1,18 @@
#ifndef FTXUI_SCREEN
#define FTXUI_SCREEN
#ifndef FTXUI_SCREEN_SCREEN
#define FTXUI_SCREEN_SCREEN
#include <string>
#include <vector>
#include <memory>
#include <ftxui/color.hpp>
#include "ftxui/screen/color.hpp"
namespace ftxui {
namespace dom {
namespace ftxui::dom {
class Node;
}
namespace ftxui::screen {
struct Pixel {
wchar_t character = U' ';
bool blink = false;
@@ -55,6 +56,6 @@ class Screen {
std::vector<std::vector<Pixel>> pixels_;
};
}; // namespace ftxui
}; // namespace ftxui::screen
#endif /* end of include guard: FTXUI_SCREEN */
#endif /* end of include guard: FTXUI_SCREEN_SCREEN */