mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-18 17:18:08 +08:00
Replace std::clamp with util::clamp and reformat the code (#321)
* Replace std::clamp with util::clamp * Apply clang-format * Execute ./tools/iwyu.sh Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/terminal_input_parser.hpp"
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include <stddef.h> // for size_t
|
||||
#include <algorithm> // for clamp, max, min
|
||||
#include <algorithm> // for max, min
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr, allocator
|
||||
#include <string> // for string, wstring
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, text, Element, reflect, inverted, Decorator, flex, focus, hbox, size, bold, dim, frame, select, EQUAL, HEIGHT
|
||||
#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
|
||||
|
||||
namespace ftxui {
|
||||
@@ -189,7 +190,7 @@ class InputBase : public ComponentBase {
|
||||
|
||||
auto mapping = CellToGlyphIndex(*content_);
|
||||
int original_glyph = cursor_position();
|
||||
original_glyph = std::clamp(original_glyph, 0, int(mapping.size()));
|
||||
original_glyph = util::clamp(original_glyph, 0, int(mapping.size()));
|
||||
int original_cell = 0;
|
||||
for (size_t i = 0; i < mapping.size(); i++) {
|
||||
if (mapping[i] == original_glyph) {
|
||||
@@ -202,7 +203,7 @@ class InputBase : public ComponentBase {
|
||||
int target_cell = original_cell + event.mouse().x - cursor_box_.x_min;
|
||||
int target_glyph = target_cell < (int)mapping.size() ? mapping[target_cell]
|
||||
: (int)mapping.size();
|
||||
target_glyph = std::clamp(target_glyph, 0, GlyphCount(*content_));
|
||||
target_glyph = util::clamp(target_glyph, 0, GlyphCount(*content_));
|
||||
if (cursor_position() != target_glyph) {
|
||||
cursor_position() = target_glyph;
|
||||
option_->on_change();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <algorithm> // for clamp, max
|
||||
#include <algorithm> // for max
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr, allocator_traits<>::value_type
|
||||
#include <string> // for operator+, string
|
||||
@@ -13,9 +13,9 @@
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Released, Mouse::WheelDown, Mouse::WheelUp, Mouse::None
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, reflect, text, nothing, select, vbox, Elements, focus
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/screen/util.hpp"
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef, ConstStringRef
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/screen/util.hpp" // for clamp
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef, ConstStringRef
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <algorithm> // for clamp, max
|
||||
#include <algorithm> // for max
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr, allocator_traits<>::value_type
|
||||
#include <string> // for string
|
||||
@@ -14,8 +14,8 @@
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, reflect, text, Element, hbox, vbox, Elements, focus, nothing, select
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/screen/util.hpp"
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef
|
||||
#include "ftxui/screen/util.hpp" // for clamp
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
|
@@ -277,7 +277,6 @@ CapturedMouse ScreenInteractive::CaptureMouse() {
|
||||
}
|
||||
|
||||
void ScreenInteractive::Loop(Component component) {
|
||||
|
||||
// Suspend previously active screen:
|
||||
if (g_active_screen) {
|
||||
std::swap(suspended_screen_, g_active_screen);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <algorithm> // for clamp, max
|
||||
#include <algorithm> // for max
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr, allocator_traits<>::value_type
|
||||
#include <utility> // for move
|
||||
@@ -12,8 +12,8 @@
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, Elements, hbox, reflect, separator, text, focus, nothing, select
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/screen/util.hpp"
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef
|
||||
#include "ftxui/screen/util.hpp" // for clamp
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
|
@@ -41,10 +41,10 @@ Table::Table() {
|
||||
|
||||
Table::Table(std::vector<std::vector<std::string>> input) {
|
||||
std::vector<std::vector<Element>> output;
|
||||
for(auto& row : input) {
|
||||
for (auto& row : input) {
|
||||
output.push_back({});
|
||||
auto& output_row = output.back();
|
||||
for(auto& cell : row) {
|
||||
for (auto& cell : row) {
|
||||
output_row.push_back(text(cell));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user