Skip to content
You are viewing documentation for v5.0.0. Switch to latest (main).

Module ftxui/component ​

Classes & Structs ​

ClassDescription
ftxui::AnimatedColorOptionOption about a potentially animated color.
ftxui::AnimatedColorsOption
ftxui::ButtonOptionOption for the AnimatedButton component.
ftxui::CheckboxOptionOption for the Checkbox component.
ftxui::ComponentBaseIt implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ftxui::Event.
ftxui::EntryStatearguments for ButtonOption::transform, CheckboxOption::transform, Radiobox::transform, MenuEntryOption::transform, MenuOption::transform.
ftxui::EventRepresent an event. It can be key press event, a terminal resize, or more ...
ftxui::InputOptionOption for the Input component.
ftxui::InputStateUsed to define style for the Input component.
ftxui::Loop
ftxui::MenuEntryOptionOption for the MenuEntry component.
ftxui::MenuOptionOption for the Menu component.
ftxui::MouseA mouse event. It contains the coordinate of the mouse, the button pressed and the modifier (shift, ctrl, meta).
ftxui::RadioboxOptionOption for the Radiobox component.
ftxui::ResizableSplitOption
ftxui::ScreenInteractive
ftxui::SliderOption
ftxui::UnderlineOption
ftxui::WindowOptions
ftxui::WindowRenderState
ftxui::animation::Animator
ftxui::animation::Params

Type Aliases ​

Clock ​

cpp
using Clock = std::chrono::steady_clock;

Duration ​

cpp
using Duration = std::chrono::duration< float >;

Function ​

cpp
using Function = std::function< float(float)>;

TimePoint ​

cpp
using TimePoint = std::chrono::time_point< Clock >;

CapturedMouse ​

cpp
using CapturedMouse = std::unique_ptr< CapturedMouseInterface >;

Closure ​

cpp
using Closure = std::function< void()>;

Component ​

cpp
using Component = std::shared_ptr< ComponentBase >;

Examples: component/checkbox, component/collapsible, component/focus_cursor, component/gallery, component/homescreen, component/input, component/menu2, component/menu_multiple, component/menu_style, component/menu_underline_animated_gallery, component/modal_dialog, component/toggle (+1 more)

ComponentDecorator ​

cpp
using ComponentDecorator = std::function< Component(Component)>;

Components ​

cpp
using Components = std::vector< Component >;

ElementDecorator ​

cpp
using ElementDecorator = std::function< Element(Element)>;

Task ​

cpp
using Task = std::variant< Event, Closure, AnimationTask >;

Examples: dom/package_manager

Functions ​

SymbolDescription
SetA color option that can be animated. @params _inactive The color when the component is inactive. @params _active The color when the component is active. @params _duration The duration of the animation. @params _function The easing function of the animation.
LinearModeled after the line y = x.
QuadraticInModeled after the parabola y = x^2.
ButtonDraw a button. Execute a function when clicked.
AnimatedCreate a ButtonOption, using animated colors.
AsciiCreate a ButtonOption, highlighted using [] characters.
BorderCreate a ButtonOption. The button is shown using a border, inverted when focused. This is the current default.
SimpleCreate a ButtonOption, inverted when focused.
CatchEventDecorate a component, using on_event to catch events. This function must returns true when the event has been handled, false otherwise.
CheckboxDraw checkable element.
ActiveReturns if the element if the currently active child of its parent.
ActiveChildReturn the currently Active child.
AddAdd a child. @param child The child to be attached.
CaptureMouseTake the CapturedMouse if available. There is only one component of them. It represents a component taking priority over others.
ChildAtAccess the child at index i.
ChildCountReturns the number of children.
DetachDetach this child from its parent.
DetachAllChildrenRemove all children.
FocusableReturn true when the component contains focusable elements. The non focusable Components will be skipped when navigating using the keyboard.
FocusedReturns if the elements if focused by the user. True when the ComponentBase is focused by the user. An element is Focused when it is with all its ancestors the ActiveChild() of their parents, and it Focusable().
OnAnimationCalled in response to an animation event.
OnEventCalled in response to an event.
ParentReturn the parent ComponentBase, or nul if any.
RenderDraw the component. Build a ftxui::Element to be drawn on the ftxi::Screen representing this ftxui::ComponentBase.
SetActiveChildMake the child to be the "active" one.
TakeFocusConfigure all the ancestors to give focus to this component.
HorizontalA list of components, drawn one by one horizontally and navigated horizontally using left/right arrow key or 'h'/'l' keys.
StackedA 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.
TabA 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.
VerticalA list of components, drawn one by one vertically and navigated vertically using up/down arrow key or 'j'/'k' keys.
DropdownA dropdown menu.
CharacterAn event corresponding to a given typed character.
MouseAn event corresponding to a given typed character.
SpecialAn custom event whose meaning is defined by the user of the library.
HoverableWrap a component. Gives the ability to know if it is hovered by the mouse.
InputAn input box for editing text.
DefaultCreate the default input style:
SpaciousA white on black style with high margins:
HasQuittedWhether the loop has quitted.
LoopA Loop is a wrapper around a Component and a ScreenInteractive. It is used to run a Component in a terminal.
MaybeDecorate a component child. It is shown only when show returns true.
MenuA list of text. The focused element is selected.
MenuEntryA specific menu entry. They can be put into a Container::Vertical to form a menu.
HorizontalAnimatedStandard options for an animated horizontal menu. This can be useful to implement a tab bar.
ToggleStandard options for a horitontal menu with some separator. This can be useful to implement a tab bar.
VerticalAnimatedStandard options for an animated vertical menu. This can be useful to implement a list of selectable items.
RadioboxA list of element, where only one can be selected.
RendererReturn a component, using render to render its interface.
ResizableSplitA split in between two components.
ResizableSplitBottomAn vertical split in between two components, configurable using the mouse.
ResizableSplitLeftAn horizontal split in between two components, configurable using the mouse.
ResizableSplitRightAn horizontal split in between two components, configurable using the mouse.
ResizableSplitTopAn vertical split in between two components, configurable using the mouse.
ExitExit the main loop.
ExitLoopClosureReturn a function to exit the main loop.
PostAdd a task to the main loop. It will be executed later, after every other scheduled tasks.
PostEventAdd an event to the main loop. It will be executed later, after every other scheduled events.
TrackMouseSet whether mouse is tracked and events reported. called outside of the main loop. E.g ScreenInteractive::Loop(...).
SliderAn horizontal slider.
SetAnimationSet how the underline should animate.
SetAnimationDurationSet how the underline should animate.
SetAnimationFunctionSet how the underline should animate.
WindowA draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stacked({...}) component;.

Set ​

cpp
void Set(Color inactive, Color active, animation::Duration duration = std::chrono::milliseconds(250), animation::easing::Function function = animation::easing::QuadraticInOut);

A color option that can be animated. @params _inactive The color when the component is inactive. @params _active The color when the component is active. @params _duration The duration of the animation. @params _function The easing function of the animation.

Examples: component/flexbox_gallery, component/menu_style

Linear ​

cpp
float Linear(float p);

Modeled after the line y = x.

Examples: component/menu_style

QuadraticIn ​

cpp
float QuadraticIn(float p);

Modeled after the parabola y = x^2.

Button ​

Draw a button. Execute a function when clicked.

Parameters:

  • option: Additional optional parameters.

See also: ButtonBase

Example

cpp
auto screen = ScreenInteractive::FitComponent();
Component button = Button({
  .label = "Click to quit",
  .on_click = screen.ExitLoopClosure(),
});
screen.Loop(button)

Output

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

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/composition, component/gallery, component/modal_dialog, component/modal_dialog_custom, component/nested_screen, component/renderer, component/with_restored_io

Button ​

cpp
Component Button(ConstStringRef label, std::function< void()> on_click, ButtonOption options = ButtonOption::Simple());

Draw a button. Execute a function when clicked.

Parameters:

  • label: The label of the button.
  • on_click: The action to execute when clicked.
  • option: Additional optional parameters.

See also: ButtonBase

Example

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

Output

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

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/composition, component/gallery, component/modal_dialog, component/modal_dialog_custom, component/nested_screen, component/renderer, component/with_restored_io

Animated ​

cpp
static ButtonOption Animated();

Create a ButtonOption, using animated colors.

Examples: component/button_animated, component/button_in_frame, component/button_style, component/modal_dialog

Animated ​

Create a ButtonOption, using animated colors.

Examples: component/button_animated, component/button_in_frame, component/button_style, component/modal_dialog

Animated ​

cpp
static ButtonOption Animated(Color background, Color foreground);

Create a ButtonOption, using animated colors.

Examples: component/button_animated, component/button_in_frame, component/button_style, component/modal_dialog

Animated ​

cpp
static ButtonOption Animated(Color background, Color foreground, Color background_active, Color foreground_active);

Create a ButtonOption, using animated colors.

Examples: component/button_animated, component/button_in_frame, component/button_style, component/modal_dialog

Ascii ​

cpp
static ButtonOption Ascii();

Create a ButtonOption, highlighted using [] characters.

Examples: component/button_style

Border ​

cpp
static ButtonOption Border();

Create a ButtonOption. The button is shown using a border, inverted when focused. This is the current default.

Examples: dom/table

Simple ​

cpp
static ButtonOption Simple();

Create a ButtonOption, inverted when focused.

Examples: component/button_style

CatchEvent ​

cpp
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_event: The function drawing the interface.

Example

cpp
auto screen = ScreenInteractive::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);

Examples: component/canvas_animated, component/custom_loop, component/print_key_press

Checkbox ​

cpp
Component Checkbox(ConstStringRef label, bool * checked, CheckboxOption options = CheckboxOption::Simple());

Draw checkable element.

Parameters:

  • label: The label of the checkbox.
  • checked: Whether the checkbox is checked or not.
  • option: Additional optional parameters.

See also: CheckboxBase

Example

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

Output

text
☐ Make a sandwitch

Examples: component/checkbox_in_frame, component/flexbox_gallery, component/gallery, component/homescreen, component/maybe, component/window

Simple ​

cpp
static CheckboxOption Simple();

Option for standard Checkbox.

Examples: component/button_style

Active ​

cpp
bool Active() const;

Returns if the element if the currently active child of its parent.

ActiveChild ​

cpp
virtual Component ActiveChild();

Return the currently Active child.

Returns: the currently Active child.

Add ​

cpp
void Add(Component children);

Add a child. @param child The child to be attached.

Examples: component/button_in_frame, component/checkbox, component/checkbox_in_frame, component/menu_underline_animated_gallery, component/slider_direction, component/window

CaptureMouse ​

cpp
CapturedMouse CaptureMouse(const Event & event);

Take the CapturedMouse if available. There is only one component of them. It represents a component taking priority over others.

Parameters:

  • event: The event

ChildAt ​

cpp
Component & ChildAt(size_t i);

Access the child at index i.

Examples: component/menu_underline_animated_gallery

ChildCount ​

cpp
size_t ChildCount() const;

Returns the number of children.

Detach ​

cpp
void Detach();

Detach this child from its parent.

See also: Detach, Parent

DetachAllChildren ​

Remove all children.

Focusable ​

cpp
virtual bool Focusable() const;

Return true when the component contains focusable elements. The non focusable Components will be skipped when navigating using the keyboard.

Focused ​

cpp
bool Focused() const;

Returns if the elements if focused by the user. True when the ComponentBase is focused by the user. An element is Focused when it is with all its ancestors the ActiveChild() of their parents, and it Focusable().

Examples: component/renderer

OnAnimation ​

cpp
virtual void OnAnimation(animation::Params & params);

Called in response to an animation event.

Parameters:

  • params: the parameters of the animation The default implementation dispatch the event to every child.

OnEvent ​

cpp
virtual bool OnEvent(Event);

Called in response to an event.

Parameters:

  • event: The event.

Returns: True when the event has been handled. The default implementation called OnEvent on every child until one return true. If none returns true, return false.

Parent ​

cpp
ComponentBase * Parent() const;

Return the parent ComponentBase, or nul if any.

See also: Detach, Parent

Render ​

cpp
virtual Element Render();

Draw the component. Build a ftxui::Element to be drawn on the ftxi::Screen representing this ftxui::ComponentBase.

Examples: component/button, component/button_animated, component/button_in_frame, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/flexbox_gallery, component/focus, component/gallery, component/homescreen (+54 more)

SetActiveChild ​

cpp
virtual void SetActiveChild(ComponentBase * child);

Make the child to be the "active" one.

Parameters:

  • child: the child to become active.

Examples: component/menu_underline_animated_gallery

SetActiveChild ​

cpp
void SetActiveChild(Component child);

Make the child to be the "active" one.

Parameters:

  • child: the child to become active.

Examples: component/menu_underline_animated_gallery

TakeFocus ​

cpp
void TakeFocus();

Configure all the ancestors to give focus to this component.

Horizontal ​

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

Parameters:

  • children: the list of components.

See also: ContainerBase

Example

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

Examples: component/button, component/button_animated, component/button_style, component/canvas_animated, component/composition, component/dropdown, component/flexbox_gallery, component/homescreen, component/input_style, component/menu2, component/menu_multiple, component/menu_style (+4 more)

Horizontal ​

cpp
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:

  • children: the list of components.
  • selector: A reference to the index of the selected children.

See also: ContainerBase

Example

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

Examples: component/button, component/button_animated, component/button_style, component/canvas_animated, component/composition, component/dropdown, component/flexbox_gallery, component/homescreen, component/input_style, component/menu2, component/menu_multiple, component/menu_style (+4 more)

Stacked ​

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:

  • children: The list of components.

See also: Window

Example

cpp
auto container = Container::Stacked({
  children_1,
  children_2,
  children_3,
  children_4,
});

Examples: component/window

Tab ​

cpp
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:

  • children: The list of components.
  • selector: The index of the drawn children.

See also: ContainerBase

Example

cpp
int tab_drawn = 0;
auto container = Container::Tab({
  children_1,
  children_2,
  children_3,
  children_4,
}, &tab_drawn);

Examples: component/canvas_animated, component/homescreen, component/modal_dialog_custom, component/print_key_press, component/tab_horizontal, component/tab_vertical

Vertical ​

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

Parameters:

  • children: the list of components.

See also: ContainerBase

Example

cpp
auto container = Container::Vertical({
  children_1,
  children_2,
  children_3,
  children_4,
});

Examples: component/button_in_frame, component/button_style, component/checkbox, component/checkbox_in_frame, component/collapsible, component/dropdown, component/flexbox_gallery, component/focus, component/focus_cursor, component/gallery, component/homescreen, component/input (+15 more)

Vertical ​

cpp
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:

  • children: the list of components.
  • selector: A reference to the index of the selected children.

See also: ContainerBase

Example

cpp
auto container = Container::Vertical({
  children_1,
  children_2,
  children_3,
  children_4,
});

Examples: component/button_in_frame, component/button_style, component/checkbox, component/checkbox_in_frame, component/collapsible, component/dropdown, component/flexbox_gallery, component/focus, component/focus_cursor, component/gallery, component/homescreen, component/input (+15 more)

cpp
Component Dropdown(ConstStringListRef entries, int * selected);

A dropdown menu.

Parameters:

  • entries: The list of entries to display.
  • selected: The index of the selected entry.

Examples: component/dropdown

Character ​

cpp
static Event Character(std::string);

An event corresponding to a given typed character.

Parameters:

  • input: The character typed by the user.

Character ​

cpp
static Event Character(char);

An event corresponding to a given typed character.

Parameters:

  • c: The character typed by the user.

Character ​

cpp
static Event Character(wchar_t);

An event corresponding to a given typed character.

Parameters:

  • c: The character typed by the user.

Mouse ​

cpp
static Event Mouse(std::string, Mouse mouse);

An event corresponding to a given typed character.

Parameters:

  • input: The sequence of character send by the terminal.
  • mouse: The mouse state.

Examples: component/print_key_press

Special ​

cpp
static Event Special(std::string);

An custom event whose meaning is defined by the user of the library.

Parameters:

  • input: An arbitrary sequence of character defined by the developer.

Hoverable ​

cpp
Component Hoverable(Component component, bool * hover);

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

Parameters:

  • component: The wrapped component.
  • hover: The value to reflect whether the component is hovered or not.

Example

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

Hoverable ​

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

Wrap a component. Uses callbacks.

Parameters:

  • component: The wrapped component.
  • on_enter: Callback OnEnter
  • on_leave: Callback OnLeave

Example

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

Hoverable ​

cpp
ComponentDecorator Hoverable(bool * hover);

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

Parameters:

  • hover: The value to reflect whether the component is hovered or not.

Example

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

Hoverable ​

cpp
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:

  • on_enter: is called when the mouse hover the component.
  • on_leave: is called when the mouse leave the component.

Example

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

// NOLINTNEXTLINE ComponentDecorator Hoverable(std::function<void()> on_enter, // NOLINTNEXTLINE std::function<void()> on_leave) { return [on_enter, on_leave](Component component) { return Hoverable(std::move(component), on_enter, on_leave); }; } /** Wrap a component. Gives the ability to know if it is hovered by the mouse.

Parameters:

  • component: the wrapped component.
  • on_change: is called when the mouse enter or leave the component.

Examplecpp auto button =Button("exit", screen.ExitLoopClosure()); bool hovered = false; auto button_hoverable =Hoverable(button,

Hoverable ​

cpp
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_change: is called when the mouse enter or leave the component.

Example

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

Input ​

cpp
Component Input(InputOption options = {});

An input box for editing text.

Parameters:

  • option: Additional optional parameters.

See also: InputBase

Example

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

Output

text
placeholder

Examples: component/checkbox, component/gallery, component/homescreen, component/input, component/input_style, component/textarea

Input ​

cpp
Component Input(StringRef content, InputOption options = {});

An input box for editing text.

Parameters:

  • content: The editable content.
  • option: Additional optional parameters.

See also: InputBase

Example

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

Output

text
placeholder

Examples: component/checkbox, component/gallery, component/homescreen, component/input, component/input_style, component/textarea

Input ​

cpp
Component Input(StringRef content, StringRef placeholder, InputOption options = {});

An input box for editing text.

Parameters:

  • content: The editable content.
  • option: Additional optional parameters.

See also: InputBase

Example

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

Output

text
placeholder

Examples: component/checkbox, component/gallery, component/homescreen, component/input, component/input_style, component/textarea

Default ​

cpp
static InputOption Default();

Create the default input style:

Standard options for the input component.

Examples: component/button_in_frame, component/homescreen, component/input_style, component/menu_style, dom/color_gallery, dom/style_color

Spacious ​

cpp
static InputOption Spacious();

A white on black style with high margins:

Standard options for a more beautiful input component.

Examples: component/input_style

HasQuitted ​

cpp
bool HasQuitted();

Whether the loop has quitted.

Examples: component/custom_loop

Loop ​

cpp
Loop(ScreenInteractive * screen, Component component);

A Loop is a wrapper around a Component and a ScreenInteractive. It is used to run a Component in a terminal.

See also: Component, ScreenInteractive., ScreenInteractive::Loop(), ScreenInteractive::ExitLoop()

Parameters:

  • screen: The screen to use.
  • component: The component to run.

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/custom_loop, component/dropdown, component/flexbox_gallery (+33 more)

Maybe ​

cpp
Component Maybe(Component, std::function< bool()>);

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

Parameters:

  • child: the compoenent to decorate.
  • show: a function returning whether child should shown.

Examples: component/maybe

Maybe ​

cpp
ComponentDecorator Maybe(std::function< bool()>);

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

Parameters:

  • show: a function returning whether the decorated component should be shown.

Example

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

Examples: component/maybe

Maybe ​

cpp
Component Maybe(Component, const bool * show);

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

Parameters:

  • child: the compoennt to decorate.
  • show: a boolean. child is shown when show is true.

Example

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

Examples: component/maybe

Maybe ​

cpp
ComponentDecorator Maybe(const bool * show);

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

Parameters:

  • show: a boolean. child is shown when show is true.

Example

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

Examples: component/maybe

A list of text. The focused element is selected.

Parameters:

  • option: a structure containing all the paramters.

Example

cpp
auto screen = ScreenInteractive::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);

Output

text
> entry 1
  entry 2
  entry 3

Examples: component/canvas_animated, component/gallery, component/homescreen, component/menu, component/menu2, component/menu_in_frame, component/menu_multiple, component/menu_style, component/menu_underline_animated_gallery, component/tab_vertical

cpp
Component Menu(ConstStringListRef entries, int * selected_, MenuOption options = MenuOption::Vertical());

A list of text. The focused element is selected.

Parameters:

  • entries: The list of entries in the menu.
  • selected: The index of the currently selected element.
  • option: Additional optional parameters.

Example

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

Output

text
> entry 1
  entry 2
  entry 3

Examples: component/canvas_animated, component/gallery, component/homescreen, component/menu, component/menu2, component/menu_in_frame, component/menu_multiple, component/menu_style, component/menu_underline_animated_gallery, component/tab_vertical

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

Parameters:

  • label: The text drawn representing this element.
  • option: Additional optional parameters.

Example

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

Output

text
> entry 1
  entry 2
  entry 3

Examples: component/menu_entries, component/menu_entries_animated

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

Parameters:

  • option: The parameters.

Example

cpp
auto screen = ScreenInteractive::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

text
> entry 1
  entry 2
  entry 3

Examples: component/menu_entries, component/menu_entries_animated

Horizontal ​

cpp
static MenuOption Horizontal();

Standard options for an horizontal menu. This can be useful to implement a tab bar.

Examples: component/button, component/button_animated, component/button_style, component/canvas_animated, component/composition, component/dropdown, component/flexbox_gallery, component/homescreen, component/input_style, component/menu2, component/menu_multiple, component/menu_style (+4 more)

HorizontalAnimated ​

Standard options for an animated horizontal menu. This can be useful to implement a tab bar.

Examples: component/homescreen, component/menu_style, component/menu_underline_animated_gallery

Toggle ​

cpp
static MenuOption Toggle();

Standard options for a horitontal menu with some separator. This can be useful to implement a tab bar.

Examples: component/gallery, component/menu_style, component/tab_horizontal, component/toggle

Vertical ​

cpp
static MenuOption Vertical();

Standard options for a vertical menu. This can be useful to implement a list of selectable items.

Examples: component/button_in_frame, component/button_style, component/checkbox, component/checkbox_in_frame, component/collapsible, component/dropdown, component/flexbox_gallery, component/focus, component/focus_cursor, component/gallery, component/homescreen, component/input (+15 more)

VerticalAnimated ​

Standard options for an animated vertical menu. This can be useful to implement a list of selectable items.

Examples: component/menu_style

Radiobox ​

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

Parameters:

  • option: The parameters

See also: RadioboxBase

Example

cpp
auto screen = ScreenInteractive::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);

Output

text
◉ entry 1
○ entry 2
○ entry 3

Examples: component/flexbox_gallery, component/gallery, component/homescreen, component/maybe, component/radiobox, component/radiobox_in_frame, component/tab_horizontal, component/tab_vertical

Radiobox ​

cpp
Component Radiobox(ConstStringListRef entries, int * selected_, RadioboxOption options = {});

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

Parameters:

  • entries: The list of entries in the list.
  • selected: The index of the currently selected element.
  • option: Additional optional parameters.

See also: RadioboxBase

Example

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

Output

text
◉ entry 1
○ entry 2
○ entry 3

Examples: component/flexbox_gallery, component/gallery, component/homescreen, component/maybe, component/radiobox, component/radiobox_in_frame, component/tab_horizontal, component/tab_vertical

Simple ​

cpp
static RadioboxOption Simple();

Option for standard Radiobox.

Examples: component/button_style

Renderer ​

cpp
Component Renderer(std::function< Element()>);

Return a component, using render to render its interface.

Parameters:

  • render: The function drawing the interface.

Example

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

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/custom_loop, component/flexbox_gallery, component/focus (+27 more)

Renderer ​

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

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

Parameters:

  • child: The component to forward events to.
  • render: The function drawing the interface.

Example

cpp
auto screen = ScreenInteractive::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);

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/custom_loop, component/flexbox_gallery, component/focus (+27 more)

Renderer ​

cpp
Component Renderer(std::function< Element(bool)>);

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

Parameters:

  • render: The function drawing the interface, taking a boolean telling whether the component is focused or not.

Example

cpp
auto screen = ScreenInteractive::TerminalOutput();
auto renderer = Renderer([] (bool focused) {
  if (focused)
    return text("My interface") | inverted;
  else
    return text("My interface");
});
screen.Loop(renderer);

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/custom_loop, component/flexbox_gallery, component/focus (+27 more)

Renderer ​

Decorate a component, by decorating what it renders.

Parameters:

  • decorator: the function modifying the element it renders.

Example

cpp
    auto screen = ScreenInteractive::TerminalOutput();
    auto renderer = */
//     Renderer([] { return text("Hello");)

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/custom_loop, component/flexbox_gallery, component/focus (+27 more)

ResizableSplit ​

cpp
Component ResizableSplit(ResizableSplitOption options);

A split in between two components.

Parameters:

  • options: all the parameters.

Example

cpp
auto left = Renderer([] { return text("Left") | center;});
auto right = Renderer([] { return text("right") | center;});
int left_size = 10;
auto component = ResizableSplit({
  .main = left,
  .back = right,
  .direction = Direction::Left,
  .main_size = &left_size,
  .separator_func = [] { return separatorDouble(); },
});

Output

text
       ║
left   ║   right
       ║

ResizableSplitBottom ​

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

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

Parameters:

  • main: The main component of size main_size, on the bottom.
  • back: The back component taking the remaining size, on the top.
  • main_size: The size of the main component.

Example

cpp
auto screen = ScreenInteractive::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

text
   top
────────────
   bottom

Examples: component/flexbox_gallery, component/resizable_split

ResizableSplitLeft ​

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

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

Parameters:

  • main: The main component of size main_size, on the left.
  • back: The back component taking the remaining size, on the right.
  • main_size: The size of the main component.

Example

cpp
auto screen = ScreenInteractive::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);

Output

text
       │
left   │   right
       │

Examples: component/homescreen, component/resizable_split, component/textarea

ResizableSplitRight ​

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

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

Parameters:

  • main: The main component of size main_size, on the right.
  • back: The back component taking the remaining size, on the left.
  • main_size: The size of the main component.

Example

cpp
auto screen = ScreenInteractive::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);

Output

text
       │
left   │   right
       │

Examples: component/flexbox_gallery, component/resizable_split

ResizableSplitTop ​

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

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

Parameters:

  • main: The main component of size main_size, on the top.
  • back: The back component taking the remaining size, on the bottom.
  • main_size: The size of the main component.

Example

cpp
auto screen = ScreenInteractive::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);

Output

text
   top
────────────
   bottom

Examples: component/resizable_split

CaptureMouse ​

cpp
CapturedMouse CaptureMouse();

Try to get the unique lock about behing able to capture the mouse.

Returns: A unique lock if the mouse is not already captured, otherwise a null.

Exit ​

cpp
void Exit();

Exit the main loop.

ExitLoopClosure ​

cpp
Closure ExitLoopClosure();

Return a function to exit the main loop.

Examples: component/gallery, component/menu, component/menu2, component/modal_dialog, component/modal_dialog_custom, component/nested_screen, component/renderer, component/with_restored_io

HasQuitted ​

cpp
bool HasQuitted();

Return whether the main loop has been quit.

Examples: component/custom_loop

Loop ​

cpp
void Loop(Component);

Execute the main loop.

Parameters:

  • component: The component to draw.

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/custom_loop, component/dropdown, component/flexbox_gallery (+33 more)

Post ​

cpp
void Post(Task task);

Add a task to the main loop. It will be executed later, after every other scheduled tasks.

Examples: component/homescreen

PostEvent ​

cpp
void PostEvent(Event event);

Add an event to the main loop. It will be executed later, after every other scheduled events.

TrackMouse ​

cpp
void TrackMouse(bool enable = true);

Set whether mouse is tracked and events reported. called outside of the main loop. E.g ScreenInteractive::Loop(...).

Parameters:

  • enable: Whether to enable mouse event tracking.

Note

This muse be called outside of the main loop. E.g. before calling ScreenInteractive::Loop.

Note

Mouse tracking is enabled by default.

Note

Mouse tracking is only supported on terminals that supports it.

Example

cpp
auto screen = ScreenInteractive::TerminalOutput();
screen.TrackMouse(false);
screen.Loop(component);

Slider ​

cpp
Component Slider(ConstStringRef label, Ref< int > value, ConstRef< int > min = 0, ConstRef< int > max = 100, ConstRef< int > increment = 5);

An horizontal slider.

Parameters:

  • label: The name of the slider.
  • value: The current value of the slider.
  • min: The minimum value.
  • max: The maximum value.
  • increment: The increment when used by the cursor.

Example

cpp
auto screen = ScreenInteractive::TerminalOutput();
int value = 50;
auto slider = Slider("Value:", &value, 0, 100, 1);
screen.Loop(slider);

Output

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

Examples: component/focus, component/gallery, component/linear_gradient_gallery, component/slider, component/slider_direction, component/slider_rgb, component/window

Slider ​

cpp
Component Slider(SliderOption< T > options);

A slider in any direction.

Parameters:

  • options: The options

Example

cpp
auto screen = ScreenInteractive::TerminalOutput();
int value = 50;
auto slider = Slider({
  .value = &value,
  .min = 0,
  .max = 100,
  .increment= 20,
});
screen.Loop(slider);

Examples: component/focus, component/gallery, component/linear_gradient_gallery, component/slider, component/slider_direction, component/slider_rgb, component/window

Toggle ​

cpp
Component Toggle(ConstStringListRef entries, int * selected);

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

Parameters:

  • entries: The list of selectable entries to display.
  • selected: Reference the selected entry. See also Menu.

Examples: component/gallery, component/menu_style, component/tab_horizontal, component/toggle

SetAnimation ​

cpp
void SetAnimation(animation::Duration d, animation::easing::Function f);

Set how the underline should animate.

Parameters:

  • d: The duration of the animation.
  • f: The easing function of the animation.

Examples: component/menu_style

SetAnimationDuration ​

cpp
void SetAnimationDuration(animation::Duration d);

Set how the underline should animate.

Parameters:

  • d: The duration of the animation.

Examples: component/menu_underline_animated_gallery

SetAnimationFunction ​

cpp
void SetAnimationFunction(animation::easing::Function f);

Set how the underline should animate.

Parameters:

  • f: The easing function of the animation.

Examples: component/menu_style, component/menu_underline_animated_gallery

SetAnimationFunction ​

cpp
void SetAnimationFunction(animation::easing::Function f_leader, animation::easing::Function f_follower);

Set how the underline should animate. This is useful to desynchronize the animation of the leader and the follower.

Parameters:

  • f_leader: The duration of the animation for the leader.
  • f_follower: The duration of the animation for the follower.

Examples: component/menu_style, component/menu_underline_animated_gallery

Window ​

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

Parameters:

  • option: A struct holding every parameters.

See also: Window

Example

cpp
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,
});

Examples: component/menu_multiple, component/window