FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
ftxui / dom

title-img

このモジュールは、ftxui::Elementの階層セットを定義します。要素はレイアウトを管理し、ターミナルの寸法変更に反応できます。このモジュールが多数の演算子を使用してシンプルなレイアウトを作成するために使用される以下の例に注目してください。

Example セクションには、例のコレクションが用意されています。

例:

namespace ftxui {
...
// Define the document
Element document = vbox({
text("The window") | bold | color(Color::Blue),
gauge(0.5)
text("The footer")
});
// Add a border, by calling the `ftxui::border` decorator function.
document = border(document);
// Add another border, using the pipe operator.
document = document | border.
// Add another border, using the |= operator.
document |= border
...
}
Element text(std::string_view text)
UTF8エンコードされたユニコードテキストを表示します。
Element color(Color color, Element child)
要素の前景色を設定します。
Definition dom/color.cpp:81
Element gauge(float progress)
高精細プログレスバーを描画します。
Element vbox(Elements children)
要素を縦に一つずつ表示するコンテナ。
Definition vbox.cpp:95
FTXUI ftxui::名前空間
Definition animation.hpp:11

要素の一覧

すべての要素の一覧が含まれており、対応するヘッダーファイルを インクルードすることでアクセスできます:

// 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.
#ifndef FTXUI_DOM_ELEMENTS_HPP
#define FTXUI_DOM_ELEMENTS_HPP
#include <cstdint>
#include <functional>
#include <memory>
#include <string_view>
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)>;
/// @brief BorderStyleは、ターミナルUIの要素に適用できる様々なボーダースタイルを表す列挙型です。
///
/// BorderStyleは、ターミナルUIの要素に適用できる様々なボーダースタイルを表す列挙型です。
/// ウィンドウ、フレーム、セパレータなどの要素の周囲の境界線の視覚的な外観を定義するために使用されます。
/// @ingroup dom
enum BorderStyle : uint8_t {
};
// デコレータと共に要素をパイプします。
// 例えば、次の行は同等です:
// -> text("ftxui") | bold | underlined
// -> underlined(bold(text("FTXUI")))
// --- ウィジェット ---
FTXUI_EXPORT(DOM) Element text(std::string_view text);
FTXUI_EXPORT(DOM) Element vtext(std::string_view text);
FTXUI_EXPORT(DOM) Element separator();
FTXUI_EXPORT(DOM) Element separatorLight();
FTXUI_EXPORT(DOM) Element separatorHeavy();
FTXUI_EXPORT(DOM) Element separator(Cell);
FTXUI_EXPORT(DOM) Element separatorCharacter(std::string_view);
float right,
Color unselected_color,
Color selected_color);
float down,
Color unselected_color,
Color selected_color);
FTXUI_EXPORT(DOM) Element gauge(float progress);
FTXUI_EXPORT(DOM) Element gaugeLeft(float progress);
FTXUI_EXPORT(DOM) Element gaugeRight(float progress);
FTXUI_EXPORT(DOM) Element gaugeUp(float progress);
FTXUI_EXPORT(DOM) Element gaugeDown(float progress);
// charset[0]は"空"のグリフで、charset.back()は"満杯"です。間にある
// エントリは境界セルを陰影付けします。
Element gaugeCharset(float progress,
std::vector<std::string> charset,
FTXUI_EXPORT(DOM) Decorator borderWith(const Cell&);
Element window(Element title, Element content, BorderStyle border = ROUNDED);
FTXUI_EXPORT(DOM) Element spinner(int charset_index, size_t image_index);
FTXUI_EXPORT(DOM) Element paragraph(std::string_view text);
FTXUI_EXPORT(DOM) Element paragraphAlignLeft(std::string_view text);
FTXUI_EXPORT(DOM) Element paragraphAlignRight(std::string_view text);
FTXUI_EXPORT(DOM) Element paragraphAlignCenter(std::string_view text);
FTXUI_EXPORT(DOM) Element paragraphAlignJustify(std::string_view text);
FTXUI_EXPORT(DOM) Element canvas(ConstRef<Canvas>);
Element canvas(int width, int height, std::function<void(Canvas&)>);
FTXUI_EXPORT(DOM) Element canvas(std::function<void(Canvas&)>);
// -- デコレータ ---
FTXUI_EXPORT(DOM) Decorator color(const LinearGradient&);
FTXUI_EXPORT(DOM) Decorator bgcolor(const LinearGradient&);
FTXUI_EXPORT(DOM) Element color(const LinearGradient&, Element);
FTXUI_EXPORT(DOM) Element bgcolor(const LinearGradient&, Element);
FTXUI_EXPORT(DOM) Decorator hyperlink(std::string_view link);
FTXUI_EXPORT(DOM) Element hyperlink(std::string_view link, Element child);
FTXUI_EXPORT(DOM) Decorator selectionColor(Color foreground);
FTXUI_EXPORT(DOM) Decorator selectionStyle(std::function<void(Cell&)> style);
// --- レイアウトは
// 水平、垂直、またはスタックされた要素のセットです。
Element flexbox(Elements, FlexboxConfig config = FlexboxConfig());
FTXUI_EXPORT(DOM) Element gridbox(std::vector<Elements> lines);
Element hflow(Elements); // ヘルパー: 行方向のデフォルトflexbox。
Element vflow(Elements); // ヘルパー: 列方向のデフォルトflexbox。
// -- 柔軟性 ---
// コンテナ内ですべてが使用されていない残りのスペースを
// どのように共有するかを定義します。
FTXUI_EXPORT(DOM) Element flex(Element); // 可能/必要な場合に拡大/最小化します。
FTXUI_EXPORT(DOM) Element flex_grow(Element); // 可能な場合に要素を拡大します。
FTXUI_EXPORT(DOM) Element flex_shrink(Element); // 必要な場合に要素を最小化します。
Element xflex(Element); // X軸で可能/必要な場合に拡大/最小化します。
Element xflex_grow(Element); // X軸で可能な場合に要素を拡大します。
Element xflex_shrink(Element); // X軸で必要な場合に要素を最小化します。
Element yflex(Element); // Y軸で可能/必要な場合に拡大/最小化します。
Element yflex_grow(Element); // Y軸で可能な場合に要素を拡大します。
Element yflex_shrink(Element); // Y軸で必要な場合に要素を最小化します。
FTXUI_EXPORT(DOM) Element notflex(Element); // flex属性をリセットします。
FTXUI_EXPORT(DOM) Element filler(); // 空白の拡大可能な要素。
// -- サイズのオーバーライド;
enum WidthOrHeight : uint8_t { WIDTH, HEIGHT };
enum Constraint : uint8_t { LESS_THAN, EQUAL, GREATER_THAN };
// --- フレーム ---
// フレームはスクロール可能な領域です。内部領域は外部領域よりも
// 大きい可能性があります。内部領域は、フォーカスされた要素を
// 表示させるためにスクロールされます。
FTXUI_EXPORT(DOM) Element select(Element e); // 非推奨 - focusのエイリアス。
// --- カーソル ---
// これらは`focus`に似ていますが、カーソルの形状も変更します。
// --- その他 ---
// |element|を描画する前に、下のピクセルをクリアします。これはdboxと
// 組み合わせて使用すると便利です。
// --- ユーティリティ --------------------------------------------------------------------
namespace Dimension {
FTXUI_EXPORT(DOM) Dimensions Fit(Element&, bool extend_beyond_screen = false);
} // namespace Dimension
} // namespace ftxui
// コンテナが入力として任意の数の子を取れるようにします。
#include "ftxui/dom/take_any_args.hpp"
// wstringを使用した古い定義を含めます。
#endif // FTXUI_DOM_ELEMENTS_HPP
#define FTXUI_EXPORT(component)
Definition export.hpp:25
Element window(Element title, Element content, BorderStyle border=ROUNDED)
要素の周囲にタイトルとボーダーを持つウィンドウを描画します。
Element borderDouble(Element child)
要素の周囲に二重線のボーダーを描画します。
Element focusCursorBarBlinking(Element child)
focus と同じですが、カーソル形状を点滅バーに設定します。
Definition frame.cpp:188
Element xflex(Element)
必要に応じてX軸上で拡大・縮小します。
Definition flex.cpp:99
Element gaugeDirection(float progress, Direction direction)
指定された方向に進行する高精細プログレスバーを描画します。
Decorator focusPositionRelative(float x, float y)
frame内で使用され、ビューを特定の位置にスクロールさせます。位置は要求されたサイズの割合で表されます。
Element separatorStyled(BorderStyle style)
他の2つの要素の間に垂直または水平の区切り線を描画します。
Element xflex_grow(Element)
可能であればX軸上で拡大します。
Definition flex.cpp:117
Element underlinedDouble(Element child)
テキストに二重下線を適用します。
Element clear_under(Element element)
|child|を描画する前に、その下のセルをクリアする。これは dboxとの組み合わせで有用。
Element borderDashed(Element child)
要素の周囲に破線のボーダーを描画します。
Element separatorEmpty()
他の2つの要素の間にEMPTYスタイルで垂直または水平の区切り線を描画します。
Element vscroll_indicator(Element child)
右側に垂直スクロールバーを表示します。 色はコンテンツに従います。
Element nothing(Element element)
何も行わないデコレーションです。
Definition dom/util.cpp:28
Element paragraphAlignLeft(std::string_view the_text)
段落を複数行にわたって左揃えで描画する要素を返します。
Decorator size(WidthOrHeight direction, Constraint constraint, int value)
要素のサイズに制約を適用する。
Element flex(Element child)
子要素をコンテナに残されたスペースに比例して拡大させます。
Definition flex.cpp:93
Element hyperlink(std::string_view link, Element child)
ウェブブラウザを使用してレンダリングされた領域をクリック可能にします。 ユーザーがクリックするとリンクが開きます。 これは、限られたターミナルエミュレータでのみサポートされています。 リスト: http...
Definition hyperlink.cpp:52
Element gaugeRight(float progress)
左から右へ進行する高精細プログレスバーを描画します。
Element focusCursorUnderlineBlinking(Element child)
focus と同じですが、カーソル形状を点滅下線に設定します。
Definition frame.cpp:216
Element bold(Element child)
より強調したい要素に、太字フォントを使用します。
Definition bold.cpp:33
Element spinner(int charset_index, size_t image_index)
時間やイベントの効果を表現するのに便利です。これはアスキーアートの「ビデオ」を表示します。
Element borderRounded(Element child)
要素の周囲に角の丸いボーダーを描画します。
Element emptyElement()
Definition dom/util.cpp:140
Element yflex(Element)
必要に応じてY軸上で拡大・縮小します。
Definition flex.cpp:105
Element flex_shrink(Element child)
必要であれば最小化します。
Definition flex.cpp:129
Element focusCursorBar(Element child)
focus と同じですが、カーソル形状を静止ブロックに設定します。
Definition frame.cpp:174
Element focusCursorBlock(Element child)
focus と同じですが、カーソル形状を静止ブロックに設定します。
Definition frame.cpp:146
Element vtext(std::string_view text)
ユニコードテキストを垂直に表示します。
BorderStyle
BorderStyleは、ターミナルUIの要素に適用できる様々なボーダースタイルを表す列挙型です。
Definition elements.hpp:35
Element underlined(Element child)
指定された要素に下線を追加します。
Element center(Element child)
要素を水平方向および垂直方向に中央揃えします。
Element paragraphAlignJustify(std::string_view the_text)
段落を複数行にわたって両端揃えで描画する要素を返します。 中央に。
Direction
Directionは、東西南北の4つの基本方向を表す列挙型です。
Definition direction.hpp:14
Element focusCursorUnderline(Element child)
focus と同じですが、カーソル形状を静止下線に設定します。
Definition frame.cpp:202
Element borderHeavy(Element child)
要素の周囲に太いボーダーを描画します。
Element inverted(Element child)
前景色と背景色を反転させるフィルターを追加します。
Definition inverted.cpp:33
Element gaugeUp(float progress)
下から上へ進行する高精細プログレスバーを描画します。
Element gaugeCharset(float progress, std::vector< std::string > charset, Direction direction=Direction::Right)
カスタム文字セットを使って高精細なプログレスバーを描画する。
Element align_right(Element child)
要素を右側に揃えます。
Decorator focusPosition(int x, int y)
frame内で使用され、ビューを特定の位置にスクロールさせます。位置はセル数で表されます。
Element yflex_grow(Element)
可能であればY軸上で拡大します。
Definition flex.cpp:123
Element hscroll_indicator(Element child)
下部に水平スクロールバーを表示します。 色はコンテンツに従います。
Element flex_grow(Element child)
可能であれば拡大します。
Definition flex.cpp:111
Element separatorDashed()
他の2つの要素の間にLIGHTスタイルで垂直または水平の区切り線を描画します。
Element notflex(Element child)
要素を柔軟にしないようにします。
Definition flex.cpp:147
Element strikethrough(Element child)
テキストに打ち消し線を適用します。
Element italic(Element child)
テキストに二重下線を適用します。
Definition italic.cpp:17
Element dbox(Elements children_)
複数の要素を互いに重ねて表示する。
Element xflex_shrink(Element)
必要であればX軸上で最小化します。
Definition flex.cpp:135
Decorator borderWith(const Cell &pixel)
borderと同じだが、周囲に一定のCellを使用する。
Element gaugeLeft(float progress)
右から左へ進行する高精細プログレスバーを描画します。
Element paragraphAlignCenter(std::string_view the_text)
段落を複数行にわたって中央揃えで描画する要素を返します。
Element borderLight(Element child)
要素の周囲に細いボーダーを描画します。
Element focus(Element child)
子要素を兄弟要素の中でフォーカスされたものとして設定します。
Definition frame.cpp:101
Element paragraph(std::string_view the_text)
段落を複数行で描画する要素を返します。
Element bgcolor(Color color, Element child)
要素の背景色を設定します。
Definition dom/color.cpp:96
Decorator borderStyled(BorderStyle style)
borderと同じですが、異なるスタイルを使用します。
Element paragraphAlignRight(std::string_view the_text)
段落を複数行にわたって右揃えで描画する要素を返します。
Element filler()
コンテナ内の残りのスペースに比例して拡大する要素。
Definition flex.cpp:69
Element dim(Element child)
強調を抑えたい要素に、明るいフォントを使用します。
Definition dim.cpp:33
Element automerge(Element child)
文字が近くの他の文字と自動的にマージされるようにします。
Definition automerge.cpp:17
Element blink(Element child)
描画されたテキストは、可視と非可視の間で交互に切り替わります。
Definition blink.cpp:33
Element vcenter(Element child)
要素を垂直方向に中央揃えします。
Element separatorDouble()
他の2つの要素の間にHEAVYスタイルで垂直または水平の区切り線を描画します。
Element focusCursorBlockBlinking(Element child)
focus と同じですが、カーソル形状を点滅ブロックに設定します。
Definition frame.cpp:160
Element border(Element child)
要素の周囲にボーダーを描画します。
Element borderEmpty(Element child)
要素の周囲に空のボーダーを描画します。
Element yflex_shrink(Element)
必要であればY軸上で最小化します。
Definition flex.cpp:141
Element hcenter(Element child)
要素を水平方向に中央揃えします。
Element gaugeDown(float progress)
上から下へ進行する高精細プログレスバーを描画します。
@ EMPTY
Definition elements.hpp:41
@ DOUBLE
Definition elements.hpp:39
@ HEAVY
Definition elements.hpp:38
@ ROUNDED
Definition elements.hpp:40
@ DASHED
Definition elements.hpp:37
@ LIGHT
Definition elements.hpp:36
FTXUI ftxui::Dimension::名前空間
bool extend_beyond_screen
Definition elements.hpp:229
@ LESS_THAN
Definition elements.hpp:191
@ GREATER_THAN
Definition elements.hpp:191
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
行/列に要素を表示し、一杯になると次の列/行に折り返すことができるコンテナ。
Definition flexbox.cpp:249
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
Decorator yflex_shrink_factor(int shrink)
Definition flex.cpp:199
size_t image_index
Definition elements.hpp:101
std::shared_ptr< Node > Element
Definition elements.hpp:25
Element xframe(Element child)
frame と同じですが、x軸のみに適用されます。
Definition frame.cpp:125
Decorator xflex_grow_factor(int grow)
Definition flex.cpp:175
FTXUI_EXPORT(DOM) Element gridbox(std Element hflow(Elements)
要素を左から右へ行で表示するコンテナ。一杯になると、下の新しい行から開始します。
Definition flexbox.cpp:266
Decorator yflex_grow_factor(int grow)
Definition flex.cpp:193
Direction direction
Definition elements.hpp:80
Element hbox(Elements children)
要素を水平方向に1つずつ表示するコンテナ。
Definition hbox.cpp:93
std::vector< Element > Elements
Definition elements.hpp:26
Decorator selectionForegroundColor(Color foreground)
要素が選択されたときの描画色を設定します。 スタイルは既存のスタイルに重ねて適用されることに注意してください。
Decorator yflex_factor(int grow, int shrink)
Definition flex.cpp:187
WidthOrHeight
Definition elements.hpp:190
Component operator|(Component component, ComponentDecorator decorator)
Decorator selectionBackgroundColor(Color foreground)
要素が選択されたときの背景色を設定します。 スタイルは既存のスタイルに重ねて適用されることに注意してください。
std::function< Element(Element)> Decorator
Definition elements.hpp:27
Decorator flex_shrink_factor(int shrink)
Definition flex.cpp:163
Element yframe(Element child)
frame と同じですが、y軸のみに適用されます。
Definition frame.cpp:133
Decorator flex_grow_factor(int grow)
Definition flex.cpp:157
Decorator selectionColor(Color foreground)
要素が選択されたときの色を設定します。
int shrink
Definition elements.hpp:162
int y
Definition elements.hpp:131
Element selectionStyleReset(Element child)
要素の選択スタイルをリセットします。
const Element & element
Definition node.hpp:94
Decorator reflect(Box &box)
Definition reflect.cpp:43
std::function< std::vector< int >(int, int)> GraphFunction
Definition elements.hpp:28
Decorator xflex_shrink_factor(int shrink)
Definition flex.cpp:181
FTXUI_EXPORT(DOM) Element separatorCharacter(std Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
Decorator xflex_factor(int grow, int shrink)
Definition flex.cpp:169
Decorator flex_factor(int grow, int shrink)
Definition flex.cpp:151
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
int value
Definition elements.hpp:192
Element canvas(int width, int height, std::function< void(Canvas &)>)
要求されたサイズのキャンバスを描画する要素を生成します。
Element frame(Element child)
要素を「仮想」領域内に表示できるようにします。そのサイズはコンテナよりも大きくすることができます。 この場合、より小さい部分のみが表示されます。フォーカスされた要素を表示するためにビューはスクロール可能...
Definition frame.cpp:117
Component & operator|=(Component &component, ComponentDecorator decorator)
Element select(Element e)
childをその兄弟の中でフォーカスされた要素に設定する。
Definition frame.cpp:108
Decorator selectionStyle(std::function< void(Cell &)> style)
要素が選択されたときのスタイルを設定します。
Element vflow(Elements)
要素を上から下へ行で表示するコンテナ。一杯になると、右側の新しい列から開始します。
Definition flexbox.cpp:283
Element graph(GraphFunction graph_function)
GraphFunctionを使用してグラフを描画します。
std::uint8_t left
Definition screen.cpp:147
std::uint8_t down
Definition screen.cpp:150
std::uint8_t right
Definition screen.cpp:149

text

最も単純なウィジェットです。テキストを表示します。

text("I am a piece of text");
I am a piece of text.

vtext

ftxui::textと同じですが、垂直に表示されます。

コード:

vtext("HELLO");

ターミナルの出力:

H
E
L
L
O

paragraph

ftxui::textに似ていますが、個々の単語はコンテナの幅に応じて複数行に折り返されます。

サンプルコード:

paragraph("A very long text")

ezgif com-gif-maker (4)

より詳細な例については、詳細な例を参照してください。Paragraphには、以下に示す他のバリアントも含まれています。

namespace ftxui {
Element paragraph(std::string text);
Element paragraphAlignLeft(std::string text);
Element paragraphAlignRight(std::string text);
Element paragraphAlignCenter(std::string text);
Element paragraphAlignJustify(std::string text);
}

border

要素の周りに枠線を追加します。

コード:

border(text("The element"))

ターミナルの出力:

┌───────────┐
│The element│
└───────────┘
Note
パイプ演算子を使用しても同じ動作を実現できます。

コード:
text("The element") | border

Borderには、以下に示すさまざまなスタイルもあります。

window

ftxui::windowはftxui::borderですが、追加のヘッダーがあります。要素の周囲にウィンドウを追加するには、それをラップし、ヘッダーとして文字列を指定します。 コード:

window("The window", text("The element"))

ターミナルの出力:

┌The window─┐
│The element│
└───────────┘

separator

コンテナの内容を視覚的に2つに分割するために、垂直/水平の線を 表示します。

コード:

border(
hbox({
text("Left"),
separator(),
text("Right")
})
)

ターミナルの出力:

┌────┬─────┐
│left│right│
└────┴─────┘

Separatorsには、以下に示すさまざまなフレーバーがあります。

namespace ftxui {
Element separator(void);
Element separatorLight();
Element separatorHeavy();
Element separator(Cell);
Element separatorCharacter(std::string);
float right,
Color background,
Color foreground);
float down,
Color background,
Color foreground);
}

gauge

これは進捗の割合を表す視覚要素です。

コード:

border(gauge(0.5))

ターミナルの出力:

┌────────────────────────────────────────────────────────────────────────────┐
│██████████████████████████████████████ │
└────────────────────────────────────────────────────────────────────────────┘

ゲージは以下に示すように様々な向きで表示できます:

namespace {
Element gauge(float ratio);
Element gaugeLeft(float ratio);
Element gaugeRight(float ratio);
Element gaugeUp(float ratio);
Element gaugeDown(float ratio);
Element gaugeDirection(float ratio, GaugeDirection);
}

graph

参照:

Element graph(GraphFunction);

色

ほとんどのターミナルコンソールは、色付きのテキストと色付きの背景を表示できます。FTXUIはすべてのカラーパレットをサポートしています。

Decorator color(Color);
Decorator bgcolor(Color);

カラーギャラリー: image

Palette16

ほとんどのターミナルでは、以下の色がサポートされています。

  • Default
  • Black
  • GrayDark
  • GrayLight
  • White
  • Blue
  • BlueLight
  • Cyan
  • CyanLight
  • Green
  • GreenLight
  • Magenta
  • MagentaLight
  • Red
  • RedLight
  • Yellow
  • YellowLight

パイプ演算子を使った上記の色の使用例:

text("Blue foreground") | color(Color::Blue);
text("Blue background") | bgcolor(Color::Blue);
text("Black on white") | color(Color::Black) | bgcolor(Color::White);

Palette256

256色をサポートするターミナルで。

text("HotPink") | color(Color::HotPink);

トゥルーカラー

TrueColorをサポートするターミナルでは、24ビットRGB色空間を直接使用できます。

以下のコンストラクタを使用して、色の**RGB**または**HSV**値を指定します。

コンストラクタは2つあります:

ftxui::Color::RGB(uint8_t red, uint8_t green, uint8_t blue);
ftxui::Color::HSV(uint8_t hue, uint8_t saturation, uint8_t value);

線形グラデーション

FTXUIは線形グラデーションをサポートしています。前景または背景のいずれかです。

Decorator color(const LinearGradient&);
Decorator bgcolor(const LinearGradient&);

ftxui::LinearGradientは、角度(度数)と色の停止点のリストによって定義されます。

auto gradient = LinearGradient()
.Angle(45)
.AddStop(0.0, Color::Red)
.AddStop(0.5, Color::Green)
.AddStop(1.0, Color::Blue);

簡略化されたコンストラクタも使用できます:

LinearGradient(Color::Red, Color::Blue);
LinearGradient(45, Color::Red, Color::Blue);

デモを参照してください。

Style

色付きのテキストと色付きの背景に加えて、多くのターミナルはbold、italic、dim、underlined、inverted、blinkなどのテキスト効果をサポートしています。

Element bold(Element);
Element italic(Element);
Element dim(Element);
Element inverted(Element);
Element underlined(Element);
Element underlinedDouble(Element);
Element strikethrough(Element);
Element blink(Element);
Decorator color(Color);
Decorator bgcolor(Color);
Decorator colorgrad(LinearGradient);
Decorator bgcolorgrad(LinearGradient);

例

image

これらの効果を使用するには、要素を目的の効果でラップするだけです:

underlined(bold(text("This text is bold and underlined")))

あるいは、パイプ演算子を使って要素にチェーンすることもできます:

text("This text is bold") | bold | underlined

レイアウト

要素を次の方法で配置できます。

  • ftxui::hboxで**水平に**
  • ftxui::vboxで**垂直に**
  • ftxui::gridboxで**グリッド内に**
  • ftxui::flexboxを使用して**一方向に折り返し**

ftxui::hbox、ftxui::vbox、ftxui::fillerを使用した例。

image

ftxui::gridboxを使用した例。

image

flexboxを使用した例。

image

この例と関連するデモを確認してください。

要素はftxui::flexデコレータを使用して柔軟にすることもできます。

コード:

hbox({
text("left") | border ,
text("middle") | border | flex,
text("right") | border,
});

ターミナルの出力:

┌────┐┌─────────────────────────────────────────────────────┐┌─────┐
│left││middle ││right│
└────┘└─────────────────────────────────────────────────────┘└─────┘

コード:

hbox({
text("left") | border ,
text("middle") | border | flex,
text("right") | border | flex,
});

ターミナルの出力:

┌────┐┌───────────────────────────────┐┌───────────────────────────────┐
│left││middle ││right │
└────┘└───────────────────────────────┘└───────────────────────────────┘

テーブル

データを整然としたテーブル形式に簡単に整形できます。

基本的な例:

auto table = Table({
{"Planet", "Radius", "Mass"},
{"Mercury", "2440", "0.330"},
{"Venus", "6052", "4.87"},
{"Earth", "6371", "5.97"},
{"Mars", "3390", "0.642"},
});
table.SelectAll().Border(LIGHT);
table.SelectRow(0).Decorate(bold);
table.SelectRow(0).SeparatorVertical(LIGHT);
table.SelectRow(0).Border(DOUBLE);
auto document = table.Render();

コード例:

image

選択とスタイリング

テーブルの一部を選択し、デコレーターや枠線を適用できます。選択方法には以下が含まれます:

ftxui::TableSelection::SelectAll();
ftxui::TableSelection::SelectCell(column, row);
ftxui::TableSelection::SelectRow(row_index);
ftxui::TableSelection::SelectRows(row_min, row_max);
ftxui::TableSelection::SelectColumn(column_index);
ftxui::TableSelection::SelectColumns(column_min, column_max);
ftxui::TableSelection::SelectRectangle(column_min, column_max, row_min, row_max);

選択が行われたら、以下を適用できます:

ftxui::TableSelection::Decorate(Decorator); // Apply a decorator to the whole selection (cells and borders).
ftxui::TableSelection::DecorateCells(Decorator); // Apply a decorator only to the cells.
ftxui::TableSelection::Border(BorderStyle); // Add a border around the selection.
ftxui::TableSelection::Separator(BorderStyle); //

色付きの枠線

枠線や区切り線にのみ特化してデコレーターを適用することもできます:

// Apply a red border to the whole table.
table.SelectAll().Border(LIGHT, color(Color::Red));
// Apply a blue separator to the first row.
table.SelectRow(0).SeparatorVertical(LIGHT, color(Color::Blue));

枠線を細かく装飾するために、以下のメソッドが利用可能です:

ftxui::TableSelection::DecorateBorder(Decorator); // Apply a decorator to all borders of the selection.
ftxui::TableSelection::DecorateBorderLeft(Decorator); // Apply a decorator to the left border of the selection.
ftxui::TableSelection::DecorateBorderRight(Decorator); // Apply a decorator to the right border of the selection.
ftxui::TableSelection::DecorateBorderTop(Decorator); // Apply a decorator to the top border of the selection.
ftxui::TableSelection::DecorateBorderBottom(Decorator); // Apply a decorator to the bottom border of the selection.
ftxui::TableSelection::DecorateSeparator(Decorator); // Apply a decorator to all separators of the selection.
ftxui::TableSelection::DecorateSeparatorVertical(Decorator); // Apply a decorator to all vertical separators of the selection.
ftxui::TableSelection::DecorateSeparatorHorizontal(Decorator); // Apply a decorator to all horizontal separators of the selection.

キャンバス

API <ftxui/dom/canvas.hpp>を参照してください。

auto c = Canvas(100, 100);
c.DrawPointLine(10, 10, 80, 10, Color::Red);
auto element = canvas(c);

描画はftxui::Canvasで、点字、ブロック、または単純な文字を使用して実行できます。

単純な例:

image

複雑な例:

ezgif com-gif-maker (3)