FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
ftxui/component

Detailed Description

Please check the tutorial of the ftxui/component module.

Functions

 FTXUI_EXPORT (COMPONENT) void RequestAnimationFrame()
 RequestAnimationFrame is a function that requests a new frame to be drawn in the next animation cycle.
 
class FTXUI_EXPORT (COMPONENT) ComponentBase = {})
 It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ftxui::Event.
 
Component Button (ButtonOption option)
 Draw a button. Execute a function when clicked.
 
Component Button (ConstStringRef label, std::function< void()> on_click, ButtonOption option)
 Draw a button. Execute a function when clicked.
 
Component CatchEvent (Component child, std::function< bool(Event event)> on_event)
 Return a component, using |on_event| to catch events. This function must returns true when the event has been handled, false otherwise.
 
ComponentDecorator CatchEvent (std::function< bool(Event)> on_event)
 Decorate a component, using |on_event| to catch events. This function must returns true when the event has been handled, false otherwise.
 
Component Checkbox (CheckboxOption option)
 Draw checkable element.
 
Component Checkbox (ConstStringRef label, bool *checked, CheckboxOption option)
 Draw checkable element.
 
Component Vertical (Components children)
 A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or 'j'/'k' keys.
 
Component Vertical (Components children, int *selector)
 A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or 'j'/'k' keys. This is useful for implementing a Menu for instance.
 
Component Horizontal (Components children)
 A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow key or 'h'/'l' keys.
 
Component Horizontal (Components children, int *selector)
 A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow key or 'h'/'l' keys.
 
Component Tab (Components children, int *selector)
 A list of components, where only one is drawn and interacted with at a time. The |selector| gives the index of the selected component. This is useful to implement tabs.
 
Component Stacked (Components children)
 A list of components to be stacked on top of each other. Events are propagated to the first component, then the second if not handled, etc. The components are drawn in the reverse order they are given. When a component take focus, it is put at the front, without changing the relative order of the other elements.
 
Component Dropdown (ConstStringListRef entries, int *selected)
 A dropdown menu.
 
Component Dropdown (DropdownOption option)
 A dropdown menu.
 
Component Hoverable (Component component, bool *hover)
 Wrap a component. Gives the ability to know if it is hovered by the mouse.
 
Component Hoverable (Component component, std::function< void()> on_enter, std::function< void()> on_leave)
 Wrap a component. Uses callbacks.
 
ComponentDecorator Hoverable (bool *hover)
 Wrap a component. Gives the ability to know if it is hovered by the mouse.
 
ComponentDecorator Hoverable (std::function< void()> on_enter, std::function< void()> on_leave)
 Wrap a component. Gives the ability to know if it is hovered by the mouse.
 
Component Hoverable (Component component, std::function< void(bool)> on_change)
 Wrap a component. Gives the ability to know if it is hovered by the mouse.
 
ComponentDecorator Hoverable (std::function< void(bool)> on_change)
 Wrap a component. Gives the ability to know if it is hovered by the mouse.
 
Component Input (InputOption option)
 An input box for editing text.
 
Component Input (StringRef content, InputOption option)
 An input box for editing text.
 
Component Input (StringRef content, StringRef placeholder, InputOption option)
 An input box for editing text.
 
Component Maybe (Component child, std::function< bool()> show)
 Decorate a component |child|. It is shown only when |show| returns true.
 
ComponentDecorator Maybe (std::function< bool()> show)
 Decorate a component. It is shown only when the |show| function returns true.
 
Component Maybe (Component child, const bool *show)
 Decorate a component |child|. It is shown only when |show| is true.
 
ComponentDecorator Maybe (const bool *show)
 Decorate a component. It is shown only when |show| is true.
 
Component Menu (MenuOption option)
 A list of text. The focused element is selected.
 
Component Menu (ConstStringListRef entries, int *selected, MenuOption option)
 A list of text. The focused element is selected.
 
Component Toggle (ConstStringListRef entries, int *selected)
 An horizontal list of elements. The user can navigate through them.
 
Component MenuEntry (ConstStringRef label, MenuEntryOption option)
 A specific menu entry. They can be put into a Container::Vertical to form a menu.
 
Component MenuEntry (MenuEntryOption option)
 A specific menu entry. They can be put into a Container::Vertical to form a menu.
 
FTXUI_EXPORT(COMPONENT) ComponentDecorator Maybe(std Component Modal (Component main, Component modal, const bool *show_modal)
 
ComponentDecorator Modal (Component modal, const bool *show_modal)
 
Component Radiobox (RadioboxOption option)
 A list of element, where only one can be selected.
 
Component Radiobox (ConstStringListRef entries, int *selected, RadioboxOption option)
 A list of element, where only one can be selected.
 
Component Renderer (std::function< Element()> render)
 Return a component, using |render| to render its interface.
 
Component Renderer (Component child, std::function< Element()> render)
 Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
 
FTXUI_EXPORT(COMPONENT) Component Renderer(std Component Renderer (std::function< Element(bool)> render)
 Return a focusable component, using |render| to render its interface.
 
ComponentDecorator Renderer (ElementDecorator decorator)
 Decorate a component, by decorating what it renders.
 
Component ResizableSplitLeft (Component main, Component back, int *main_size)
 An horizontal split in between two components, configurable using the mouse.
 
Component ResizableSplitRight (Component main, Component back, int *main_size)
 An horizontal split in between two components, configurable using the mouse.
 
Component ResizableSplitTop (Component main, Component back, int *main_size)
 An vertical split in between two components, configurable using the mouse.
 
Component ResizableSplitBottom (Component main, Component back, int *main_size)
 An vertical split in between two components, configurable using the mouse.
 
Component Slider (ConstStringRef label, Ref< int > value, ConstRef< int > min, ConstRef< int > max, ConstRef< int > increment)
 An horizontal slider.
 
Component Window (WindowOptions option)
 A draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stacked({...}) component;.
 

Function Documentation

◆ FTXUI_EXPORT() [1/2]

class FTXUI_EXPORT ( COMPONENT )

RequestAnimationFrame is a function that requests a new frame to be drawn in the next animation cycle.

Note
This function is typically called by components that need to update their state or appearance over time, such as animations or transitions. This is useful when the change doesn't depend depend on the events seen by the terminal, but rather on the passage of time.

Components who haven't completed their animation can call this function to request a new frame to be drawn later.

When there is no new events and no animations to complete, no new frame is drawn.

The duration this animation step represents.

The duration this animation step represents.

Definition at line 27 of file animation.hpp.

◆ FTXUI_EXPORT() [2/2]

template FTXUI_EXPORT ( COMPONENT ) = {})

It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ftxui::Event.

A mouse event. It contains the coordinate of the mouse, the button pressed and the modifier (shift, ctrl, meta).

Loop is a class that manages the event loop for a component.

Represent an event. It can be key press event, a terminal resize, or more ...

Option for the Dropdown component.

A dropdown menu is a checkbox opening/closing a radiobox.

State passed to the Window component's render function.

Option for the Radiobox component.

Option for the Input component.

Used to define style for the Input component.

Option for the Checkbox component.

Option for the AnimatedButton component.

Option for the Menu component.

Option for the MenuEntry component.

Option about a potentially animated color.

Option for the underline effect.

arguments for transform from |ButtonOption|, |CheckboxOption|, |RadioboxOption|, |MenuEntryOption|, |MenuOption|.

For example:

  • Printable character can be created using Event::Character('a').
  • Some special are predefined, like Event::ArrowLeft.
  • One can find arbitrary code for special Events using: ./example/util/print_key_press For instance, CTLR+A maps to Event::Special({1});

Useful documentation about xterm specification: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html

It is responsible for running the component, handling events, and updating the screen.

The Loop class is designed to be used with an App object, which represents the terminal screen.

Example

int main() {
auto screen = ftxui::App::TerminalOutput();
auto component = ftxui::Button("Click me", [] { ... });
ftxui::Loop loop(screen.get(), component);
// Either
loop.Run(); // Blocking until the component quits.
// Or
loop.RunOnce(); // Non-blocking, returns immediately.
// Or
loop.RunOnceBlocking(); // Blocking until handling one event.
// Or in a loop:
while (!loop.HasQuitted()) {
loop.RunOnce();
// Do something else like running a different library loop function.
}
}
Component Button(ConstStringRef label, std::function< void()> on_click, ButtonOption options=ButtonOption::Simple())
Draw a button. Execute a function when clicked.

< The label to display.

< The state of the button/checkbox/radiobox

< Whether the entry is the active one.

< Whether the entry is one focused by the user.

< Index of the entry when applicable or -1.

‍The list of entries.

‍The index of the selected entry.

‍Called when the selected entry changes.

‍Called when the user presses enter.

Called when the user change the state.

< Whether the input is hovered by the mouse.

< Whether the input is focused by the user.

< Whether the input is empty and displaying the placeholder.

Create the default input style:

A white on black style with high margins:

The content of the input.

The content of the input when it's empty.

< Obscure the input content using '*'.

< Whether the input can be multiline.

< Insert or overtype character mode.

Called when the content changes.

Called when the user presses enter.

Called when the selected entry changes.

< The element wrapped inside this window.

< The title of the window.

< Whether the window is the active one.

< Whether the window is being dragged.

< Whether the window is being resized.

< Whether the resizeable left side is hovered.

< Whether the resizeable right side is hovered.

< Whether the resizeable top side is hovered.

< Whether the resizeable down side is hovered.

< The component wrapped by this window.

< The title displayed by this window.

< The left side position of the window.

< The top side position of the window.

< The width of the window.

< The height of the window.

< Can the left side be resized?

< Can the right side be resized?

< Can the top side be resized?

< Can the down side be resized?

An optional function to customize how the window looks like:

Whether the dropdown is open or closed:

Supported terminal only.

Supported terminal only.

< The label to display.

< The state of the button/checkbox/radiobox

< Whether the entry is the active one.

< Whether the entry is one focused by the user.

< Index of the entry when applicable or -1.

‍The list of entries.

‍The index of the selected entry.

‍Called when the selected entry changes.

‍Called when the user presses enter.

Called when the user change the state.

< Whether the input is hovered by the mouse.

< Whether the input is focused by the user.

< Whether the input is empty and displaying the placeholder.

Create the default input style:

A white on black style with high margins:

The content of the input.

The content of the input when it's empty.

< Obscure the input content using '*'.

< Whether the input can be multiline.

< Insert or overtype character mode.

Called when the content changes.

Called when the user presses enter.

Called when the selected entry changes.

< The element wrapped inside this window.

< The title of the window.

< Whether the window is the active one.

< Whether the window is being dragged.

< Whether the window is being resized.

< Whether the resizeable left side is hovered.

< Whether the resizeable right side is hovered.

< Whether the resizeable top side is hovered.

< Whether the resizeable down side is hovered.

< The component wrapped by this window.

< The title displayed by this window.

< The left side position of the window.

< The top side position of the window.

< The width of the window.

< The height of the window.

< Can the left side be resized?

< Can the right side be resized?

< Can the top side be resized?

< Can the down side be resized?

An optional function to customize how the window looks like:

Whether the dropdown is open or closed:

Supported terminal only.

Supported terminal only.

Definition at line 1 of file captured_mouse.hpp.

◆ Button() [1/2]

Component Button ( ButtonOption option)

Draw a button. Execute a function when clicked.

Parameters
optionAdditional optional parameters.
See also
ButtonBase

Example

auto screen = App::FitComponent();
Component button = Button({
.label = "Click to quit",
.on_click = screen.ExitLoopClosure(),
});
screen.Loop(button)
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23

Output

┌─────────────┐
│Click to quit│
└─────────────┘

Definition at line 174 of file src/ftxui/component/button.cpp.

◆ Button() [2/2]

Component Button ( ConstStringRef label,
std::function< void()> on_click,
ButtonOption option )

Draw a button. Execute a function when clicked.

Parameters
labelThe label of the button.
on_clickThe action to execute when clicked.
optionAdditional optional parameters.
See also
ButtonBase

Example

auto screen = App::FitComponent();
std::string label = "Click to quit";
Component button = Button(&label, screen.ExitLoopClosure());
screen.Loop(button)

Output

┌─────────────┐
│Click to quit│
└─────────────┘

Definition at line 202 of file src/ftxui/component/button.cpp.

◆ CatchEvent() [1/2]

Component CatchEvent ( Component child,
std::function< bool(Event event)> on_event )

Return a component, using |on_event| to catch events. This function must returns true when the event has been handled, false otherwise.

Parameters
childThe wrapped component.
on_eventThe function drawing the interface.

Example

auto screen = App::TerminalOutput();
auto renderer = Renderer([] {
return text("My interface");
});
auto component = CatchEvent(renderer, [&](Event event) {
if (event == Event::Character('q')) {
screen.ExitLoopClosure()();
return true;
}
return false;
});
screen.Loop(component);
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Element text(std::string_view text)
Display a piece of UTF8 encoded unicode text.
Component CatchEvent(Component child, std::function< bool(Event)>)

Definition at line 54 of file catch_event.cpp.

◆ CatchEvent() [2/2]

ComponentDecorator CatchEvent ( std::function< bool(Event)> on_event)

Decorate a component, using |on_event| to catch events. This function must returns true when the event has been handled, false otherwise.

Parameters
on_eventThe function drawing the interface.

Example

auto screen = App::TerminalOutput();
auto renderer = Renderer([] { return text("Hello world"); });
renderer |= CatchEvent([&](Event event) {
if (event == Event::Character('q')) {
screen.ExitLoopClosure()();
return true;
}
return false;
});
screen.Loop(renderer);

Definition at line 80 of file catch_event.cpp.

◆ Checkbox() [1/2]

Component Checkbox ( CheckboxOption option)

Draw checkable element.

Parameters
optionAdditional optional parameters.
See also
CheckboxBase

Example

auto screen = App::FitComponent();
CheckboxOption option;
option.label = "Make a sandwidth";
option.checked = false;
Component checkbox = Checkbox(option);
screen.Loop(checkbox)
Component Checkbox(ConstStringRef label, bool *checked, CheckboxOption options=CheckboxOption::Simple())
Draw checkable element.

Output

☐ Make a sandwich

Definition at line 110 of file src/ftxui/component/checkbox.cpp.

◆ Checkbox() [2/2]

Component Checkbox ( ConstStringRef label,
bool * checked,
CheckboxOption option )

Draw checkable element.

Parameters
labelThe label of the checkbox.
checkedWhether the checkbox is checked or not.
optionAdditional optional parameters.
See also
CheckboxBase

Example

auto screen = App::FitComponent();
std::string label = "Make a sandwidth";
bool checked = false;
Component checkbox = Checkbox(&label, &checked);
screen.Loop(checkbox)

Output

☐ Make a sandwich

Definition at line 137 of file src/ftxui/component/checkbox.cpp.

◆ Vertical() [1/2]

Component Vertical ( Components children)

A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or 'j'/'k' keys.

Parameters
childrenthe list of components.
See also
ContainerBase

Example

auto container = Container::Vertical({
children_1,
children_2,
children_3,
children_4,
});
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...

Definition at line 317 of file container.cpp.

◆ Vertical() [2/2]

Component Vertical ( Components children,
int * selector )

A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or 'j'/'k' keys. This is useful for implementing a Menu for instance.

Parameters
childrenthe list of components.
selectorA reference to the index of the selected children.
See also
ContainerBase

Example

int selected_children = 2;
auto container = Container::Vertical({
children_1,
children_2,
children_3,
children_4,
}, &selected_children);

Definition at line 340 of file container.cpp.

◆ Horizontal() [1/2]

Component Horizontal ( Components children)

A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow key or 'h'/'l' keys.

Parameters
childrenthe list of components.
See also
ContainerBase

Example

auto container = Container::Horizontal({
children_1,
children_2,
children_3,
children_4,
});
Component Horizontal(Components children, int *selector)
A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow...

Definition at line 360 of file container.cpp.

◆ Horizontal() [2/2]

Component Horizontal ( Components children,
int * selector )

A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow key or 'h'/'l' keys.

Parameters
childrenthe list of components.
selectorA reference to the index of the selected children.
See also
ContainerBase

Example

int selected_children = 2;
auto container = Container::Horizontal({
children_1,
children_2,
children_3,
children_4,
}, selected_children);

Definition at line 382 of file container.cpp.

◆ Tab()

Component Tab ( Components children,
int * selector )

A list of components, where only one is drawn and interacted with at a time. The |selector| gives the index of the selected component. This is useful to implement tabs.

Parameters
childrenThe list of components.
selectorThe index of the drawn children.
See also
ContainerBase

Example

int tab_drawn = 0;
auto container = Container::Tab({
children_1,
children_2,
children_3,
children_4,
}, &tab_drawn);
Component Tab(Components children, int *selector)
A list of components, where only one is drawn and interacted with at a time. The |selector| gives the...

Definition at line 405 of file container.cpp.

◆ Stacked()

Component Stacked ( Components children)

A list of components to be stacked on top of each other. Events are propagated to the first component, then the second if not handled, etc. The components are drawn in the reverse order they are given. When a component take focus, it is put at the front, without changing the relative order of the other elements.

This should be used with the Window component.

Parameters
childrenThe list of components.
See also
Window

Example

auto container = Container::Stacked({
children_1,
children_2,
children_3,
children_4,
});
Component Stacked(Components children)
A list of components to be stacked on top of each other. Events are propagated to the first component...

Definition at line 432 of file container.cpp.

◆ Dropdown() [1/2]

Component Dropdown ( ConstStringListRef entries,
int * selected )

A dropdown menu.

Parameters
entriesThe list of entries to display.
selectedThe index of the selected entry.

Definition at line 22 of file src/ftxui/component/dropdown.cpp.

◆ Dropdown() [2/2]

Component Dropdown ( DropdownOption option)

A dropdown menu.

Parameters
optionThe options for the dropdown.

Definition at line 33 of file src/ftxui/component/dropdown.cpp.

◆ Hoverable() [1/6]

Component Hoverable ( Component component,
bool * hover )

Wrap a component. Gives the ability to know if it is hovered by the mouse.

Parameters
componentThe wrapped component.
hoverThe value to reflect whether the component is hovered or not.

Example

auto button = Button("exit", screen.ExitLoopClosure());
bool hover = false;
auto button_hover = Hoverable(button, &hover);
Component Hoverable(Component component, bool *hover)
Wrap a component. Gives the ability to know if it is hovered by the mouse.
Definition hoverable.cpp:33

Definition at line 33 of file hoverable.cpp.

◆ Hoverable() [2/6]

Component Hoverable ( Component component,
std::function< void()> on_enter,
std::function< void()> on_leave )

Wrap a component. Uses callbacks.

Parameters
componentThe wrapped component.
on_enterCallback OnEnter
on_leaveCallback OnLeave

Example

auto button = Button("exit", screen.ExitLoopClosure());
bool hover = false;
auto button_hover = Hoverable(button, &hover);

Definition at line 76 of file hoverable.cpp.

◆ Hoverable() [3/6]

ComponentDecorator Hoverable ( bool * hover)

Wrap a component. Gives the ability to know if it is hovered by the mouse.

Parameters
hoverThe value to reflect whether the component is hovered or not.

Example

bool hover = false;
auto button = Button("exit", screen.ExitLoopClosure());
button |= Hoverable(&hover);

Definition at line 131 of file hoverable.cpp.

◆ Hoverable() [4/6]

ComponentDecorator Hoverable ( std::function< void()> on_enter,
std::function< void()> on_leave )

Wrap a component. Gives the ability to know if it is hovered by the mouse.

Parameters
on_enteris called when the mouse hover the component.
on_leaveis called when the mouse leave the component.

Example

auto button = Button("exit", screen.ExitLoopClosure());
int on_enter_cnt = 0;
int on_leave_cnt = 0;
button |= Hoverable(
[&]{ on_enter_cnt++; },
[&]{ on_leave_cnt++; }
);

Definition at line 155 of file hoverable.cpp.

◆ Hoverable() [5/6]

Component Hoverable ( Component component,
std::function< void(bool)> on_change )

Wrap a component. Gives the ability to know if it is hovered by the mouse.

Parameters
componentthe wrapped component.
on_changeis called when the mouse enter or leave the component.

Example

auto button = Button("exit", screen.ExitLoopClosure());
bool hovered = false;
auto button_hoverable = Hoverable(button,
[&](bool hover) { hovered = hover;});

Definition at line 178 of file hoverable.cpp.

◆ Hoverable() [6/6]

ComponentDecorator Hoverable ( std::function< void(bool)> on_change)

Wrap a component. Gives the ability to know if it is hovered by the mouse.

Parameters
on_changeis called when the mouse enter or leave the component.

Example

auto button = Button("exit", screen.ExitLoopClosure());
bool hovered = false;
button |= Hoverable([&](bool hover) { hovered = hover;});

Definition at line 199 of file hoverable.cpp.

◆ Input() [1/3]

Component Input ( InputOption option)

An input box for editing text.

Parameters
optionAdditional optional parameters.
See also
InputBase

Example

auto screen = App::FitComponent();
std::string content= "";
std::string placeholder = "placeholder";
Component input = Input({
.content = &content,
.placeholder = &placeholder,
})
screen.Loop(input);
Component Input(StringRef content, InputOption options={})
An input box for editing text.

Output

placeholder

Definition at line 590 of file src/ftxui/component/input.cpp.

◆ Input() [2/3]

Component Input ( StringRef content,
InputOption option )

An input box for editing text.

Parameters
contentThe editable content.
optionAdditional optional parameters.
See also
InputBase

Example

auto screen = App::FitComponent();
std::string content= "";
std::string placeholder = "placeholder";
Component input = Input(content, {
.placeholder = &placeholder,
.password = true,
})
screen.Loop(input);

Output

placeholder

Definition at line 618 of file src/ftxui/component/input.cpp.

◆ Input() [3/3]

Component Input ( StringRef content,
StringRef placeholder,
InputOption option )

An input box for editing text.

Parameters
contentThe editable content.
placeholderThe placeholder text.
optionAdditional optional parameters.
See also
InputBase

Example

auto screen = App::FitComponent();
std::string content= "";
std::string placeholder = "placeholder";
Component input = Input(content, placeholder);
screen.Loop(input);

Output

placeholder

Definition at line 645 of file src/ftxui/component/input.cpp.

◆ Maybe() [1/4]

Component Maybe ( Component child,
std::function< bool()> show )

Decorate a component |child|. It is shown only when |show| returns true.

Parameters
childthe component to decorate.
showa function returning whether |child| should shown.

Definition at line 21 of file src/ftxui/component/maybe.cpp.

◆ Maybe() [2/4]

ComponentDecorator Maybe ( std::function< bool()> show)

Decorate a component. It is shown only when the |show| function returns true.

Parameters
showa function returning whether the decorated component should be shown.

Example

auto component = Renderer([]{ return text("Hello World!"); });
auto maybe_component = component | Maybe([&]{ return counter == 42; });
Component Maybe(Component child, std::function< bool()> show)
Decorate a component |child|. It is shown only when |show| returns true.

Definition at line 57 of file src/ftxui/component/maybe.cpp.

◆ Maybe() [3/4]

Component Maybe ( Component child,
const bool * show )

Decorate a component |child|. It is shown only when |show| is true.

Parameters
childthe component to decorate.
showa boolean. |child| is shown when |show| is true.

Example

auto component = Renderer([]{ return text("Hello World!"); });
auto maybe_component = Maybe(component, &show);
const bool * show

Definition at line 74 of file src/ftxui/component/maybe.cpp.

◆ Maybe() [4/4]

ComponentDecorator Maybe ( const bool * show)

Decorate a component. It is shown only when |show| is true.

Parameters
showa boolean. |child| is shown when |show| is true.

Example

auto component = Renderer([]{ return text("Hello World!"); });
auto maybe_component = component | Maybe(&show);

Definition at line 88 of file src/ftxui/component/maybe.cpp.

◆ Menu() [1/2]

Component Menu ( MenuOption option)

A list of text. The focused element is selected.

Parameters
optiona structure containing all the parameters.

Example

auto screen = App::TerminalOutput();
std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;
auto menu = Menu({
.entries = &entries,
.selected = &selected,
});
screen.Loop(menu);
Component Menu(ConstStringListRef entries, int *selected_, MenuOption options=MenuOption::Vertical())
A list of text. The focused element is selected.

Output

> entry 1
entry 2
entry 3

Definition at line 505 of file src/ftxui/component/menu.cpp.

◆ Menu() [2/2]

Component Menu ( ConstStringListRef entries,
int * selected,
MenuOption option )

A list of text. The focused element is selected.

Parameters
entriesThe list of entries in the menu.
selectedThe index of the currently selected element.
optionAdditional optional parameters.

Example

auto screen = App::TerminalOutput();
std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;
auto menu = Menu(&entries, &selected);
screen.Loop(menu);

Output

> entry 1
entry 2
entry 3

Definition at line 536 of file src/ftxui/component/menu.cpp.

◆ Toggle()

Component Toggle ( ConstStringListRef entries,
int * selected )

An horizontal list of elements. The user can navigate through them.

Parameters
entriesThe list of selectable entries to display.
selectedReference the selected entry. See also |Menu|.

Definition at line 547 of file src/ftxui/component/menu.cpp.

◆ MenuEntry() [1/2]

Component MenuEntry ( ConstStringRef label,
MenuEntryOption option )

A specific menu entry. They can be put into a Container::Vertical to form a menu.

Parameters
labelThe text drawn representing this element.
optionAdditional optional parameters.

Example

auto screen = App::TerminalOutput();
int selected = 0;
auto menu = Container::Vertical({
MenuEntry("entry 1"),
MenuEntry("entry 2"),
MenuEntry("entry 3"),
}, &selected);
screen.Loop(menu);
Component MenuEntry(ConstStringRef label, MenuEntryOption options={})
A specific menu entry. They can be put into a Container::Vertical to form a menu.

Output

> entry 1
entry 2
entry 3

Definition at line 577 of file src/ftxui/component/menu.cpp.

◆ MenuEntry() [2/2]

Component MenuEntry ( MenuEntryOption option)

A specific menu entry. They can be put into a Container::Vertical to form a menu.

Parameters
optionThe parameters.

Example

auto screen = App::TerminalOutput();
int selected = 0;
auto menu = Container::Vertical({
MenuEntry({.label = "entry 1"}),
MenuEntry({.label = "entry 2"}),
MenuEntry({.label = "entry 3"}),
}, &selected);
screen.Loop(menu);

Output

> entry 1
entry 2
entry 3

Definition at line 607 of file src/ftxui/component/menu.cpp.

◆ Modal() [1/2]

Component Modal ( Component main,
Component modal,
const bool * show_modal )

Definition at line 18 of file modal.cpp.

◆ Modal() [2/2]

ComponentDecorator Modal ( Component modal,
const bool * show_modal )

Definition at line 58 of file modal.cpp.

◆ Radiobox() [1/2]

Component Radiobox ( RadioboxOption option)

A list of element, where only one can be selected.

Parameters
optionThe parameters
See also
RadioboxBase

Example

auto screen = App::TerminalOutput();
std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;
auto menu = Radiobox({
.entries = entries,
.selected = &selected,
});
screen.Loop(menu);
Component Radiobox(ConstStringListRef entries, int *selected_, RadioboxOption options={})
A list of element, where only one can be selected.

Output

◉ entry 1
○ entry 2
○ entry 3

NOLINTNEXTLINE

Definition at line 205 of file src/ftxui/component/radiobox.cpp.

◆ Radiobox() [2/2]

Component Radiobox ( ConstStringListRef entries,
int * selected,
RadioboxOption option )

A list of element, where only one can be selected.

Parameters
entriesThe list of entries in the list.
selectedThe index of the currently selected element.
optionAdditional optional parameters.
See also
RadioboxBase

Example

auto screen = App::TerminalOutput();
std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;
auto menu = Radiobox(&entries, &selected);
screen.Loop(menu);

Output

◉ entry 1
○ entry 2
○ entry 3

Definition at line 237 of file src/ftxui/component/radiobox.cpp.

◆ Renderer() [1/4]

Component Renderer ( std::function< Element()> render)

Return a component, using |render| to render its interface.

Parameters
renderThe function drawing the interface.

Example

auto screen = App::TerminalOutput();
auto renderer = Renderer([] {
return text("My interface");
});
screen.Loop(renderer);

Definition at line 29 of file src/ftxui/component/renderer.cpp.

◆ Renderer() [2/4]

Component Renderer ( Component child,
std::function< Element()> render )

Return a new Component, similar to |child|, but using |render| as the Component::Render() event.

Parameters
childThe component to forward events to.
renderThe function drawing the interface.

Example

auto screen = App::TerminalOutput();
std::string label = "Click to quit";
auto button = Button(&label, screen.ExitLoopClosure());
auto renderer = Renderer(button, [&] {
return hbox({
text("A button:"),
button->Render(),
});
});
screen.Loop(renderer);
Element hbox(Elements children)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94

Definition at line 61 of file src/ftxui/component/renderer.cpp.

◆ Renderer() [3/4]

Component Renderer ( std::function< Element(bool)> render)

Return a focusable component, using |render| to render its interface.

Parameters
renderThe function drawing the interface, taking a boolean telling whether the component is focused or not.

Example

auto screen = App::TerminalOutput();
auto renderer = Renderer([] (bool focused) {
if (focused)
return text("My interface") | inverted;
else
return text("My interface");
});
screen.Loop(renderer);
Element inverted(Element child)
Add a filter that will invert the foreground and the background colors.
Definition inverted.cpp:34

Definition at line 84 of file src/ftxui/component/renderer.cpp.

◆ Renderer() [4/4]

ComponentDecorator Renderer ( ElementDecorator decorator)

Decorate a component, by decorating what it renders.

Parameters
decoratorthe function modifying the element it renders.

Example

auto screen = App::TerminalOutput();
auto renderer =
Renderer([] { return text("Hello"); })
| Renderer(bold)
| Renderer(inverted);
screen.Loop(renderer);

Definition at line 125 of file src/ftxui/component/renderer.cpp.

◆ ResizableSplitLeft()

Component ResizableSplitLeft ( Component main,
Component back,
int * main_size )

An horizontal split in between two components, configurable using the mouse.

Parameters
mainThe main component of size |main_size|, on the left.
backThe back component taking the remaining size, on the right.
main_sizeThe size of the |main| component.

Example

auto screen = App::Fullscreen();
int left_size = 10;
auto left = Renderer([] { return text("Left") | center;});
auto right = Renderer([] { return text("right") | center;});
auto split = ResizableSplitLeft(left, right, &left_size);
screen.Loop(split);
Component ResizableSplitLeft(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Element center(Element child)
Center an element horizontally and vertically.
std::uint8_t left
Definition screen.cpp:142
std::uint8_t right
Definition screen.cpp:144

Output

left │ right

Definition at line 199 of file src/ftxui/component/resizable_split.cpp.

◆ ResizableSplitRight()

Component ResizableSplitRight ( Component main,
Component back,
int * main_size )

An horizontal split in between two components, configurable using the mouse.

Parameters
mainThe main component of size |main_size|, on the right.
backThe back component taking the remaining size, on the left.
main_sizeThe size of the |main| component.

Example

auto screen = App::Fullscreen();
int right_size = 10;
auto left = Renderer([] { return text("Left") | center;});
auto right = Renderer([] { return text("right") | center;});
auto split = ResizableSplitRight(right, left, &right_size)
screen.Loop(split);
Component ResizableSplitRight(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.

Output

left │ right

Definition at line 233 of file src/ftxui/component/resizable_split.cpp.

◆ ResizableSplitTop()

Component ResizableSplitTop ( Component main,
Component back,
int * main_size )

An vertical split in between two components, configurable using the mouse.

Parameters
mainThe main component of size |main_size|, on the top.
backThe back component taking the remaining size, on the bottom.
main_sizeThe size of the |main| component.

Example

auto screen = App::Fullscreen();
int top_size = 1;
auto top = Renderer([] { return text("Top") | center;});
auto bottom = Renderer([] { return text("Bottom") | center;});
auto split = ResizableSplitTop(top, bottom, &top_size)
screen.Loop(split);
Component ResizableSplitTop(Component main, Component back, int *main_size)
An vertical split in between two components, configurable using the mouse.
std::uint8_t top
Definition screen.cpp:143

Output

top
────────────
bottom

Definition at line 267 of file src/ftxui/component/resizable_split.cpp.

◆ ResizableSplitBottom()

Component ResizableSplitBottom ( Component main,
Component back,
int * main_size )

An vertical split in between two components, configurable using the mouse.

Parameters
mainThe main component of size |main_size|, on the bottom.
backThe back component taking the remaining size, on the top.
main_sizeThe size of the |main| component.

Example

auto screen = App::Fullscreen();
int bottom_size = 1;
auto top = Renderer([] { return text("Top") | center;});
auto bottom = Renderer([] { return text("Bottom") | center;});
auto split = ResizableSplit::Bottom(bottom, top, &bottom_size)
screen.Loop(split);

Output

top
────────────
bottom

Definition at line 301 of file src/ftxui/component/resizable_split.cpp.

◆ Slider()

Component Slider ( ConstStringRef label,
Ref< int > value,
ConstRef< int > min,
ConstRef< int > max,
ConstRef< int > increment )

An horizontal slider.

Parameters
labelThe name of the slider.
valueThe current value of the slider.
minThe minimum value.
maxThe maximum value.
incrementThe increment when used by the cursor.

Example

auto screen = App::TerminalOutput();
int value = 50;
auto slider = Slider("Value:", &value, 0, 100, 1);
screen.Loop(slider);
Component Slider(SliderOption< T > options)
A slider in any direction.
int value
Definition elements.hpp:178

Output

Value:[██████████████████████████ ]

Definition at line 257 of file src/ftxui/component/slider.cpp.

◆ Window()

Component Window ( WindowOptions option)

A draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stacked({...}) component;.

Parameters
optionA struct holding every parameters.
See also
Window

Example

auto window_1= Window({
.inner = DummyWindowContent(),
.title = "First window",
});
auto window_2= Window({
.inner = DummyWindowContent(),
.title = "Second window",
});
auto container = Container::Stacked({
window_1,
window_2,
});
Component Window(WindowOptions option)
A draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stac...
Component DummyWindowContent()
Definition scrollbar.cpp:10

Definition at line 311 of file src/ftxui/component/window.cpp.