mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-10-22 12:38:13 +08:00
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:
@@ -1,11 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gtest/gtest.h> // for AssertionResult, Message, TestPartResult, Test, EXPECT_EQ, EXPECT_TRUE, TestInfo (ptr only), TEST
|
||||
#include <ftxui/dom/direction.hpp> // for Direction, Direction::Down, Direction::Left, Direction::Right, Direction::Up
|
||||
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Renderer, ResizableSplitBottom, ResizableSplitLeft, ResizableSplitRight, ResizableSplitTop
|
||||
#include "ftxui/component/component.hpp" // for ResizableSplit, Renderer, ResizableSplitBottom, ResizableSplitLeft, ResizableSplitRight, ResizableSplitTop
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed, Mouse::Released
|
||||
#include "ftxui/dom/elements.hpp" // for text, Element
|
||||
#include "ftxui/dom/elements.hpp" // for Element, separatorDouble, text
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
|
||||
@@ -56,6 +57,31 @@ TEST(ResizableSplit, BasicLeft) {
|
||||
EXPECT_EQ(position, 10);
|
||||
}
|
||||
|
||||
TEST(ResizableSplit, BasicLeftWithCustomSeparator) {
|
||||
int position = 1;
|
||||
auto component = ResizableSplit({
|
||||
.main = BasicComponent(),
|
||||
.back = BasicComponent(),
|
||||
.direction = Direction::Left,
|
||||
.main_size = &position,
|
||||
.separator_func = [] { return separatorDouble(); },
|
||||
});
|
||||
auto screen = Screen(4, 4);
|
||||
Render(screen, component->Render());
|
||||
EXPECT_EQ(position, 1);
|
||||
EXPECT_EQ(screen.ToString(),
|
||||
" ║ \r\n"
|
||||
" ║ \r\n"
|
||||
" ║ \r\n"
|
||||
" ║ ");
|
||||
EXPECT_TRUE(component->OnEvent(MousePressed(1, 1)));
|
||||
EXPECT_EQ(position, 1);
|
||||
EXPECT_TRUE(component->OnEvent(MousePressed(2, 1)));
|
||||
EXPECT_EQ(position, 2);
|
||||
EXPECT_TRUE(component->OnEvent(MouseReleased(2, 1)));
|
||||
EXPECT_EQ(position, 2);
|
||||
}
|
||||
|
||||
TEST(ResizableSplit, BasicRight) {
|
||||
int position = 3;
|
||||
auto component =
|
||||
@@ -71,6 +97,31 @@ TEST(ResizableSplit, BasicRight) {
|
||||
EXPECT_EQ(position, 9);
|
||||
}
|
||||
|
||||
TEST(ResizableSplit, BasicRightWithCustomSeparator) {
|
||||
int position = 1;
|
||||
auto component = ResizableSplit({
|
||||
.main = BasicComponent(),
|
||||
.back = BasicComponent(),
|
||||
.direction = Direction::Right,
|
||||
.main_size = &position,
|
||||
.separator_func = [] { return separatorDouble(); },
|
||||
});
|
||||
auto screen = Screen(4, 4);
|
||||
Render(screen, component->Render());
|
||||
EXPECT_EQ(position, 1);
|
||||
EXPECT_EQ(screen.ToString(),
|
||||
" ║ \r\n"
|
||||
" ║ \r\n"
|
||||
" ║ \r\n"
|
||||
" ║ ");
|
||||
EXPECT_TRUE(component->OnEvent(MousePressed(2, 1)));
|
||||
EXPECT_EQ(position, 1);
|
||||
EXPECT_TRUE(component->OnEvent(MousePressed(1, 1)));
|
||||
EXPECT_EQ(position, 2);
|
||||
EXPECT_TRUE(component->OnEvent(MouseReleased(1, 1)));
|
||||
EXPECT_EQ(position, 2);
|
||||
}
|
||||
|
||||
TEST(ResizableSplit, BasicTop) {
|
||||
int position = 3;
|
||||
auto component =
|
||||
@@ -86,6 +137,31 @@ TEST(ResizableSplit, BasicTop) {
|
||||
EXPECT_EQ(position, 10);
|
||||
}
|
||||
|
||||
TEST(ResizableSplit, BasicTopWithCustomSeparator) {
|
||||
int position = 1;
|
||||
auto component = ResizableSplit({
|
||||
.main = BasicComponent(),
|
||||
.back = BasicComponent(),
|
||||
.direction = Direction::Up,
|
||||
.main_size = &position,
|
||||
.separator_func = [] { return separatorDouble(); },
|
||||
});
|
||||
auto screen = Screen(4, 4);
|
||||
Render(screen, component->Render());
|
||||
EXPECT_EQ(position, 1);
|
||||
EXPECT_EQ(screen.ToString(),
|
||||
" \r\n"
|
||||
"════\r\n"
|
||||
" \r\n"
|
||||
" ");
|
||||
EXPECT_TRUE(component->OnEvent(MousePressed(1, 1)));
|
||||
EXPECT_EQ(position, 1);
|
||||
EXPECT_TRUE(component->OnEvent(MousePressed(1, 2)));
|
||||
EXPECT_EQ(position, 2);
|
||||
EXPECT_TRUE(component->OnEvent(MouseReleased(1, 2)));
|
||||
EXPECT_EQ(position, 2);
|
||||
}
|
||||
|
||||
TEST(ResizableSplit, BasicBottom) {
|
||||
int position = 3;
|
||||
auto component =
|
||||
@@ -101,6 +177,31 @@ TEST(ResizableSplit, BasicBottom) {
|
||||
EXPECT_EQ(position, 9);
|
||||
}
|
||||
|
||||
TEST(ResizableSplit, BasicBottomWithCustomSeparator) {
|
||||
int position = 1;
|
||||
auto component = ResizableSplit({
|
||||
.main = BasicComponent(),
|
||||
.back = BasicComponent(),
|
||||
.direction = Direction::Down,
|
||||
.main_size = &position,
|
||||
.separator_func = [] { return separatorDouble(); },
|
||||
});
|
||||
auto screen = Screen(4, 4);
|
||||
Render(screen, component->Render());
|
||||
EXPECT_EQ(position, 1);
|
||||
EXPECT_EQ(screen.ToString(),
|
||||
" \r\n"
|
||||
" \r\n"
|
||||
"════\r\n"
|
||||
" ");
|
||||
EXPECT_TRUE(component->OnEvent(MousePressed(1, 2)));
|
||||
EXPECT_EQ(position, 1);
|
||||
EXPECT_TRUE(component->OnEvent(MousePressed(1, 1)));
|
||||
EXPECT_EQ(position, 2);
|
||||
EXPECT_TRUE(component->OnEvent(MouseReleased(1, 1)));
|
||||
EXPECT_EQ(position, 2);
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||
|
Reference in New Issue
Block a user