13bool GeneratorBool(
const char*& data,
size_t& size) {
18 auto out = bool(data[0] % 2);
24std::string GeneratorString(
const char*& data,
size_t& size) {
26 while (index < size && data[index]) {
30 auto out = std::string(data, data + index);
40 return std::move(out);
43int GeneratorInt(
const char* data,
size_t size) {
47 auto out = int(data[0]);
53Color GeneratorColor(
const char* data,
size_t size) {
54 return Color::RGB(GeneratorInt(data, size), GeneratorInt(data, size),
55 GeneratorInt(data, size));
58AnimatedColorOption GeneratorAnimatedColorOption(
const char* data,
60 AnimatedColorOption option;
61 option.enabled = GeneratorBool(data, size);
62 option.inactive = GeneratorColor(data, size);
63 option.active = GeneratorColor(data, size);
64 option.duration = std::chrono::milliseconds(GeneratorInt(data, size));
68AnimatedColorsOption GeneratorAnimatedColorsOptions(
const char* data,
70 AnimatedColorsOption option;
71 option.background = GeneratorAnimatedColorOption(data, size);
72 option.foreground = GeneratorAnimatedColorOption(data, size);
76ButtonOption GeneratorButtonOption(
const char* data,
size_t size) {
78 option.animated_colors = GeneratorAnimatedColorsOptions(data, size);
82UnderlineOption GeneratorUnderlineOption(
const char* data,
size_t size) {
83 UnderlineOption option;
84 option.enabled = GeneratorBool(data, size);
85 option.color_active = GeneratorColor(data, size);
86 option.color_inactive = GeneratorColor(data, size);
87 option.leader_duration = std::chrono::milliseconds(GeneratorInt(data, size));
88 option.follower_duration =
89 std::chrono::milliseconds(GeneratorInt(data, size));
90 option.leader_delay = std::chrono::milliseconds(GeneratorInt(data, size));
91 option.follower_delay = std::chrono::milliseconds(GeneratorInt(data, size));
95MenuEntryOption GeneratorMenuEntryOption(
const char* data,
size_t size) {
96 MenuEntryOption option;
97 option.animated_colors = GeneratorAnimatedColorsOptions(data, size);
101MenuOption GeneratorMenuOption(
const char* data,
size_t size) {
103 option.underline = GeneratorUnderlineOption(data, size);
104 option.entries_option = GeneratorMenuEntryOption(data, size);
105 option.direction =
static_cast<Direction>(GeneratorInt(data, size) % 4);
111std::vector<std::string> g_list;
113Components GeneratorComponents(
const char*& data,
size_t& size,
int depth);
115Component GeneratorComponent(
const char*& data,
size_t& size,
int depth) {
117 int value = GeneratorInt(data, size);
119 return Button(GeneratorString(data, size), [] {});
122 constexpr int value_max = 19;
123 value = (
value % value_max + value_max) % value_max;
127 GeneratorString(data, size), [] {},
128 GeneratorButtonOption(data, size));
130 return Checkbox(GeneratorString(data, size), &g_bool);
132 return Input(GeneratorString(data, size), GeneratorString(data, size));
134 return Menu(&g_list, &g_int, GeneratorMenuOption(data, size));
138 return Toggle(&g_list, &g_int);
140 return Slider(GeneratorString(data, size), &g_int,
141 GeneratorInt(data, size), GeneratorInt(data, size),
142 GeneratorInt(data, size));
145 GeneratorComponent(data, size, depth - 1),
149 GeneratorComponent(data, size, depth - 1),
153 GeneratorComponent(data, size, depth - 1),
157 GeneratorComponent(data, size, depth - 1),
160 return Container::Vertical(GeneratorComponents(data, size, depth - 1));
163 return Container::Vertical(GeneratorComponents(data, size, depth - 1),
167 return Container::Horizontal(GeneratorComponents(data, size, depth - 1));
169 return Container::Horizontal(GeneratorComponents(data, size, depth - 1),
172 return Container::Tab(GeneratorComponents(data, size, depth - 1), &g_int);
174 return Maybe(GeneratorComponent(data, size, depth - 1), &g_bool);
179 GeneratorComponent(data, size, depth - 1),
180 GeneratorBool(data, size));
186Components GeneratorComponents(
const char*& data,
size_t& size,
int depth) {
189 while (size && GeneratorInt(data, size) % 2) {
190 out.push_back(GeneratorComponent(data, size, depth - 1));
193 return std::move(out);
198 g_bool = GeneratorBool(data, size);
199 g_int = GeneratorInt(data, size);
201 "test_1",
"test_2",
"test_3",
"test_4",
"test_5",
205 auto component = GeneratorComponent(data, size, depth);
207 int width = GeneratorInt(data, size);
208 int height = GeneratorInt(data, size);
217 Screen::Create(Dimension::Fixed(width), Dimension::Fixed(height));
220 std::vector<Event> events;
224 for (
size_t i = 0; i <
size; ++i) {
228 for (
const auto& event : events) {
229 component->OnEvent(event);
230 auto document = component->Render();
int LLVMFuzzerTestOneInput(const char *data, size_t size)
Component Button(ConstStringRef label, std::function< void()> on_click, ButtonOption options=ButtonOption::Simple())
Draw a button. Execute a function when clicked.
Component ResizableSplitTop(Component main, Component back, int *main_size)
An vertical split in between two components, configurable using the mouse.
Component Toggle(ConstStringListRef entries, int *selected)
An horizontal list of elements. The user can navigate through them.
Component Checkbox(ConstStringRef label, bool *checked, CheckboxOption options=CheckboxOption::Simple())
Draw checkable element.
Component Maybe(Component child, std::function< bool()> show)
Decorate a component |child|. It is shown only when |show| returns true.
Component ResizableSplitRight(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Component Input(StringRef content, InputOption options={})
An input box for editing text.
Component Dropdown(ConstStringListRef entries, int *selected)
A dropdown menu.
Component Radiobox(ConstStringListRef entries, int *selected_, RadioboxOption options={})
A list of element, where only one can be selected.
Component ResizableSplitBottom(Component main, Component back, int *main_size)
An vertical split in between two components, configurable using the mouse.
Component Menu(ConstStringListRef entries, int *selected_, MenuOption options=MenuOption::Vertical())
A list of text. The focused element is selected.
Component ResizableSplitLeft(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Decorator size(WidthOrHeight direction, Constraint constraint, int value)
Apply a constraint on the size of an element.
Direction
Direction is an enumeration that represents the four cardinal directions.
The FTXUI ftxui:: namespace.
std::vector< Component > Components
Component Collapsible(ConstStringRef label, Component child, Ref< bool > show=false)
A collapsible component. It displays a checkbox with an arrow. Once activated, the child is displayed...
Component Slider(SliderOption< T > options)
A slider in any direction.
FTXUI_EXPORT(SCREEN) std FTXUI_EXPORT(SCREEN) std std::wstring to_wstring(T s)
void Render(Screen &screen, Node *node, Selection &selection)
std::shared_ptr< ComponentBase > Component