mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 18:59:59 +08:00
3b4ab618a3
In the past, FTXUI switched from std::string to std::wstring to support fullwidth characters. The reasons was that fullwidth characters can be stored inside a single wchar_t. Then FTXUI added support for combining characters. A single glygh doesn't even fit a wchar_t. Instead, a glyph can be arbitrary large. The usage of wstring doesn't really fit the new model and have several drawbacks: 1. It doesn't simplify the implementation of FTXUI, because of combining characters. 2. It reduces drawing performance by 2x. 3. It increase Screen's memory allocation by 2x. This patch converts FTXUI to use std::string internally. It now exposes std::string based API. The std::wstring API remains, but is now deprecated. Tests and examples haven't been update to show the breakage is limited. They will be updated in a second set of patches. Bug: https://github.com/ArthurSonzogni/FTXUI/issues/153 Co-authored-by: Tushar Maheshwari <tushar27192@gmail.com>
122 lines
3.8 KiB
C++
122 lines
3.8 KiB
C++
#ifndef FTXUI_DOM_ELEMENTS_HPP
|
|
#define FTXUI_DOM_ELEMENTS_HPP
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
|
|
#include "ftxui/dom/node.hpp"
|
|
#include "ftxui/screen/box.hpp"
|
|
#include "ftxui/screen/color.hpp"
|
|
#include "ftxui/screen/screen.hpp"
|
|
#include "ftxui/screen/terminal.hpp"
|
|
|
|
namespace ftxui {
|
|
class Node;
|
|
using Element = std::shared_ptr<Node>;
|
|
using Elements = std::vector<Element>;
|
|
using Decorator = std::function<Element(Element)>;
|
|
using GraphFunction = std::function<std::vector<int>(int, int)>;
|
|
|
|
// 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);
|
|
|
|
// --- Widget ---
|
|
Element text(std::string text);
|
|
Element vtext(std::string text);
|
|
Element separator(void);
|
|
Element separator(Pixel);
|
|
Element gauge(float ratio);
|
|
Element border(Element);
|
|
Decorator borderWith(Pixel);
|
|
Element window(Element title, Element content);
|
|
Element spinner(int charset_index, size_t image_index);
|
|
Elements paragraph(std::string text); // Use inside hflow(). Split by space.
|
|
Element graph(GraphFunction);
|
|
|
|
// -- Decorator ---
|
|
Element bold(Element);
|
|
Element dim(Element);
|
|
Element inverted(Element);
|
|
Element underlined(Element);
|
|
Element blink(Element);
|
|
Decorator color(Color);
|
|
Decorator bgcolor(Color);
|
|
Element color(Color, Element);
|
|
Element bgcolor(Color, Element);
|
|
|
|
// --- Layout is
|
|
// Horizontal, Vertical or stacked set of elements.
|
|
Element hbox(Elements);
|
|
Element vbox(Elements);
|
|
Element dbox(Elements);
|
|
Element hflow(Elements);
|
|
|
|
// -- Flexibility ---
|
|
// Define how to share the remaining space when not all of it is used inside a
|
|
// container.
|
|
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 xflex(Element); // Expand/Minimize if possible/needed on X axis.
|
|
Element xflex_grow(Element); // Expand element if possible on X axis.
|
|
Element xflex_shrink(Element); // Minimize element if needed on X axis.
|
|
|
|
Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
|
|
Element yflex_grow(Element); // Expand element if possible on Y axis.
|
|
Element yflex_shrink(Element); // Minimize element if needed on Y axis.
|
|
|
|
Element notflex(Element); // Reset the flex attribute.
|
|
Element filler(); // A blank expandable element.
|
|
|
|
// -- Size override;
|
|
enum Direction { WIDTH, HEIGHT };
|
|
enum Constraint { LESS_THAN, EQUAL, GREATER_THAN };
|
|
Decorator size(Direction, Constraint, int value);
|
|
|
|
// --
|
|
Decorator reflect(Box& box);
|
|
|
|
// --- 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);
|
|
Element xframe(Element);
|
|
Element yframe(Element);
|
|
Element focus(Element);
|
|
Element select(Element);
|
|
|
|
// --- Util --------------------------------------------------------------------
|
|
Element hcenter(Element);
|
|
Element vcenter(Element);
|
|
Element center(Element);
|
|
Element align_right(Element);
|
|
Element nothing(Element element);
|
|
|
|
// Before drawing the |element| clear the pixel below. This is useful in
|
|
// combinaison with dbox.
|
|
Element clear_under(Element element);
|
|
|
|
namespace Dimension {
|
|
Dimensions Fit(Element&);
|
|
} // namespace Dimension
|
|
|
|
} // namespace ftxui
|
|
|
|
// Make container able to take any number of children as input.
|
|
#include "ftxui/dom/take_any_args.hpp"
|
|
|
|
// Include old definitions using wstring.
|
|
#include "ftxui/dom/deprecated.hpp"
|
|
#endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */
|
|
|
|
// 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.
|