FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
input_style.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient
5#include <ftxui/screen/color.hpp> // for Color, Color::White, Color::Red, Color::Blue, Color::Black, Color::GrayDark, ftxui
6#include <functional> // for function
7#include <string> // for allocator, string
8#include <utility> // for move
9
10#include "ftxui/component/component.hpp" // for Input, Horizontal, Vertical, operator|
11#include "ftxui/component/component_base.hpp" // for Component
12#include "ftxui/component/component_options.hpp" // for InputState, InputOption
13#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
14#include "ftxui/dom/elements.hpp" // for operator|=, Element, bgcolor, operator|, separatorEmpty, color, borderEmpty, separator, text, center, dim, hbox, vbox, border, borderDouble, borderRounded
15
16int main() {
17 using namespace ftxui;
18
19 InputOption style_1 = InputOption::Default();
20
21 InputOption style_2 = InputOption::Spacious();
22
23 InputOption style_3 = InputOption::Spacious();
24 style_3.transform = [](InputState state) {
25 state.element |= borderEmpty;
26
27 if (state.is_placeholder) {
28 state.element |= dim;
29 }
30
31 if (state.focused) {
32 state.element |= borderDouble;
33 state.element |= bgcolor(Color::White);
34 state.element |= color(Color::Black);
35 } else if (state.hovered) {
36 state.element |= borderRounded;
37 state.element |= bgcolor(LinearGradient(90, Color::Blue, Color::Red));
38 state.element |= color(Color::White);
39 } else {
40 state.element |= border;
41 state.element |= bgcolor(LinearGradient(0, Color::Blue, Color::Red));
42 state.element |= color(Color::White);
43 }
44
45 return state.element;
46 };
47
48 InputOption style_4 = InputOption::Spacious();
49 style_4.transform = [](InputState state) {
50 state.element = hbox({
51 text("Theorem") | center | borderEmpty | bgcolor(Color::Red),
52 separatorEmpty(),
53 separator() | color(Color::White),
54 separatorEmpty(),
55 std::move(state.element),
56 });
57
58 state.element |= borderEmpty;
59 if (state.is_placeholder) {
60 state.element |= dim;
61 }
62
63 if (state.focused) {
64 state.element |= bgcolor(Color::Black);
65 } else {
66 state.element |= bgcolor(Color::Blue);
67 }
68
69 if (state.hovered) {
70 state.element |= bgcolor(Color::GrayDark);
71 }
72
73 return vbox({state.element, separatorEmpty()});
74 };
75
76 auto generateUiFromStyle = [&](InputOption style) {
77 auto first_name = new std::string(); // Leaked
78 auto middle_name = new std::string(); // Leaked
79 auto last_name = new std::string(); // Leaked
80 return Container::Vertical({
81 Input(first_name, "first name", style),
82 Input(middle_name, "middle name", style),
83 Input(last_name, "last name", style),
84 }) |
85 borderEmpty;
86 };
87
88 auto ui = Container::Horizontal({
89 generateUiFromStyle(style_1),
90 generateUiFromStyle(style_2),
91 generateUiFromStyle(style_3),
92 generateUiFromStyle(style_4),
93 });
94
95 auto screen = ScreenInteractive::TerminalOutput();
96 screen.Loop(ui);
97}
std::function< Element(InputState)> transform
Option for the Input component.
A class representing the settings for linear-gradient color effect.
int main()
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
Used to define style for the Input component.