mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Compare commits
7 Commits
HarryPehko
...
0cd3bdcdab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cd3bdcdab | ||
|
|
21b24a1b78 | ||
|
|
bfd07ba309 | ||
|
|
d20b84f720 | ||
|
|
0dde21f09e | ||
|
|
2d50269730 | ||
|
|
df2ddcc588 |
@@ -169,13 +169,15 @@ ftxui_cc_library(
|
||||
"src/ftxui/component/util.cpp",
|
||||
"src/ftxui/component/window.cpp",
|
||||
|
||||
|
||||
# Private header from ftxui:dom.
|
||||
"src/ftxui/dom/node_decorator.hpp",
|
||||
|
||||
# Private header from ftxui:screen.
|
||||
"src/ftxui/screen/string_internal.hpp",
|
||||
"src/ftxui/screen/util.hpp",
|
||||
|
||||
# Private header.
|
||||
"include/ftxui/util/warn_windows_macro.hpp",
|
||||
],
|
||||
hdrs = [
|
||||
"include/ftxui/component/animation.hpp",
|
||||
|
||||
@@ -29,6 +29,8 @@ Next
|
||||
### Component
|
||||
- Fix ScreenInteractive::FixedSize screen stomps on the preceding terminal
|
||||
output. Thanks @zozowell in #1064.
|
||||
- Fix vertical `ftxui::Slider`. The "up" key was previously decreasing the
|
||||
value. Thanks @its-pablo in #1093 for reporting the issue.
|
||||
|
||||
|
||||
6.1.9 (2025-05-07)
|
||||
|
||||
@@ -17,10 +17,12 @@ add_subdirectory(dom)
|
||||
if (EMSCRIPTEN)
|
||||
get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES)
|
||||
foreach(file
|
||||
"index.css"
|
||||
"index.html"
|
||||
"index.mjs"
|
||||
"index.css"
|
||||
"run_webassembly.py")
|
||||
"run_webassembly.py"
|
||||
"sw.js"
|
||||
)
|
||||
configure_file(${file} ${file})
|
||||
endforeach(file)
|
||||
endif()
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#ifndef FTXUI_COMPONENT_RECEIVER_HPP_
|
||||
#define FTXUI_COMPONENT_RECEIVER_HPP_
|
||||
|
||||
#include <ftxui/util/warn_windows_macro.h>
|
||||
#include <ftxui/util/warn_windows_macro.hpp>
|
||||
#include <algorithm> // for copy, max
|
||||
#include <atomic> // for atomic, __atomic_base
|
||||
#include <condition_variable> // for condition_variable
|
||||
|
||||
@@ -33,6 +33,20 @@ Decorator flexDirection(Direction direction) {
|
||||
return xflex; // NOT_REACHED()
|
||||
}
|
||||
|
||||
Direction Opposite(Direction d) {
|
||||
switch (d) {
|
||||
case Direction::Up:
|
||||
return Direction::Down;
|
||||
case Direction::Down:
|
||||
return Direction::Up;
|
||||
case Direction::Left:
|
||||
return Direction::Right;
|
||||
case Direction::Right:
|
||||
return Direction::Left;
|
||||
}
|
||||
return d; // NOT_REACHED()
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class SliderBase : public SliderOption<T>, public ComponentBase {
|
||||
public:
|
||||
@@ -47,59 +61,15 @@ class SliderBase : public SliderOption<T>, public ComponentBase {
|
||||
flexDirection(this->direction) | reflect(gauge_box_) | gauge_color;
|
||||
}
|
||||
|
||||
void OnLeft() {
|
||||
switch (this->direction) {
|
||||
case Direction::Right:
|
||||
this->value() -= this->increment();
|
||||
break;
|
||||
case Direction::Left:
|
||||
this->value() += this->increment();
|
||||
break;
|
||||
case Direction::Up:
|
||||
case Direction::Down:
|
||||
break;
|
||||
void OnDirection(Direction pressed) {
|
||||
if (pressed == this->direction) {
|
||||
this->value() += this->increment();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void OnRight() {
|
||||
switch (this->direction) {
|
||||
case Direction::Right:
|
||||
this->value() += this->increment();
|
||||
break;
|
||||
case Direction::Left:
|
||||
this->value() -= this->increment();
|
||||
break;
|
||||
case Direction::Up:
|
||||
case Direction::Down:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnUp() {
|
||||
switch (this->direction) {
|
||||
case Direction::Up:
|
||||
this->value() -= this->increment();
|
||||
break;
|
||||
case Direction::Down:
|
||||
this->value() += this->increment();
|
||||
break;
|
||||
case Direction::Left:
|
||||
case Direction::Right:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDown() {
|
||||
switch (this->direction) {
|
||||
case Direction::Down:
|
||||
this->value() += this->increment();
|
||||
break;
|
||||
case Direction::Up:
|
||||
this->value() -= this->increment();
|
||||
break;
|
||||
case Direction::Left:
|
||||
case Direction::Right:
|
||||
break;
|
||||
if (pressed == Opposite(this->direction)) {
|
||||
this->value() -= this->increment();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,16 +80,16 @@ class SliderBase : public SliderOption<T>, public ComponentBase {
|
||||
|
||||
T old_value = this->value();
|
||||
if (event == Event::ArrowLeft || event == Event::Character('h')) {
|
||||
OnLeft();
|
||||
OnDirection(Direction::Left);
|
||||
}
|
||||
if (event == Event::ArrowRight || event == Event::Character('l')) {
|
||||
OnRight();
|
||||
OnDirection(Direction::Right);
|
||||
}
|
||||
if (event == Event::ArrowUp || event == Event::Character('k')) {
|
||||
OnDown();
|
||||
OnDirection(Direction::Up);
|
||||
}
|
||||
if (event == Event::ArrowDown || event == Event::Character('j')) {
|
||||
OnUp();
|
||||
OnDirection(Direction::Down);
|
||||
}
|
||||
|
||||
this->value() = std::max(this->min(), std::min(this->max(), this->value()));
|
||||
|
||||
@@ -58,11 +58,39 @@ void ComputeShrinkHard(std::vector<Element>* elements,
|
||||
|
||||
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
|
||||
|
||||
void Compute(std::vector<Element>* elements, int target_size) {
|
||||
void Compute(std::vector<Element>* elements, int target_size, bool hack) {
|
||||
int size = 0;
|
||||
int flex_grow_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);
|
||||
|
||||
} else {
|
||||
ComputeShrinkHard(elements, extra_space + flex_shrink_size,
|
||||
size - flex_shrink_size);
|
||||
if (hack)
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
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
|
||||
|
||||
#endif /* end of include guard: FTXUI_DOM_BOX_HELPER_HPP */
|
||||
|
||||
@@ -46,6 +46,12 @@ class GridBox : public Node {
|
||||
line.push_back(filler());
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& line : lines_) {
|
||||
for (const auto &element : line) {
|
||||
children_.push_back( element );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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_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 box_y = box;
|
||||
|
||||
@@ -216,13 +216,13 @@ Element Table::Render() {
|
||||
|
||||
// Line
|
||||
if ((x + y) % 2 == 1) {
|
||||
it = std::move(it) | flex;
|
||||
it = std::move(it)| flex; //it = std::move(it); // | flex;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Cells
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user