Add coverage and remove deprecated WideInput.

This commit is contained in:
ArthurSonzogni
2022-04-27 11:33:42 +02:00
parent 5ba301d316
commit 114cbfcffd
7 changed files with 61 additions and 99 deletions

View File

@@ -0,0 +1,56 @@
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult
#include <memory> // for shared_ptr, __shared_ptr_access, allocator, make_shared
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Make
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
#include "gtest/gtest_pred_impl.h" // for EXPECT_EQ, Test, SuiteApiResolver, TEST, TestFactoryImpl
namespace ftxui {
TEST(AnimationTest, StartAndEnd) {
std::vector<animation::easing::Function> functions = {
animation::easing::Linear,
animation::easing::QuadraticIn,
animation::easing::QuadraticOut,
animation::easing::QuadraticInOut,
animation::easing::CubicIn,
animation::easing::CubicOut,
animation::easing::CubicInOut,
animation::easing::QuarticIn,
animation::easing::QuarticOut,
animation::easing::QuarticInOut,
animation::easing::QuinticIn,
animation::easing::QuinticOut,
animation::easing::QuinticInOut,
animation::easing::SineIn,
animation::easing::SineOut,
animation::easing::SineInOut,
animation::easing::CircularIn,
animation::easing::CircularOut,
animation::easing::CircularInOut,
animation::easing::ExponentialIn,
animation::easing::ExponentialOut,
animation::easing::ExponentialInOut,
animation::easing::ElasticIn,
animation::easing::ElasticOut,
animation::easing::ElasticInOut,
animation::easing::BackIn,
animation::easing::BackOut,
animation::easing::BackInOut,
animation::easing::BounceIn,
animation::easing::BounceOut,
animation::easing::BounceInOut,
};
for (auto& it : functions) {
EXPECT_NEAR(0.f, it(0.f), 1.0e-4);
EXPECT_NEAR(1.f, it(1.f), 1.0e-4);
}
}
} // namespace ftxui
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.

View File

@@ -10,7 +10,6 @@
#include "ftxui/component/component.hpp" // for Make, Input
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for InputOption
#include "ftxui/component/deprecated.hpp" // for Input
#include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Backspace, Event::Custom, Event::Delete, Event::End, Event::Home, Event::Return
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed
#include "ftxui/component/screen_interactive.hpp" // for Component
@@ -18,7 +17,7 @@
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/string.hpp" // for GlyphPosition, GlyphCount, to_string, CellToGlyphIndex, to_wstring
#include "ftxui/screen/util.hpp" // for clamp
#include "ftxui/util/ref.hpp" // for StringRef, Ref, WideStringRef, ConstStringRef
#include "ftxui/util/ref.hpp" // for StringRef, Ref, ConstStringRef
namespace ftxui {
@@ -236,36 +235,6 @@ class InputBase : public ComponentBase {
Ref<InputOption> option_;
};
// An input box. The user can type text into it.
// For convenience, the std::wstring version of Input simply wrap a
// InputBase.
class WideInputBase : public InputBase {
public:
WideInputBase(WideStringRef content,
ConstStringRef placeholder,
Ref<InputOption> option)
: InputBase(&wrapped_content_, std::move(placeholder), std::move(option)),
content_(std::move(content)),
wrapped_content_(to_string(*content_)) {}
Element Render() override {
wrapped_content_ = to_string(*content_);
return InputBase::Render();
}
bool OnEvent(Event event) override {
wrapped_content_ = to_string(*content_);
if (InputBase::OnEvent(event)) {
*content_ = to_wstring(wrapped_content_);
return true;
}
return false;
}
WideStringRef content_;
std::string wrapped_content_;
};
} // namespace
/// @brief An input box for editing text.
@@ -297,35 +266,6 @@ Component Input(StringRef content,
std::move(option));
}
/// @brief . An input box for editing text.
/// @param content The editable content.
/// @param placeholder The text displayed when content is still empty.
/// @param option Additional optional parameters.
/// @ingroup component
/// @see InputBase
///
/// ### Example
///
/// ```cpp
/// auto screen = ScreenInteractive::FitComponent();
/// std::string content= "";
/// std::string placeholder = "placeholder";
/// Component input = Input(&content, &placeholder);
/// screen.Loop(input);
/// ```
///
/// ### Output
///
/// ```bash
/// placeholder
/// ```
Component Input(WideStringRef content,
ConstStringRef placeholder,
Ref<InputOption> option) {
return Make<WideInputBase>(std::move(content), std::move(placeholder),
std::move(option));
}
} // namespace ftxui
// Copyright 2020 Arthur Sonzogni. All rights reserved.