14bool GeneratorBool(
const char*& data,
size_t& size) {
19 auto out = bool(data[0] % 2);
25std::string GeneratorString(
const char*& data,
size_t& size) {
27 while (index < size && data[index]) {
31 auto out = std::string(data, data + index);
41 return std::move(out);
44int GeneratorInt(
const char* data,
size_t size) {
48 auto out = int(data[0]);
54Color GeneratorColor(
const char* data,
size_t size) {
55 return Color::RGB(GeneratorInt(data, size), GeneratorInt(data, size),
56 GeneratorInt(data, size));
59AnimatedColorOption GeneratorAnimatedColorOption(
const char* data,
61 AnimatedColorOption option;
62 option.enabled = GeneratorBool(data, size);
63 option.inactive = GeneratorColor(data, size);
64 option.active = GeneratorColor(data, size);
65 option.duration = std::chrono::milliseconds(GeneratorInt(data, size));
69AnimatedColorsOption GeneratorAnimatedColorsOptions(
const char* data,
71 AnimatedColorsOption option;
72 option.background = GeneratorAnimatedColorOption(data, size);
73 option.foreground = GeneratorAnimatedColorOption(data, size);
77ButtonOption GeneratorButtonOption(
const char* data,
size_t size) {
79 option.animated_colors = GeneratorAnimatedColorsOptions(data, size);
83UnderlineOption GeneratorUnderlineOption(
const char* data,
size_t size) {
84 UnderlineOption option;
85 option.enabled = GeneratorBool(data, size);
86 option.color_active = GeneratorColor(data, size);
87 option.color_inactive = GeneratorColor(data, size);
88 option.leader_duration = std::chrono::milliseconds(GeneratorInt(data, size));
89 option.follower_duration =
90 std::chrono::milliseconds(GeneratorInt(data, size));
91 option.leader_delay = std::chrono::milliseconds(GeneratorInt(data, size));
92 option.follower_delay = std::chrono::milliseconds(GeneratorInt(data, size));
96MenuEntryOption GeneratorMenuEntryOption(
const char* data,
size_t size) {
97 MenuEntryOption option;
98 option.animated_colors = GeneratorAnimatedColorsOptions(data, size);
102MenuOption GeneratorMenuOption(
const char* data,
size_t size) {
104 option.underline = GeneratorUnderlineOption(data, size);
105 option.entries_option = GeneratorMenuEntryOption(data, size);
106 option.direction =
static_cast<Direction>(GeneratorInt(data, size) % 4);
112std::vector<std::string> g_list;
114Components GeneratorComponents(
const char*& data,
size_t& size,
int depth);
116Component GeneratorComponent(
const char*& data,
size_t& size,
int depth) {
118 int value = GeneratorInt(data, size);
120 return Button(GeneratorString(data, size), [] {});
123 constexpr int value_max = 26;
124 value = (
value % value_max + value_max) % value_max;
128 GeneratorString(data, size), [] {},
129 GeneratorButtonOption(data, size));
131 return Checkbox(GeneratorString(data, size), &g_bool);
133 return Input(GeneratorString(data, size), GeneratorString(data, size));
135 return Menu(&g_list, &g_int, GeneratorMenuOption(data, size));
139 return Toggle(&g_list, &g_int);
141 return Slider(GeneratorString(data, size), &g_int,
142 GeneratorInt(data, size), GeneratorInt(data, size),
143 GeneratorInt(data, size));
146 GeneratorComponent(data, size, depth - 1),
150 GeneratorComponent(data, size, depth - 1),
154 GeneratorComponent(data, size, depth - 1),
158 GeneratorComponent(data, size, depth - 1),
161 return Container::Vertical(GeneratorComponents(data, size, depth - 1));
164 return Container::Vertical(GeneratorComponents(data, size, depth - 1),
168 return Container::Horizontal(GeneratorComponents(data, size, depth - 1));
170 return Container::Horizontal(GeneratorComponents(data, size, depth - 1),
173 return Container::Tab(GeneratorComponents(data, size, depth - 1), &g_int);
175 return Maybe(GeneratorComponent(data, size, depth - 1), &g_bool);
180 GeneratorComponent(data, size, depth - 1),
181 GeneratorBool(data, size));
183 return Container::Stacked(GeneratorComponents(data, size, depth - 1));
185 return MenuEntry(GeneratorString(data, size));
187 return Renderer(GeneratorComponent(data, size, depth - 1),
188 [] {
return text(
"hello"); });
190 return CatchEvent(GeneratorComponent(data, size, depth - 1),
191 [](Event) {
return true; });
193 return Modal(GeneratorComponent(data, size, depth - 1),
194 GeneratorComponent(data, size, depth - 1), &g_bool);
196 return Hoverable(GeneratorComponent(data, size, depth - 1), &g_bool);
198 WindowOptions options;
199 options.inner = GeneratorComponent(data, size, depth - 1);
200 options.title = GeneratorString(data, size);
208Components GeneratorComponents(
const char*& data,
size_t& size,
int depth) {
211 while (size && GeneratorInt(data, size) % 2) {
212 out.push_back(GeneratorComponent(data, size, depth - 1));
215 return std::move(out);
220 g_bool = GeneratorBool(data, size);
221 g_int = GeneratorInt(data, size);
223 "test_1",
"test_2",
"test_3",
"test_4",
"test_5",
227 auto component = GeneratorComponent(data, size, depth);
229 int width = GeneratorInt(data, size);
230 int height = GeneratorInt(data, size);
239 Screen::Create(Dimension::Fixed(width), Dimension::Fixed(height));
242 std::vector<Event> events;
246 for (
size_t i = 0; i <
size; ++i) {
250 for (
const auto& event : events) {
251 component->OnEvent(event);
252 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.
FTXUI_EXPORT(COMPONENT) ComponentDecorator Maybe(std Component Modal(Component main, Component modal, const bool *show_modal)
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Component Hoverable(Component component, bool *hover)
Wrap a component. Gives the ability to know if it is hovered by the mouse.
Component Checkbox(ConstStringRef label, bool *checked, CheckboxOption options=CheckboxOption::Simple())
Draw checkable element.
Component Window(WindowOptions option)
A draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stac...
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.
Component MenuEntry(ConstStringRef label, MenuEntryOption options={})
A specific menu entry. They can be put into a Container::Vertical to form a menu.
Element text(std::string_view text)
Display a piece of UTF8 encoded unicode text.
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
Component CatchEvent(Component child, std::function< bool(Event)>)