mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Compare commits
4 Commits
6874ef7b63
...
09ddb27934
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09ddb27934 | ||
|
|
994915dbb9 | ||
|
|
2d50269730 | ||
|
|
df2ddcc588 |
@@ -6,6 +6,7 @@ add_library(ftxui-modules)
|
|||||||
|
|
||||||
target_sources(ftxui-modules
|
target_sources(ftxui-modules
|
||||||
PUBLIC FILE_SET CXX_MODULES FILES
|
PUBLIC FILE_SET CXX_MODULES FILES
|
||||||
|
src/ftxui/ftxui.cppm
|
||||||
src/ftxui/component.cppm
|
src/ftxui/component.cppm
|
||||||
src/ftxui/component/animation.cppm
|
src/ftxui/component/animation.cppm
|
||||||
src/ftxui/component/captured_mouse.cppm
|
src/ftxui/component/captured_mouse.cppm
|
||||||
|
|||||||
@@ -12,8 +12,24 @@ FTXUI experimentally supports
|
|||||||
compilation times and improve code organization. Each header has a
|
compilation times and improve code organization. Each header has a
|
||||||
corresponding module.
|
corresponding module.
|
||||||
|
|
||||||
**Example with CMake and Ninja**
|
Use the FTXUI_BUILD_MODULES option to build the FTXUI project itself to provide C++ 20 modules,
|
||||||
|
for example with CMake and Ninja:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cmake \
|
||||||
|
-DCMAKE_GENERATOR=Ninja \
|
||||||
|
-DFTXUI_BUILD_MODULES=ON \
|
||||||
|
..
|
||||||
|
|
||||||
|
ninja
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> To use modules, you need a C++20 compatible compiler, CMake version 3.20 or
|
||||||
|
> higher, and use a compatible generator like Ninja. Note that Makefile
|
||||||
|
> generators **do not support modules**.
|
||||||
|
|
||||||
|
Then, in your own code you can consume the modules and code as normal:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
import ftxui;
|
import ftxui;
|
||||||
@@ -26,23 +42,30 @@ int main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
Note, the `ftxui` convenience module which simply pulls together all the modules:
|
||||||
cmake \
|
|
||||||
-DCMAKE_GENERATOR=Ninja \
|
|
||||||
-DFTXUI_BUILD_MODULES=ON \
|
|
||||||
..
|
|
||||||
|
|
||||||
ninja
|
```cpp
|
||||||
|
export import ftxui.component;
|
||||||
|
export import ftxui.dom;
|
||||||
|
export import ftxui.screen;
|
||||||
|
export import ftxui.util;
|
||||||
|
```
|
||||||
|
You can instead import only the module(s) you need if desired.
|
||||||
|
|
||||||
|
To properly find and link the modules with CMake, use `target_link_libraries` to get the right
|
||||||
|
compiler, linker, etc. flags.
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
target_link_libraries(my_executable
|
||||||
|
#...whatever...
|
||||||
|
PRIVATE ftxui::modules
|
||||||
|
)
|
||||||
```
|
```
|
||||||
> [!NOTE]
|
|
||||||
> To use modules, you need a C++20 compatible compiler, CMake version 3.20 or
|
|
||||||
> higher, and use a compatible generator like Ninja. Note that Makefile
|
|
||||||
> generators **do not support modules**.
|
|
||||||
|
|
||||||
### Module list
|
### Module list
|
||||||
|
|
||||||
The modules directly reference the corresponding header, or a group of related
|
The modules directly reference the corresponding header, or a group of related
|
||||||
headers to provide a more convenient interface. The following modules
|
headers to provide a more convenient interface. The following modules
|
||||||
are available:
|
are available:
|
||||||
|
|
||||||
- `ftxui`
|
- `ftxui`
|
||||||
|
|||||||
@@ -58,11 +58,39 @@ void ComputeShrinkHard(std::vector<Element>* elements,
|
|||||||
|
|
||||||
element.size = element.min_size + added_space;
|
element.size = element.min_size + added_space;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Called when the size allowed is lower than the requested size, and the
|
||||||
|
// shrinkable element can not absorbe the (negative) extra_space. This assign
|
||||||
|
// zero to shrinkable elements and distribute the remaining (negative)
|
||||||
|
// extra_space toward the other non shrinkable elements.
|
||||||
|
void ComputeShrinkHardHack(std::vector<Element>* elements,
|
||||||
|
int extra_space,
|
||||||
|
int size)
|
||||||
|
{
|
||||||
|
for (Element& element : *elements)
|
||||||
|
{
|
||||||
|
if (element.flex_shrink != 0)
|
||||||
|
{
|
||||||
|
element.size = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = elements->rbegin(); it != elements->rend(); ++it)
|
||||||
|
{
|
||||||
|
Element& element = *it;
|
||||||
|
|
||||||
|
auto remove = std::min(element.min_size, -extra_space);
|
||||||
|
element.size = element.min_size - remove;
|
||||||
|
extra_space += remove;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void Compute(std::vector<Element>* elements, int target_size) {
|
void Compute(std::vector<Element>* elements, int target_size, bool hack) {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
int flex_grow_sum = 0;
|
int flex_grow_sum = 0;
|
||||||
int flex_shrink_sum = 0;
|
int flex_shrink_sum = 0;
|
||||||
@@ -84,8 +112,14 @@ void Compute(std::vector<Element>* elements, int target_size) {
|
|||||||
ComputeShrinkEasy(elements, extra_space, flex_shrink_sum);
|
ComputeShrinkEasy(elements, extra_space, flex_shrink_sum);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ComputeShrinkHard(elements, extra_space + flex_shrink_size,
|
if (hack)
|
||||||
size - flex_shrink_size);
|
{
|
||||||
|
ComputeShrinkHardHack(elements, extra_space + flex_shrink_size, size - flex_shrink_size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ComputeShrinkHard(elements, extra_space + flex_shrink_size, size - flex_shrink_size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ struct Element {
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void Compute(std::vector<Element>* elements, int target_size);
|
void Compute(std::vector<Element>* elements, int target_size, bool hack=false);
|
||||||
} // namespace ftxui::box_helper
|
} // namespace ftxui::box_helper
|
||||||
|
|
||||||
#endif /* end of include guard: FTXUI_DOM_BOX_HELPER_HPP */
|
#endif /* end of include guard: FTXUI_DOM_BOX_HELPER_HPP */
|
||||||
|
|||||||
@@ -46,6 +46,12 @@ class GridBox : public Node {
|
|||||||
line.push_back(filler());
|
line.push_back(filler());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto& line : lines_) {
|
||||||
|
for (const auto &element : line) {
|
||||||
|
children_.push_back( element );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeRequirement() override {
|
void ComputeRequirement() override {
|
||||||
@@ -109,7 +115,7 @@ class GridBox : public Node {
|
|||||||
|
|
||||||
const int target_size_x = box.x_max - box.x_min + 1;
|
const int target_size_x = box.x_max - box.x_min + 1;
|
||||||
const int target_size_y = box.y_max - box.y_min + 1;
|
const int target_size_y = box.y_max - box.y_min + 1;
|
||||||
box_helper::Compute(&elements_x, target_size_x);
|
box_helper::Compute(&elements_x, target_size_x, true);
|
||||||
box_helper::Compute(&elements_y, target_size_y);
|
box_helper::Compute(&elements_y, target_size_y);
|
||||||
|
|
||||||
Box box_y = box;
|
Box box_y = box;
|
||||||
|
|||||||
@@ -216,13 +216,13 @@ Element Table::Render() {
|
|||||||
|
|
||||||
// Line
|
// Line
|
||||||
if ((x + y) % 2 == 1) {
|
if ((x + y) % 2 == 1) {
|
||||||
it = std::move(it) | flex;
|
it = std::move(it)| flex; //it = std::move(it); // | flex;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cells
|
// Cells
|
||||||
if ((x % 2) == 1 && (y % 2) == 1) {
|
if ((x % 2) == 1 && (y % 2) == 1) {
|
||||||
it = std::move(it) | flex_shrink;
|
// it = std::move(it) | flex_shrink; //it = std::move(it) | flex_shrink;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user