Skip to content

Commit

Permalink
Add Changelog.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurSonzogni committed Dec 26, 2024
1 parent d907fe4 commit 1aaf179
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ current (development)
- Feature: Add support for `Input`'s insert mode. Add `InputOption::insert`
option. Added by @mingsheng13.
- Feature: Add `DropdownOption` to configure the dropdown. See #826.
- Feature: Add support for Selection. Thanks @clement-roblot. See #926.
- See `ScreenInteractive::GetSelection()`.
- See `ScreenInteractive::SelectionChange(...)` listener.
- Bugfix/Breaking change: `Mouse transition`:
- Detect when the mouse move, as opposed to being pressed.
The Mouse::Moved motion was added.
Expand All @@ -40,6 +43,13 @@ current (development)
- Feature: Add `hscroll_indicator`. It display an horizontal indicator
reflecting the current scroll position. Proposed by @ibrahimnasson in
[issue 752](https://github.com/ArthurSonzogni/FTXUI/issues/752)
- Feature: Add support for Selection. Thanks @clement-roblot. See #926.
- See `selectionColor` decorator.
- See `selectionBackgroundColor` decorator.
- See `selectionForegroundColor` decorator.
- See `selectionStyle(style)` decorator.
- See `selectionStyleReset` decorator.


### Screen
- Feature: Add `Box::IsEmpty()`.
Expand Down
18 changes: 8 additions & 10 deletions examples/component/selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ using namespace ftxui;

Element LoremIpsum() {
return vbox({
text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do "
"eiusmod tempor incididunt ut labore et dolore magna aliqua."),
text("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris "
"nisi ut aliquip ex ea commodo consequat."),
text("Duis aute irure dolor in reprehenderit in voluptate velit esse "
"cillum dolore eu fugiat nulla pariatur."),
text("FTXUI: A powerful library for building user interfaces."),
text("Enjoy a rich set of components and a declarative style."),
text("Create beautiful and responsive UIs with minimal effort."),
text("Join the community and experience the power of FTXUI."),
});
}

Expand All @@ -31,9 +29,9 @@ int main() {

int selection_change_counter = 0;
std::string selection_content = "";
screen.SelectionOnChange([&] {
screen.SelectionChange([&] {
selection_change_counter++;
selection_content = screen.SelectionAsString();
selection_content = screen.GetSelection();
});

// The components:
Expand All @@ -42,7 +40,7 @@ int main() {
text("Select changed: " + std::to_string(selection_change_counter) +
" times"),
text("Currently selected: "),
paragraph(selection_content) | frame | border | xflex |
paragraph(selection_content) | vscroll_indicator | frame | border |
size(HEIGHT, EQUAL, 10),
window(text("Horizontal split"), hbox({
LoremIpsum(),
Expand All @@ -58,7 +56,7 @@ int main() {
separator(),
LoremIpsum(),
})),
window(text("Grid split"),
window(text("Grid split with different style"),
vbox({
hbox({
LoremIpsum(),
Expand Down
4 changes: 2 additions & 2 deletions include/ftxui/component/screen_interactive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class ScreenInteractive : public Screen {
void ForceHandleCtrlZ(bool force);

// Selection API.
std::string SelectionAsString();
void SelectionOnChange(std::function<void()> callback);
std::string GetSelection();
void SelectionChange(std::function<void()> callback);

private:
void ExitNow();
Expand Down
4 changes: 2 additions & 2 deletions src/ftxui/component/screen_interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,14 @@ void ScreenInteractive::ForceHandleCtrlZ(bool force) {
}

/// @brief Returns the content of the current selection
std::string ScreenInteractive::SelectionAsString() {
std::string ScreenInteractive::GetSelection() {
if (!selection_) {
return "";
}
return selection_->GetParts();
}

void ScreenInteractive::SelectionOnChange(std::function<void()> callback) {
void ScreenInteractive::SelectionChange(std::function<void()> callback) {
selection_on_change_ = std::move(callback);
}

Expand Down
14 changes: 7 additions & 7 deletions src/ftxui/dom/selection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ Event MouseMove(int x, int y) {
TEST(SelectionTest, DefaultSelection) {
auto component = Renderer([&] { return text("Lorem ipsum dolor"); });
auto screen = ScreenInteractive::FixedSize(20, 1);
EXPECT_EQ(screen.SelectionAsString(), "");
EXPECT_EQ(screen.GetSelection(), "");
Loop loop(&screen, component);
screen.PostEvent(MousePressed(3, 1));
screen.PostEvent(MouseReleased(10, 1));
loop.RunOnce();

EXPECT_EQ(screen.SelectionAsString(), "rem ipsu");
EXPECT_EQ(screen.GetSelection(), "rem ipsu");
}

TEST(SelectionTest, SelectionOnChange) {
TEST(SelectionTest, SelectionChange) {
int selectionChangeCounter = 0;
auto component = Renderer([&] { return text("Lorem ipsum dolor"); });
auto screen = ScreenInteractive::FixedSize(20, 1);
screen.SelectionOnChange([&] { selectionChangeCounter++; });
screen.SelectionChange([&] { selectionChangeCounter++; });

Loop loop(&screen, component);
loop.RunOnce();
Expand All @@ -97,7 +97,7 @@ TEST(SelectionTest, SelectionOnChange) {
loop.RunOnce();
EXPECT_EQ(selectionChangeCounter, 3);

EXPECT_EQ(screen.SelectionAsString(), "rem ipsu");
EXPECT_EQ(screen.GetSelection(), "rem ipsu");
}

// Check that submitting multiple mouse events quickly doesn't trigger multiple
Expand All @@ -106,7 +106,7 @@ TEST(SelectionTest, SelectionOnChangeSquashedEvents) {
int selectionChangeCounter = 0;
auto component = Renderer([&] { return text("Lorem ipsum dolor"); });
auto screen = ScreenInteractive::FixedSize(20, 1);
screen.SelectionOnChange([&] { selectionChangeCounter++; });
screen.SelectionChange([&] { selectionChangeCounter++; });

Loop loop(&screen, component);
loop.RunOnce();
Expand All @@ -123,7 +123,7 @@ TEST(SelectionTest, SelectionOnChangeSquashedEvents) {
loop.RunOnce();
EXPECT_EQ(selectionChangeCounter, 2);

EXPECT_EQ(screen.SelectionAsString(), "rem ipsu");
EXPECT_EQ(screen.GetSelection(), "rem ipsu");
}

TEST(SelectionTest, StyleSelection) {
Expand Down

0 comments on commit 1aaf179

Please sign in to comment.