Remove Ref<XxxOption> and add new interfaces. (#686)

1. Stop taking Ref<XxxOption> in Component constructors. Instead, use
   the XxxOption directly. Passing by copy avoid problems developers had
   where one was shared in between multiple component, causing issues.

2. Add variants of most component constructors taking a struct only.

This replaces:
https://github.com/ArthurSonzogni/FTXUI/pull/670

This fixes:
https://github.com/ArthurSonzogni/FTXUI/issues/426
This commit is contained in:
Arthur Sonzogni
2023-06-25 17:22:05 +02:00
committed by GitHub
parent e73e7f0d68
commit 455998d759
26 changed files with 918 additions and 693 deletions

View File

@@ -845,9 +845,11 @@ class CanvasNodeBase : public Node {
} // namespace
/// @brief Produce an element from a Canvas, or a reference to a Canvas.
// NOLINTNEXTLINE
Element canvas(ConstRef<Canvas> canvas) {
class Impl : public CanvasNodeBase {
public:
// NOLINTNEXTLINE
explicit Impl(ConstRef<Canvas> canvas) : canvas_(std::move(canvas)) {
requirement_.min_x = (canvas_->width() + 1) / 2;
requirement_.min_y = (canvas_->height() + 3) / 4;

View File

@@ -13,10 +13,10 @@ namespace ftxui {
class Hyperlink : public NodeDecorator {
public:
Hyperlink(Element child, std::string link)
: NodeDecorator(std::move(child)), link_(link) {}
: NodeDecorator(std::move(child)), link_(std::move(link)) {}
void Render(Screen& screen) override {
uint8_t hyperlink_id = screen.RegisterHyperlink(link_);
const uint8_t hyperlink_id = screen.RegisterHyperlink(link_);
for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) {
screen.PixelAt(x, y).hyperlink = hyperlink_id;
@@ -44,7 +44,7 @@ class Hyperlink : public NodeDecorator {
/// hyperlink("https://github.com/ArthurSonzogni/FTXUI", "link");
/// ```
Element hyperlink(std::string link, Element child) {
return std::make_shared<Hyperlink>(std::move(child), link);
return std::make_shared<Hyperlink>(std::move(child), std::move(link));
}
/// @brief Decorate using an hyperlink.
@@ -61,6 +61,7 @@ Element hyperlink(std::string link, Element child) {
/// Element document =
/// text("red") | hyperlink("https://github.com/Arthursonzogni/FTXUI");
/// ```
// NOLINTNEXTLINE
Decorator hyperlink(std::string link) {
return [link](Element child) { return hyperlink(link, std::move(child)); };
}