Feature resizable spilt with custom separator (#583)

* Feature: ResizableSplit with custom separator

This resolves:
    https://github.com/ArthurSonzogni/FTXUI/issues/580

Co-authored-by: Pin Loon Lee <pinloon_0428@hotmail.com>
This commit is contained in:
Arthur Sonzogni
2023-03-09 20:21:23 +01:00
committed by GitHub
parent 436c237213
commit 9b074d1e27
15 changed files with 385 additions and 310 deletions

View File

@@ -1,7 +1,8 @@
#include <algorithm> // for max, min
#include <ftxui/component/component_options.hpp> // for SliderOption
#include <string> // for allocator
#include <utility> // for move
#include <ftxui/dom/direction.hpp> // for Direction, Direction::Down, Direction::Left, Direction::Right, Direction::Up
#include <string> // for allocator
#include <utility> // for move
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
#include "ftxui/component/component.hpp" // for Make, Slider
@@ -9,7 +10,7 @@
#include "ftxui/component/event.hpp" // for Event, Event::ArrowDown, Event::ArrowLeft, Event::ArrowRight, Event::ArrowUp
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed, Mouse::Released
#include "ftxui/component/screen_interactive.hpp" // for Component
#include "ftxui/dom/elements.hpp" // for operator|, text, GaugeDirection, Element, xflex, hbox, color, underlined, GaugeDirection::Down, GaugeDirection::Left, GaugeDirection::Right, GaugeDirection::Up, reflect, Decorator, dim, vcenter, yflex, gaugeDirection
#include "ftxui/dom/elements.hpp" // for operator|, text, Element, xflex, hbox, color, underlined, reflect, Decorator, dim, vcenter, focus, nothing, select, yflex, gaugeDirection
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/color.hpp" // for Color, Color::GrayDark, Color::White
#include "ftxui/screen/util.hpp" // for clamp
@@ -18,13 +19,13 @@
namespace ftxui {
namespace {
Decorator flexDirection(GaugeDirection direction) {
Decorator flexDirection(Direction direction) {
switch (direction) {
case GaugeDirection::Up:
case GaugeDirection::Down:
case Direction::Up:
case Direction::Down:
return yflex;
case GaugeDirection::Left:
case GaugeDirection::Right:
case Direction::Left:
case Direction::Right:
return xflex;
}
return xflex; // NOT_REACHED()
@@ -52,56 +53,56 @@ class SliderBase : public ComponentBase {
void OnLeft() {
switch (options_->direction) {
case GaugeDirection::Right:
case Direction::Right:
value_() -= increment_();
break;
case GaugeDirection::Left:
case Direction::Left:
value_() += increment_();
break;
case GaugeDirection::Up:
case GaugeDirection::Down:
case Direction::Up:
case Direction::Down:
break;
}
}
void OnRight() {
switch (options_->direction) {
case GaugeDirection::Right:
case Direction::Right:
value_() += increment_();
break;
case GaugeDirection::Left:
case Direction::Left:
value_() -= increment_();
break;
case GaugeDirection::Up:
case GaugeDirection::Down:
case Direction::Up:
case Direction::Down:
break;
}
}
void OnUp() {
switch (options_->direction) {
case GaugeDirection::Up:
case Direction::Up:
value_() -= increment_();
break;
case GaugeDirection::Down:
case Direction::Down:
value_() += increment_();
break;
case GaugeDirection::Left:
case GaugeDirection::Right:
case Direction::Left:
case Direction::Right:
break;
}
}
void OnDown() {
switch (options_->direction) {
case GaugeDirection::Down:
case Direction::Down:
value_() -= increment_();
break;
case GaugeDirection::Up:
case Direction::Up:
value_() += increment_();
break;
case GaugeDirection::Left:
case GaugeDirection::Right:
case Direction::Left:
case Direction::Right:
break;
}
}
@@ -153,25 +154,25 @@ class SliderBase : public ComponentBase {
if (captured_mouse_) {
switch (options_->direction) {
case GaugeDirection::Right: {
case Direction::Right: {
value_() = min_() + (event.mouse().x - gauge_box_.x_min) *
(max_() - min_()) /
(gauge_box_.x_max - gauge_box_.x_min);
break;
}
case GaugeDirection::Left: {
case Direction::Left: {
value_() = max_() - (event.mouse().x - gauge_box_.x_min) *
(max_() - min_()) /
(gauge_box_.x_max - gauge_box_.x_min);
break;
}
case GaugeDirection::Down: {
case Direction::Down: {
value_() = min_() + (event.mouse().y - gauge_box_.y_min) *
(max_() - min_()) /
(gauge_box_.y_max - gauge_box_.y_min);
break;
}
case GaugeDirection::Up: {
case Direction::Up: {
value_() = max_() - (event.mouse().y - gauge_box_.y_min) *
(max_() - min_()) /
(gauge_box_.y_max - gauge_box_.y_min);