FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
flexbox_config.hpp
Go to the documentation of this file.
1// Copyright 2021 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#ifndef FTXUI_DOM_FLEXBOX_CONFIG_HPP
5#define FTXUI_DOM_FLEXBOX_CONFIG_HPP
6
7/*
8 This replicate the CSS flexbox model.
9 See guide for documentation:
10 https://css-tricks.com/snippets/css/a-guide-to-flexbox/
11*/
12
13 namespace ftxui {
14
15/// @brief FlexboxConfig is a configuration structure that defines the layout
16/// properties for a flexbox container.
17//
18/// It allows you to specify the direction of the flex items, whether they
19/// should wrap, how they should be justified along the main axis, and how
20/// they should be aligned along the cross axis.
21/// It also includes properties for gaps between flex items in both the
22/// main and cross axes.
23/// This structure is used to configure the layout behavior of flexbox
24/// containers in a terminal user interface.
25///
26/// @ingroup dom
27 struct FlexboxConfig {
28 /// This establishes the main-axis, thus defining the direction flex items are
29 /// placed in the flex container. Flexbox is (aside wrapping) single-direction
30 /// layout concept. Think of flex items as primarily laying out either in
31 /// horizontal rows or vertical columns.
32 enum class Direction {
33 Row, ///< Flex items are laid out in a row.
34 RowInversed, ///< Flex items are laid out in a row, but in reverse order.
35 Column, ///< Flex items are laid out in a column.
36 ColumnInversed ///< Flex items are laid out in a column, but in reverse
37 ///< order.
38 };
39 Direction direction = Direction::Row;
40
41 /// By default, flex items will all try to fit onto one line. You can change
42 /// that and allow the items to wrap as needed with this property.
43 enum class Wrap {
44 NoWrap, ///< Flex items will all try to fit onto one line.
45 Wrap, ///< Flex items will wrap onto multiple lines.
46 WrapInversed, ///< Flex items will wrap onto multiple lines, but in reverse
47 ///< order.
48 };
49 Wrap wrap = Wrap::Wrap;
50
51 /// This defines the alignment along the main axis. It helps distribute extra
52 /// free space leftover when either all the flex items on a line are
53 /// inflexible, or are flexible but have reached their maximum size. It also
54 /// exerts some control over the alignment of items when they overflow the
55 /// line.
56 enum class JustifyContent {
57 /// Items are aligned to the start of flexbox's direction.
58 FlexStart,
59 /// Items are aligned to the end of flexbox's direction.
60 FlexEnd,
61 /// Items are centered along the line.
62 Center,
63 /// Items are stretched to fill the line.
64 Stretch,
65 /// Items are evenly distributed in the line; first item is on the start
66 // line, last item on the end line
67 SpaceBetween,
68 /// Items are evenly distributed in the line with equal space around them.
69 /// Note that visually the spaces aren’t equal, since all the items have
70 /// equal space on both sides. The first item will have one unit of space
71 /// against the container edge, but two units of space between the next item
72 /// because that next item has its own spacing that applies.
73 SpaceAround,
74 /// Items are distributed so that the spacing between any two items (and the
75 /// space to the edges) is equal.
76 SpaceEvenly,
77 };
78 JustifyContent justify_content = JustifyContent::FlexStart;
79
80 /// This defines the default behavior for how flex items are laid out along
81 /// the cross axis on the current line. Think of it as the justify-content
82 /// version for the cross-axis (perpendicular to the main-axis).
83 enum class AlignItems {
84 FlexStart, ///< items are placed at the start of the cross axis.
85 FlexEnd, ///< items are placed at the end of the cross axis.
86 Center, ///< items are centered along the cross axis.
87 Stretch, ///< items are stretched to fill the cross axis.
88 };
89 AlignItems align_items = AlignItems::FlexStart;
90
91 // This aligns a flex container’s lines within when there is extra space in
92 // the cross-axis, similar to how justify-content aligns individual items
93 // within the main-axis.
94 enum class AlignContent {
95 FlexStart, ///< items are placed at the start of the cross axis.
96 FlexEnd, ///< items are placed at the end of the cross axis.
97 Center, ///< items are centered along the cross axis.
98 Stretch, ///< items are stretched to fill the cross axis.
99 SpaceBetween, ///< items are evenly distributed in the cross axis.
100 SpaceAround, ///< tems evenly distributed with equal space around each
101 ///< line.
102 SpaceEvenly, ///< items are evenly distributed in the cross axis with equal
103 ///< space around them.
104 };
105 AlignContent align_content = AlignContent::FlexStart;
106
107 int gap_x = 0;
108 int gap_y = 0;
109
110 // Constructor pattern. For chained use like:
111 // ```
112 // FlexboxConfig()
113 // .Set(FlexboxConfig::Direction::Row)
114 // .Set(FlexboxConfig::Wrap::Wrap);
115 // ```
116 FlexboxConfig& Set(FlexboxConfig::Direction);
117 FlexboxConfig& Set(FlexboxConfig::Wrap);
118 FlexboxConfig& Set(FlexboxConfig::JustifyContent);
119 FlexboxConfig& Set(FlexboxConfig::AlignItems);
120 FlexboxConfig& Set(FlexboxConfig::AlignContent);
121 FlexboxConfig& SetGap(int gap_x, int gap_y);
122};
123
124} // namespace ftxui
125
126#endif // FTXUI_DOM_FLEXBOX_CONFIG_HPP
ftxui::FlexboxConfig::align_content
AlignContent align_content
Definition flexbox_config.hpp:105
ftxui::FlexboxConfig::gap_x
int gap_x
Definition flexbox_config.hpp:107
ftxui::FlexboxConfig::align_items
AlignItems align_items
Definition flexbox_config.hpp:89
ftxui::FlexboxConfig::AlignContent
AlignContent
Definition flexbox_config.hpp:94
ftxui::FlexboxConfig::AlignContent::FlexStart
@ FlexStart
items are placed at the start of the cross axis.
ftxui::FlexboxConfig::Direction
Direction
Definition flexbox_config.hpp:32
ftxui::FlexboxConfig::Direction::Column
@ Column
Flex items are laid out in a column.
ftxui::FlexboxConfig::Direction::ColumnInversed
@ ColumnInversed
ftxui::FlexboxConfig::Direction::Row
@ Row
Flex items are laid out in a row.
ftxui::FlexboxConfig::Direction::RowInversed
@ RowInversed
Flex items are laid out in a row, but in reverse order.
ftxui::FlexboxConfig::direction
Direction direction
Definition flexbox_config.hpp:39
ftxui::FlexboxConfig::wrap
Wrap wrap
Definition flexbox_config.hpp:49
ftxui::FlexboxConfig::Wrap
Wrap
Definition flexbox_config.hpp:43
ftxui::FlexboxConfig::Wrap::NoWrap
@ NoWrap
Flex items will all try to fit onto one line.
ftxui::FlexboxConfig::Wrap::Wrap
@ Wrap
Flex items will wrap onto multiple lines.
ftxui::FlexboxConfig::Wrap::WrapInversed
@ WrapInversed
ftxui::FlexboxConfig::AlignItems
AlignItems
Definition flexbox_config.hpp:83
ftxui::FlexboxConfig::AlignItems::FlexStart
@ FlexStart
items are placed at the start of the cross axis.
ftxui::FlexboxConfig::SetGap
FlexboxConfig & SetGap(int gap_x, int gap_y)
Set the flexbox flex direction.
Definition flexbox_config.cpp:39
ftxui::FlexboxConfig::gap_y
int gap_y
Definition flexbox_config.hpp:108
ftxui::FlexboxConfig::justify_content
JustifyContent justify_content
Definition flexbox_config.hpp:78
ftxui::FlexboxConfig::JustifyContent
JustifyContent
Definition flexbox_config.hpp:56
ftxui::FlexboxConfig::JustifyContent::SpaceEvenly
@ SpaceEvenly
ftxui::FlexboxConfig::JustifyContent::Center
@ Center
Items are centered along the line.
ftxui::FlexboxConfig::JustifyContent::FlexStart
@ FlexStart
Items are aligned to the start of flexbox's direction.
ftxui::FlexboxConfig::JustifyContent::FlexEnd
@ FlexEnd
Items are aligned to the end of flexbox's direction.
ftxui::FlexboxConfig::JustifyContent::SpaceAround
@ SpaceAround
ftxui::FlexboxConfig::JustifyContent::SpaceBetween
@ SpaceBetween
Items are evenly distributed in the line; first item is on the start.
ftxui::FlexboxConfig::JustifyContent::Stretch
@ Stretch
Items are stretched to fill the line.
ftxui::FlexboxConfig::Set
FlexboxConfig & Set(FlexboxConfig::Direction)
Set the flexbox direction.
Definition flexbox_config.cpp:9
ftxui::FlexboxConfig
FlexboxConfig is a configuration structure that defines the layout properties for a flexbox container...
Definition flexbox_config.hpp:27
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10