2019-01-19 07:20:29 +08:00
|
|
|
|
- [Introduction](#introduction)
|
2018-10-21 20:32:25 +08:00
|
|
|
|
- [DOM](#dom)
|
|
|
|
|
* [Style](#style)
|
|
|
|
|
* [Layout](#layout)
|
2019-01-19 07:20:29 +08:00
|
|
|
|
+ [Examples](#examples)
|
2018-10-21 20:32:25 +08:00
|
|
|
|
* [Widget.](#widget)
|
|
|
|
|
+ [text](#text)
|
2019-01-20 05:06:05 +08:00
|
|
|
|
+ [border](#border)
|
2018-10-21 20:32:25 +08:00
|
|
|
|
+ [separator](#separator)
|
|
|
|
|
+ [gauge](#gauge)
|
2019-01-19 07:20:29 +08:00
|
|
|
|
* [Decorator](#decorator)
|
2018-10-21 20:32:25 +08:00
|
|
|
|
- [Components.](#components)
|
|
|
|
|
* [Input](#input)
|
|
|
|
|
* [Menu](#menu)
|
|
|
|
|
* [Toggle.](#toggle)
|
|
|
|
|
|
2019-01-19 07:20:29 +08:00
|
|
|
|
## Introduction
|
|
|
|
|
I highly recommand to not take too long on the tutorial, instead you should try
|
|
|
|
|
to understand the /example/*.
|
|
|
|
|
|
2018-10-21 20:32:25 +08:00
|
|
|
|
## DOM
|
2018-10-10 01:06:03 +08:00
|
|
|
|
All the dom element are declared in one header:
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~cpp
|
2018-10-10 01:06:03 +08:00
|
|
|
|
#include <ftxui/dom/elements.hpp>
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
|
|
It declares the following set of elements:
|
|
|
|
|
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~cpp
|
2019-01-20 05:06:05 +08:00
|
|
|
|
// --- Widget ---
|
2018-10-10 01:06:03 +08:00
|
|
|
|
Element text(std::wstring text);
|
|
|
|
|
Element separator();
|
|
|
|
|
Element gauge(float ratio);
|
2019-01-20 05:06:05 +08:00
|
|
|
|
Element border(Element);
|
2019-01-19 07:20:29 +08:00
|
|
|
|
Element window(Element title, Element content);
|
|
|
|
|
Element spinner(int charset_index, size_t image_index);
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2019-01-06 08:37:26 +08:00
|
|
|
|
// -- Decorator ---
|
2018-10-10 01:06:03 +08:00
|
|
|
|
Element bold(Element);
|
|
|
|
|
Element dim(Element);
|
|
|
|
|
Element inverted(Element);
|
|
|
|
|
Element underlined(Element);
|
2019-01-03 05:33:59 +08:00
|
|
|
|
Element blink(Element);
|
2019-01-06 08:37:26 +08:00
|
|
|
|
Decorator color(Color);
|
|
|
|
|
Decorator bgcolor(Color);
|
2019-01-19 07:20:29 +08:00
|
|
|
|
Element color(Color, Element);
|
|
|
|
|
Element bgcolor(Color, Element);
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2019-01-20 05:06:05 +08:00
|
|
|
|
// --- Layout ---
|
|
|
|
|
// Horizontal, Vertical or stacked set of elements.
|
|
|
|
|
Element vbox(Elements);
|
|
|
|
|
Element hbox(Elements);
|
|
|
|
|
Element dbox(Elements);
|
|
|
|
|
|
|
|
|
|
// -- Flexibility ---
|
|
|
|
|
// Define how to share the remaining space when not all of it is used inside a
|
|
|
|
|
// container.
|
|
|
|
|
Element filler();
|
|
|
|
|
Element flex(Element);
|
|
|
|
|
Decorator size(size_t width, size_t height);
|
|
|
|
|
|
|
|
|
|
// --- 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 focus(Element);
|
|
|
|
|
Element select(Element);
|
|
|
|
|
|
|
|
|
|
// --- Util --------------------------------------------------------------------
|
2018-10-10 01:06:03 +08:00
|
|
|
|
Element hcenter(Element);
|
|
|
|
|
Element vcenter(Element);
|
|
|
|
|
Element center(Element);
|
2019-01-19 07:20:29 +08:00
|
|
|
|
Element align_right(Element);
|
2019-01-03 05:33:59 +08:00
|
|
|
|
Element nothing(Element element);
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:32:25 +08:00
|
|
|
|
### Style
|
|
|
|
|
A terminal console can usually display colored text and colored background.
|
2019-01-03 05:33:59 +08:00
|
|
|
|
The text can also have different effects: bold, dim, underlined, inverted,
|
|
|
|
|
blink.
|
2018-10-21 20:32:25 +08:00
|
|
|
|
|
|
|
|
|
~~~cpp
|
|
|
|
|
Element bold(Element);
|
|
|
|
|
Element dim(Element);
|
|
|
|
|
Element inverted(Element);
|
|
|
|
|
Element underlined(Element);
|
|
|
|
|
Element blink(Element);
|
|
|
|
|
Element color(Color, Element);
|
|
|
|
|
Element bgcolor(Color, Element);
|
|
|
|
|
~~~
|
|
|
|
|
|
|
|
|
|
### Layout
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2019-01-06 08:37:26 +08:00
|
|
|
|
* vbox (Vertical-box)
|
|
|
|
|
* hbox (Horizontal-box)
|
2019-01-19 07:20:29 +08:00
|
|
|
|
* dbox (Depth-box)
|
2019-01-06 08:37:26 +08:00
|
|
|
|
are containers. They are used to compose all the elements together. Each
|
|
|
|
|
children are put side by side. If the container is flexible, the extra space
|
|
|
|
|
available will be shared among the remaining flexible children.
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2019-01-19 07:20:29 +08:00
|
|
|
|
flex(element) can be used to make a non-flexible element flexible. filler() is a
|
|
|
|
|
flexible empty element. You can use it align children on one side of the
|
|
|
|
|
container.
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:32:25 +08:00
|
|
|
|
#### Examples
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~cpp
|
2018-10-10 01:06:03 +08:00
|
|
|
|
hbox(
|
2019-01-20 05:06:05 +08:00
|
|
|
|
text(L"left") | border ,
|
|
|
|
|
text(L"middle") | border | flex,
|
|
|
|
|
text(L"right") | border
|
2018-10-10 01:06:03 +08:00
|
|
|
|
);
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
|
|
|
|
~~~bash
|
2018-10-10 01:06:03 +08:00
|
|
|
|
┌────┐┌─────────────────────────────────────────────────────────────────┐┌─────┐
|
|
|
|
|
│left││middle ││right│
|
|
|
|
|
└────┘└─────────────────────────────────────────────────────────────────┘└─────┘
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~cpp
|
2018-10-10 01:06:03 +08:00
|
|
|
|
hbox(
|
2019-01-20 05:06:05 +08:00
|
|
|
|
text(L"left") | border ,
|
|
|
|
|
text(L"middle") | border | flex,
|
|
|
|
|
text(L"right") | border | flex
|
2018-10-10 01:06:03 +08:00
|
|
|
|
);
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
|
|
|
|
~~~bash
|
2018-10-10 01:06:03 +08:00
|
|
|
|
┌────┐┌───────────────────────────────────┐┌───────────────────────────────────┐
|
|
|
|
|
│left││middle ││right │
|
|
|
|
|
└────┘└───────────────────────────────────┘└───────────────────────────────────┘
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:32:25 +08:00
|
|
|
|
### Widget.
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:32:25 +08:00
|
|
|
|
#### text
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:32:25 +08:00
|
|
|
|
The most simple widget. It display a text.
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~cpp
|
2018-10-10 01:06:03 +08:00
|
|
|
|
text(L"I am a piece of text");
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
|
|
|
|
~~~bash
|
2018-10-10 01:06:03 +08:00
|
|
|
|
I am a piece of text.
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2019-01-20 05:06:05 +08:00
|
|
|
|
#### border
|
2018-10-10 01:06:03 +08:00
|
|
|
|
Add a border arround an element
|
2019-01-06 08:37:26 +08:00
|
|
|
|
~~~cpp
|
2019-01-20 05:06:05 +08:00
|
|
|
|
border(text(L"The element"))
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~bash
|
2018-10-10 01:06:03 +08:00
|
|
|
|
┌───────────┐
|
|
|
|
|
│The element│
|
|
|
|
|
└───────────┘
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:32:25 +08:00
|
|
|
|
#### separator
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
|
|
Display a vertical or horizontal line to visually split the content of a
|
|
|
|
|
container in two.
|
|
|
|
|
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~cpp
|
2019-01-20 05:06:05 +08:00
|
|
|
|
border(hbox(
|
2018-10-21 20:32:25 +08:00
|
|
|
|
vbox(
|
|
|
|
|
text(L"left top"),
|
|
|
|
|
text(L"left bottom")
|
|
|
|
|
),
|
|
|
|
|
separator(),
|
|
|
|
|
vbox(
|
|
|
|
|
text(L"right top"),
|
|
|
|
|
text(L"right bottom")
|
|
|
|
|
)
|
2018-10-10 01:06:03 +08:00
|
|
|
|
));
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~bash
|
2018-10-10 01:06:03 +08:00
|
|
|
|
┌───────────┬────────────┐
|
|
|
|
|
│left top │right top │
|
|
|
|
|
│left bottom│right bottom│
|
|
|
|
|
└───────────┴────────────┘
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:32:25 +08:00
|
|
|
|
#### gauge
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
|
|
A gauge. It can be used to represent a progress bar.
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~c+
|
2019-01-20 05:06:05 +08:00
|
|
|
|
border(gauge(0.5))
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~bash
|
2018-10-10 01:06:03 +08:00
|
|
|
|
┌────────────────────────────────────────────────────────────────────────────┐
|
|
|
|
|
│██████████████████████████████████████ │
|
|
|
|
|
└────────────────────────────────────────────────────────────────────────────┘
|
2018-10-21 20:14:46 +08:00
|
|
|
|
~~~
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2019-01-06 08:37:26 +08:00
|
|
|
|
### Decorator
|
|
|
|
|
|
|
|
|
|
Terminal supports displaying text using differet style: bold, dim, underlined,
|
|
|
|
|
inverted, blink. It even support foreground and background color.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
~~~cpp
|
|
|
|
|
underlined(bold(text(L"This text is bold and underlined")))
|
|
|
|
|
~~~
|
|
|
|
|
|
|
|
|
|
Tips: The pipe operator can be used to chain Decorator:
|
|
|
|
|
~~~cpp
|
|
|
|
|
text(L"This text is bold")) | bold | underlined
|
|
|
|
|
~~~
|
|
|
|
|
|
2018-10-21 20:32:25 +08:00
|
|
|
|
## Components.
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
2019-01-19 07:20:29 +08:00
|
|
|
|
dom element are stateless.
|
2018-10-21 20:32:25 +08:00
|
|
|
|
### Input
|
2019-01-03 05:33:59 +08:00
|
|
|
|
TODO(arthursonzogni): Add Video
|
2018-10-21 20:32:25 +08:00
|
|
|
|
### Menu
|
2019-01-03 05:33:59 +08:00
|
|
|
|
TODO(arthursonzogni): Add Video
|
2018-10-21 20:32:25 +08:00
|
|
|
|
### Toggle.
|
2019-01-03 05:33:59 +08:00
|
|
|
|
TODO(arthursonzogni): Add video
|