mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-10-31 18:48:11 +08:00 
			
		
		
		
	Cleanup. (IWYU, clang-tidy, etc...)
This commit is contained in:
		| @@ -88,8 +88,6 @@ class ConstStringRef : public ConstRef<std::string> { | |||||||
|   ConstStringRef(const wchar_t* ref) |   ConstStringRef(const wchar_t* ref) | ||||||
|       : ConstStringRef(to_string(std::wstring(ref))) {} |       : ConstStringRef(to_string(std::wstring(ref))) {} | ||||||
|   ConstStringRef(const char* ref) : ConstStringRef(std::string(ref)) {} |   ConstStringRef(const char* ref) : ConstStringRef(std::string(ref)) {} | ||||||
|  |  | ||||||
|   ConstStringRef& operator=(const ConstStringRef&) = default; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| /// @brief An adapter. Reference a list of strings. | /// @brief An adapter. Reference a list of strings. | ||||||
| @@ -98,6 +96,8 @@ class ConstStringListRef { | |||||||
|   ConstStringListRef() = default; |   ConstStringListRef() = default; | ||||||
|   ConstStringListRef(const std::vector<std::string>* ref) : ref_(ref) {} |   ConstStringListRef(const std::vector<std::string>* ref) : ref_(ref) {} | ||||||
|   ConstStringListRef(const std::vector<std::wstring>* ref) : ref_wide_(ref) {} |   ConstStringListRef(const std::vector<std::wstring>* ref) : ref_wide_(ref) {} | ||||||
|  |   ConstStringListRef(const ConstStringListRef& other) = default; | ||||||
|  |   ConstStringListRef& operator=(const ConstStringListRef& other) = default; | ||||||
|  |  | ||||||
|   size_t size() const { |   size_t size() const { | ||||||
|     if (ref_) { |     if (ref_) { | ||||||
|   | |||||||
| @@ -95,7 +95,7 @@ MenuEntryOption GeneratorMenuEntryOption(const char* data, size_t size) { | |||||||
| MenuOption GeneratorMenuOption(const char* data, size_t size) { | MenuOption GeneratorMenuOption(const char* data, size_t size) { | ||||||
|   MenuOption option; |   MenuOption option; | ||||||
|   option.underline = GeneratorUnderlineOption(data, size); |   option.underline = GeneratorUnderlineOption(data, size); | ||||||
|   option.entries = GeneratorMenuEntryOption(data, size); |   option.entries_option = GeneratorMenuEntryOption(data, size); | ||||||
|   option.direction = static_cast<Direction>(GeneratorInt(data, size) % 4); |   option.direction = static_cast<Direction>(GeneratorInt(data, size) % 4); | ||||||
|   return option; |   return option; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -205,7 +205,8 @@ class SliderBase : public ComponentBase { | |||||||
|  |  | ||||||
| class SliderWithLabel : public ComponentBase { | class SliderWithLabel : public ComponentBase { | ||||||
|  public: |  public: | ||||||
|   SliderWithLabel(ConstStringRef label, Component inner) : label_(label) { |   SliderWithLabel(ConstStringRef label, Component inner) | ||||||
|  |       : label_(std::move(label)) { | ||||||
|     Add(std::move(inner)); |     Add(std::move(inner)); | ||||||
|     SetActiveChild(ChildAt(0)); |     SetActiveChild(ChildAt(0)); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ namespace ftxui { | |||||||
| namespace { | namespace { | ||||||
|  |  | ||||||
| struct LinearGradientNormalized { | struct LinearGradientNormalized { | ||||||
|   float angle = 0.f; |   float angle = 0.F; | ||||||
|   std::vector<Color> colors; |   std::vector<Color> colors; | ||||||
|   std::vector<float> positions;  // Sorted. |   std::vector<float> positions;  // Sorted. | ||||||
| }; | }; | ||||||
| @@ -27,15 +27,18 @@ LinearGradientNormalized Normalize(LinearGradient gradient) { | |||||||
|   // Handle gradient of size 0. |   // Handle gradient of size 0. | ||||||
|   if (gradient.stops.empty()) { |   if (gradient.stops.empty()) { | ||||||
|     return LinearGradientNormalized{ |     return LinearGradientNormalized{ | ||||||
|         0.f, {Color::Default, Color::Default}, {0.f, 1.f}}; |         0.F, | ||||||
|  |         {Color::Default, Color::Default}, | ||||||
|  |         {0.F, 1.F}, | ||||||
|  |     }; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Fill in the two extent, if not provided. |   // Fill in the two extent, if not provided. | ||||||
|   if (!gradient.stops.front().position) { |   if (!gradient.stops.front().position) { | ||||||
|     gradient.stops.front().position = 0.f; |     gradient.stops.front().position = 0.F; | ||||||
|   } |   } | ||||||
|   if (!gradient.stops.back().position) { |   if (!gradient.stops.back().position) { | ||||||
|     gradient.stops.back().position = 1.f; |     gradient.stops.back().position = 1.F; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Fill in the blank, by interpolating positions. |   // Fill in the blank, by interpolating positions. | ||||||
| @@ -67,20 +70,22 @@ LinearGradientNormalized Normalize(LinearGradient gradient) { | |||||||
|   // If we don't being with zero, add a stop at zero. |   // If we don't being with zero, add a stop at zero. | ||||||
|   if (gradient.stops.front().position != 0) { |   if (gradient.stops.front().position != 0) { | ||||||
|     gradient.stops.insert(gradient.stops.begin(), |     gradient.stops.insert(gradient.stops.begin(), | ||||||
|                           {gradient.stops.front().color, 0.f}); |                           {gradient.stops.front().color, 0.F}); | ||||||
|   } |   } | ||||||
|   // If we don't end with one, add a stop at one. |   // If we don't end with one, add a stop at one. | ||||||
|   if (gradient.stops.back().position != 1) { |   if (gradient.stops.back().position != 1) { | ||||||
|     gradient.stops.push_back({gradient.stops.back().color, 1.f}); |     gradient.stops.push_back({gradient.stops.back().color, 1.F}); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Normalize the angle. |   // Normalize the angle. | ||||||
|   LinearGradientNormalized normalized; |   LinearGradientNormalized normalized; | ||||||
|   // NOLINTNEXTLINE |   const float modulo = 360.F; | ||||||
|   normalized.angle = std::fmod(std::fmod(gradient.angle, 360.f) + 360.f, 360.f); |   normalized.angle = | ||||||
|   for (const auto& stop : gradient.stops) { |       std::fmod(std::fmod(gradient.angle, modulo) + modulo, modulo); | ||||||
|  |   for (auto& stop : gradient.stops) { | ||||||
|     normalized.colors.push_back(stop.color); |     normalized.colors.push_back(stop.color); | ||||||
|     normalized.positions.push_back(stop.position.value());  // NOLINT |     // NOLINTNEXTLINE | ||||||
|  |     normalized.positions.push_back(stop.position.value()); | ||||||
|   } |   } | ||||||
|   return normalized; |   return normalized; | ||||||
| } | } | ||||||
| @@ -90,8 +95,8 @@ Color Interpolate(const LinearGradientNormalized& gradient, float t) { | |||||||
|   size_t i = 1; |   size_t i = 1; | ||||||
|   while (true) { |   while (true) { | ||||||
|     if (i > gradient.positions.size()) { |     if (i > gradient.positions.size()) { | ||||||
|       // NOLINTNEXTLINE |       const float half = 0.5F; | ||||||
|       return Color::Interpolate(0.5f, gradient.colors.back(), |       return Color::Interpolate(half, gradient.colors.back(), | ||||||
|                                 gradient.colors.back()); |                                 gradient.colors.back()); | ||||||
|     } |     } | ||||||
|     if (t <= gradient.positions[i]) { |     if (t <= gradient.positions[i]) { | ||||||
| @@ -122,7 +127,7 @@ class LinearGradientColor : public NodeDecorator { | |||||||
|  |  | ||||||
|  private: |  private: | ||||||
|   void Render(Screen& screen) override { |   void Render(Screen& screen) override { | ||||||
|     const float degtorad = 0.01745329251f; |     const float degtorad = 0.01745329251F; | ||||||
|     const float dx = std::cos(gradient_.angle * degtorad); |     const float dx = std::cos(gradient_.angle * degtorad); | ||||||
|     const float dy = std::sin(gradient_.angle * degtorad); |     const float dy = std::sin(gradient_.angle * degtorad); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -224,11 +224,17 @@ Color Color::Interpolate(float t, const Color& a, const Color& b) { | |||||||
|  |  | ||||||
|   // Gamma correction: |   // Gamma correction: | ||||||
|   // https://en.wikipedia.org/wiki/Gamma_correction |   // https://en.wikipedia.org/wiki/Gamma_correction | ||||||
|   constexpr float gamma = 2.2f; |   auto interp = [](uint8_t a, uint8_t b, float t) { | ||||||
|   return Color::RGB( |     constexpr float gamma = 2.2F; | ||||||
|       uint8_t(pow(pow(a_r, gamma) * (1 - t) + pow(b_r, gamma) * t, 1 / gamma)), |     const float a_f = powf(a, gamma); | ||||||
|       uint8_t(pow(pow(a_g, gamma) * (1 - t) + pow(b_g, gamma) * t, 1 / gamma)), |     const float b_f = powf(b, gamma); | ||||||
|       uint8_t(pow(pow(a_b, gamma) * (1 - t) + pow(b_b, gamma) * t, 1 / gamma))); |     const float c_f = a_f * (1.0F - t) +  // | ||||||
|  |                       b_f * t; | ||||||
|  |     return static_cast<uint8_t>(powf(c_f, 1.F / gamma)); | ||||||
|  |   }; | ||||||
|  |   return Color::RGB(interp(a_r, b_r, t),   // | ||||||
|  |                     interp(a_g, b_g, t),   // | ||||||
|  |                     interp(a_b, b_b, t));  // | ||||||
| } | } | ||||||
|  |  | ||||||
| inline namespace literals { | inline namespace literals { | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user
	 ArthurSonzogni
					ArthurSonzogni