mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-11-04 13:38:14 +08:00 
			
		
		
		
	execute IWYU and add some coverage tests.
This commit is contained in:
		@@ -197,13 +197,13 @@ float ElasticOut(float p) {
 | 
			
		||||
// y = (1/2)*sin(13pi/2*(2*x))*pow(2, 10 * ((2*x) - 1))      ; [0,0.5)
 | 
			
		||||
// y = (1/2)*(sin(-13pi/2*((2x-1)+1))*pow(2,-10(2*x-1)) + 2) ; [0.5, 1]
 | 
			
		||||
float ElasticInOut(float p) {
 | 
			
		||||
  if (p < 0.5F) {                                             // NOLINT
 | 
			
		||||
  if (p < 0.5F) {                                               // NOLINT
 | 
			
		||||
    return 0.5 * std::sin(13.F * kPi2 * (2 * p)) *              // NOLINT
 | 
			
		||||
           std::pow(2, 10 * ((2 * p) - 1));                   // NOLINT
 | 
			
		||||
  } else {                                                    // NOLINT
 | 
			
		||||
           std::pow(2, 10 * ((2 * p) - 1));                     // NOLINT
 | 
			
		||||
  } else {                                                      // NOLINT
 | 
			
		||||
    return 0.5 * (std::sin(-13.F * kPi2 * ((2 * p - 1) + 1)) *  // NOLINT
 | 
			
		||||
                      std::pow(2, -10 * (2 * p - 1)) +        // NOLINT
 | 
			
		||||
                  2);                                         // NOLINT
 | 
			
		||||
                      std::pow(2, -10 * (2 * p - 1)) +          // NOLINT
 | 
			
		||||
                  2);                                           // NOLINT
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,37 +11,22 @@ 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,
 | 
			
		||||
      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);
 | 
			
		||||
 
 | 
			
		||||
@@ -17,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, ConstStringRef
 | 
			
		||||
#include "ftxui/util/ref.hpp"     // for StringRef, Ref, ConstStringRef
 | 
			
		||||
 | 
			
		||||
namespace ftxui {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -115,9 +115,8 @@ class MenuBase : public ComponentBase {
 | 
			
		||||
      bool is_focused = (focused_entry() == i) && is_menu_focused;
 | 
			
		||||
      bool is_selected = (*selected_ == i);
 | 
			
		||||
 | 
			
		||||
      auto focus_management = !is_selected      ? nothing
 | 
			
		||||
                              : is_menu_focused ? focus
 | 
			
		||||
                                                : nothing;
 | 
			
		||||
      auto focus_management =
 | 
			
		||||
          !is_selected ? nothing : is_menu_focused ? focus : nothing;
 | 
			
		||||
      EntryState state = {
 | 
			
		||||
          entries_[i],
 | 
			
		||||
          false,
 | 
			
		||||
 
 | 
			
		||||
@@ -43,6 +43,53 @@ TEST(MenuTest, RemoveEntries) {
 | 
			
		||||
  EXPECT_EQ(focused_entry, 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(MenuTest, Directions) {
 | 
			
		||||
  int selected = 0;
 | 
			
		||||
  std::vector<std::string> entries = {"1", "2", "3"};
 | 
			
		||||
  MenuOption option;
 | 
			
		||||
  auto menu = Menu(&entries, &selected, &option);
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    option.direction = MenuOption::Down;
 | 
			
		||||
    Screen screen(4, 3);
 | 
			
		||||
    Render(screen, menu->Render());
 | 
			
		||||
    EXPECT_EQ(screen.ToString(),
 | 
			
		||||
              "\x1B[1m\x1B[7m> 1 \x1B[22m\x1B[27m\r\n"
 | 
			
		||||
              "  2 \r\n"
 | 
			
		||||
              "  3 ");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    option.direction = MenuOption::Up;
 | 
			
		||||
    Screen screen(4, 3);
 | 
			
		||||
    Render(screen, menu->Render());
 | 
			
		||||
    EXPECT_EQ(screen.ToString(),
 | 
			
		||||
              "  3 \r\n"
 | 
			
		||||
              "  2 \r\n"
 | 
			
		||||
              "\x1B[1m\x1B[7m> 1 \x1B[22m\x1B[27m");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    option.direction = MenuOption::Right;
 | 
			
		||||
    Screen screen(10, 1);
 | 
			
		||||
    Render(screen, menu->Render());
 | 
			
		||||
    EXPECT_EQ(screen.ToString(),
 | 
			
		||||
              "\x1B[1m\x1B[7m> 1\x1B[22m\x1B[27m"
 | 
			
		||||
              "  2"
 | 
			
		||||
              "  3 ");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    option.direction = MenuOption::Left;
 | 
			
		||||
    Screen screen(10, 1);
 | 
			
		||||
    Render(screen, menu->Render());
 | 
			
		||||
    EXPECT_EQ(screen.ToString(),
 | 
			
		||||
              "  3"
 | 
			
		||||
              "  2"
 | 
			
		||||
              "\x1B[1m\x1B[7m> 1\x1B[22m\x1B[27m ");
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace ftxui
 | 
			
		||||
 | 
			
		||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
 | 
			
		||||
 
 | 
			
		||||
@@ -39,9 +39,8 @@ class RadioboxBase : public ComponentBase {
 | 
			
		||||
    for (int i = 0; i < size(); ++i) {
 | 
			
		||||
      bool is_focused = (focused_entry() == i) && is_menu_focused;
 | 
			
		||||
      bool is_selected = (hovered_ == i);
 | 
			
		||||
      auto focus_management = !is_selected      ? nothing
 | 
			
		||||
                              : is_menu_focused ? focus
 | 
			
		||||
                                                : select;
 | 
			
		||||
      auto focus_management =
 | 
			
		||||
          !is_selected ? nothing : is_menu_focused ? focus : select;
 | 
			
		||||
      auto state = EntryState{
 | 
			
		||||
          entries_[i],
 | 
			
		||||
          *selected_ == i,
 | 
			
		||||
 
 | 
			
		||||
@@ -310,7 +310,7 @@ TEST(Event, Control) {
 | 
			
		||||
  cases.push_back({char(26), true});
 | 
			
		||||
  cases.push_back({char(127), false});
 | 
			
		||||
 | 
			
		||||
  for(auto test : cases) {
 | 
			
		||||
  for (auto test : cases) {
 | 
			
		||||
    auto event_receiver = MakeReceiver<Task>();
 | 
			
		||||
    {
 | 
			
		||||
      auto parser = TerminalInputParser(event_receiver->MakeSender());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user