2020-04-20 03:00:37 +08:00
|
|
|
// 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.
|
|
|
|
|
2018-10-10 01:06:03 +08:00
|
|
|
#ifndef FTXUI_DOM_ELEMENTS_HPP
|
|
|
|
#define FTXUI_DOM_ELEMENTS_HPP
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2019-01-03 07:35:59 +08:00
|
|
|
#include <functional>
|
2020-05-21 02:36:47 +08:00
|
|
|
#include <memory>
|
2019-01-03 07:35:59 +08:00
|
|
|
|
2018-10-10 01:06:03 +08:00
|
|
|
#include "ftxui/dom/node.hpp"
|
2019-01-07 00:10:35 +08:00
|
|
|
#include "ftxui/screen/color.hpp"
|
2020-05-21 02:36:47 +08:00
|
|
|
#include "ftxui/screen/screen.hpp"
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
namespace ftxui {
|
2020-05-21 02:36:47 +08:00
|
|
|
class Node;
|
|
|
|
using Element = std::shared_ptr<Node>;
|
2019-01-13 01:24:46 +08:00
|
|
|
using Elements = std::vector<Element>;
|
2019-01-03 07:35:59 +08:00
|
|
|
using Decorator = std::function<Element(Element)>;
|
2020-02-12 04:44:55 +08:00
|
|
|
using GraphFunction = std::function<std::vector<int>(int, int)>;
|
2018-09-20 03:52:25 +08:00
|
|
|
|
2020-06-07 21:54:45 +08:00
|
|
|
// Pipe elements into decorator togethers.
|
|
|
|
// For instance the next lines are equivalents:
|
|
|
|
// -> text("ftxui") | bold | underlined
|
|
|
|
// -> underlined(bold(text(L"FTXUI")))
|
|
|
|
Element operator|(Element, Decorator);
|
|
|
|
Elements operator|(Elements, Decorator);
|
|
|
|
Decorator operator|(Decorator, Decorator);
|
|
|
|
|
2019-01-20 05:06:05 +08:00
|
|
|
// --- Widget ---
|
2018-09-22 15:49:43 +08:00
|
|
|
Element text(std::wstring text);
|
2020-06-02 05:40:32 +08:00
|
|
|
Element vtext(std::wstring text);
|
2020-05-21 02:36:47 +08:00
|
|
|
Element separator(void);
|
2019-01-27 09:33:06 +08:00
|
|
|
Element separator(Pixel);
|
2018-09-22 15:49:43 +08:00
|
|
|
Element gauge(float ratio);
|
2019-01-20 05:06:05 +08:00
|
|
|
Element border(Element);
|
2019-01-27 09:33:06 +08:00
|
|
|
Decorator borderWith(Pixel);
|
2019-01-13 01:24:46 +08:00
|
|
|
Element window(Element title, Element content);
|
2019-01-07 05:28:15 +08:00
|
|
|
Element spinner(int charset_index, size_t image_index);
|
2020-02-12 04:44:55 +08:00
|
|
|
Elements paragraph(std::wstring text); // Use inside hflow(). Split by space.
|
2019-01-27 09:33:06 +08:00
|
|
|
Element graph(GraphFunction);
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-05 09:03:49 +08:00
|
|
|
// -- Decorator ---
|
2018-10-10 01:06:03 +08:00
|
|
|
Element bold(Element);
|
|
|
|
Element dim(Element);
|
|
|
|
Element inverted(Element);
|
|
|
|
Element underlined(Element);
|
2018-10-21 20:18:11 +08:00
|
|
|
Element blink(Element);
|
2019-01-03 07:35:59 +08:00
|
|
|
Decorator color(Color);
|
|
|
|
Decorator bgcolor(Color);
|
2019-01-07 05:28:15 +08:00
|
|
|
Element color(Color, Element);
|
|
|
|
Element bgcolor(Color, Element);
|
2018-09-20 03:52:25 +08:00
|
|
|
|
2019-06-23 23:47:33 +08:00
|
|
|
// --- Layout is
|
2019-01-20 05:06:05 +08:00
|
|
|
// Horizontal, Vertical or stacked set of elements.
|
|
|
|
Element hbox(Elements);
|
2019-01-23 06:42:57 +08:00
|
|
|
Element vbox(Elements);
|
2019-01-20 05:06:05 +08:00
|
|
|
Element dbox(Elements);
|
2019-01-23 06:42:57 +08:00
|
|
|
Element hflow(Elements);
|
2019-01-20 05:06:05 +08:00
|
|
|
|
|
|
|
// -- Flexibility ---
|
|
|
|
// Define how to share the remaining space when not all of it is used inside a
|
|
|
|
// container.
|
2020-06-02 05:40:32 +08:00
|
|
|
Element flex(Element); // Expand/Minimize if possible/needed.
|
|
|
|
Element flex_grow(Element); // Expand element if possible.
|
|
|
|
Element flex_shrink(Element); // Minimize element if needed.
|
|
|
|
Element notflex(Element); // Reset the flex attribute.
|
|
|
|
Element filler(); // A blank expandable element.
|
2019-01-21 06:04:10 +08:00
|
|
|
|
|
|
|
// -- Size override;
|
|
|
|
enum Direction { WIDTH, HEIGHT };
|
|
|
|
enum Constraint { LESS_THAN, EQUAL, GREATER_THAN };
|
|
|
|
Decorator size(Direction, Constraint, int value);
|
2019-01-20 05:06:05 +08:00
|
|
|
|
|
|
|
// --- Frame ---
|
|
|
|
// A frame is a scrollable area. The internal area is potentially larger than
|
|
|
|
// the external one. The internal area is scrolled in order to make visible the
|
|
|
|
// focused element.
|
|
|
|
Element frame(Element);
|
2020-06-07 21:54:45 +08:00
|
|
|
Element xframe(Element);
|
|
|
|
Element yframe(Element);
|
2019-01-20 05:06:05 +08:00
|
|
|
Element focus(Element);
|
|
|
|
Element select(Element);
|
|
|
|
|
|
|
|
// --- Util --------------------------------------------------------------------
|
2018-09-22 15:49:43 +08:00
|
|
|
Element hcenter(Element);
|
|
|
|
Element vcenter(Element);
|
|
|
|
Element center(Element);
|
2019-01-07 01:53:02 +08:00
|
|
|
Element align_right(Element);
|
2018-10-21 20:18:11 +08:00
|
|
|
Element nothing(Element element);
|
|
|
|
|
2019-01-06 23:10:57 +08:00
|
|
|
// Make container able to take any number of children as input.
|
|
|
|
#include "take_any_args.hpp"
|
2019-01-05 09:03:49 +08:00
|
|
|
TAKE_ANY_ARGS(vbox)
|
|
|
|
TAKE_ANY_ARGS(hbox)
|
|
|
|
TAKE_ANY_ARGS(dbox)
|
2019-01-23 06:42:57 +08:00
|
|
|
TAKE_ANY_ARGS(hflow)
|
2019-01-03 07:35:59 +08:00
|
|
|
|
2020-02-12 04:44:55 +08:00
|
|
|
} // namespace ftxui
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2018-10-10 01:06:03 +08:00
|
|
|
#endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */
|