mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-29 16:39:34 +08:00
Execute clang tidy and IWYU (#528)
This commit is contained in:

committed by
ArthurSonzogni

parent
4dc1a9fff9
commit
0542227ba7
@@ -58,7 +58,7 @@ float CubicIn(float p) {
|
||||
|
||||
// Modeled after the cubic y = (x - 1)^3 + 1
|
||||
float CubicOut(float p) {
|
||||
float f = (p - 1);
|
||||
const float f = (p - 1);
|
||||
return f * f * f + 1;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ float CubicInOut(float p) {
|
||||
if (p < 0.5F) { // NOLINT
|
||||
return 4 * p * p * p;
|
||||
} else {
|
||||
float f = ((2 * p) - 2);
|
||||
const float f = ((2 * p) - 2);
|
||||
return 0.5F * f * f * f + 1; // NOLINT
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ float QuarticIn(float p) {
|
||||
|
||||
// Modeled after the quartic y = 1 - (x - 1)^4
|
||||
float QuarticOut(float p) {
|
||||
float f = (p - 1);
|
||||
const float f = (p - 1);
|
||||
return f * f * f * (1 - p) + 1;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ float QuarticInOut(float p) {
|
||||
if (p < 0.5F) { // NOLINT
|
||||
return 8 * p * p * p * p; // NOLINT
|
||||
} else {
|
||||
float f = (p - 1);
|
||||
const float f = (p - 1);
|
||||
return -8 * f * f * f * f + 1; // NOLINT
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ float QuinticIn(float p) {
|
||||
|
||||
// Modeled after the quintic y = (x - 1)^5 + 1
|
||||
float QuinticOut(float p) {
|
||||
float f = (p - 1);
|
||||
const float f = (p - 1);
|
||||
return f * f * f * f * f + 1;
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ float BackIn(float p) {
|
||||
|
||||
// Modeled after overshooting cubic y = 1-((1-x)^3-(1-x)*sin((1-x)*pi))
|
||||
float BackOut(float p) {
|
||||
float f = (1 - p);
|
||||
const float f = (1 - p);
|
||||
return 1 - (f * f * f - f * std::sin(f * kPi));
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ float BackOut(float p) {
|
||||
// y = (1/2)*(1-((1-x)^3-(1-x)*sin((1-x)*pi))+1) ; [0.5, 1]
|
||||
float BackInOut(float p) {
|
||||
if (p < 0.5F) { // NOLINT
|
||||
float f = 2 * p;
|
||||
const float f = 2 * p;
|
||||
return 0.5F * (f * f * f - f * std::sin(f * kPi)); // NOLINT
|
||||
} else {
|
||||
float f = (1 - (2 * p - 1)); // NOLINT
|
||||
|
@@ -80,7 +80,7 @@ Component Button(ConstStringRef label,
|
||||
}
|
||||
|
||||
auto focus_management = focused ? focus : active ? select : nothing;
|
||||
EntryState state = {
|
||||
const EntryState state = {
|
||||
*label_,
|
||||
false,
|
||||
active,
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
|
||||
#include <string> // for string
|
||||
#include <gtest/gtest.h> // for AssertionResult, Message, TestPartResult, EXPECT_EQ, Test, EXPECT_FALSE, EXPECT_TRUE, TestInfo (ptr only), TEST
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
|
||||
#include <string> // for string
|
||||
|
||||
#include "ftxui/component/animation.hpp" // for Duration, Params
|
||||
#include "ftxui/component/component.hpp" // for Button, Horizontal
|
||||
|
@@ -1,9 +1,10 @@
|
||||
#include <functional> // for function
|
||||
#include <memory> // for __shared_ptr_access, __shared_ptr_access<>::element_type, shared_ptr
|
||||
#include <utility> // for move
|
||||
#include <type_traits> // for remove_reference, remove_reference<>::type
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Component, Make, CatchEvent
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component.hpp" // for Make, CatchEvent, ComponentDecorator
|
||||
#include "ftxui/component/component_base.hpp" // for Component, ComponentBase
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
|
||||
namespace ftxui {
|
||||
|
@@ -22,8 +22,8 @@ class CheckboxBase : public ComponentBase {
|
||||
private:
|
||||
// Component implementation.
|
||||
Element Render() override {
|
||||
bool is_focused = Focused();
|
||||
bool is_active = Active();
|
||||
const bool is_focused = Focused();
|
||||
const bool is_active = Active();
|
||||
auto focus_management = is_focused ? focus : is_active ? select : nothing;
|
||||
auto state = EntryState{
|
||||
*label_,
|
||||
|
@@ -26,7 +26,7 @@ namespace ftxui {
|
||||
///
|
||||
/// ▼ Show details
|
||||
/// <details component>
|
||||
/// ```
|
||||
/// ```
|
||||
Component Collapsible(ConstStringRef label, Component child, Ref<bool> show) {
|
||||
class Impl : public ComponentBase {
|
||||
public:
|
||||
|
@@ -114,7 +114,7 @@ bool ComponentBase::OnEvent(Event event) { // NOLINT
|
||||
/// The default implementation dispatch the event to every child.
|
||||
/// @ingroup component
|
||||
void ComponentBase::OnAnimation(animation::Params& params) {
|
||||
for (Component& child : children_) {
|
||||
for (const Component& child : children_) {
|
||||
child->OnAnimation(params);
|
||||
}
|
||||
}
|
||||
|
@@ -123,8 +123,8 @@ MenuOption MenuOption::Toggle() {
|
||||
ButtonOption ButtonOption::Ascii() {
|
||||
ButtonOption option;
|
||||
option.transform = [](const EntryState& s) {
|
||||
std::string label = s.focused ? "[" + s.label + "]" //
|
||||
: " " + s.label + " ";
|
||||
const std::string label = s.focused ? "[" + s.label + "]" //
|
||||
: " " + s.label + " ";
|
||||
return text(label);
|
||||
};
|
||||
return option;
|
||||
|
@@ -82,8 +82,8 @@ class ContainerBase : public ComponentBase {
|
||||
return;
|
||||
}
|
||||
for (size_t offset = 1; offset < children_.size(); ++offset) {
|
||||
size_t i = ((size_t(*selector_ + offset * dir + children_.size())) %
|
||||
children_.size());
|
||||
const size_t i = ((size_t(*selector_ + offset * dir + children_.size())) %
|
||||
children_.size());
|
||||
if (children_[i]->Focusable()) {
|
||||
*selector_ = (int)i;
|
||||
return;
|
||||
@@ -108,7 +108,7 @@ class VerticalContainer : public ContainerBase {
|
||||
}
|
||||
|
||||
bool EventHandler(Event event) override {
|
||||
int old_selected = *selector_;
|
||||
const int old_selected = *selector_;
|
||||
if (event == Event::ArrowUp || event == Event::Character('k')) {
|
||||
MoveSelector(-1);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ class HorizontalContainer : public ContainerBase {
|
||||
}
|
||||
|
||||
bool EventHandler(Event event) override {
|
||||
int old_selected = *selector_;
|
||||
const int old_selected = *selector_;
|
||||
if (event == Event::ArrowLeft || event == Event::Character('h')) {
|
||||
MoveSelector(-1);
|
||||
}
|
||||
@@ -214,7 +214,7 @@ class TabContainer : public ContainerBase {
|
||||
using ContainerBase::ContainerBase;
|
||||
|
||||
Element Render() override {
|
||||
Component active_child = ActiveChild();
|
||||
const Component active_child = ActiveChild();
|
||||
if (active_child) {
|
||||
return active_child->Render();
|
||||
}
|
||||
|
@@ -1,15 +1,14 @@
|
||||
#include <memory> // for shared_ptr
|
||||
#include <utility> // for move
|
||||
#include <ftxui/component/captured_mouse.hpp> // for CapturedMouse
|
||||
#include <functional> // for function
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Make, Button
|
||||
#include "ftxui/component/component.hpp" // for ComponentDecorator, Hoverable, Make
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/event.hpp" // for Event, Event::Return
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Decorator, Element, operator|=, bgcolor, color, reflect, text, bold, border, inverted, nothing
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, reflect, Element
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/screen/color.hpp" // for Color
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringRef
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -23,7 +22,7 @@ void Post(std::function<void()> f) {
|
||||
f();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
/// @brief Wrap a component. Gives the ability to know if it is hovered by the
|
||||
/// mouse.
|
||||
@@ -38,11 +37,12 @@ void Post(std::function<void()> f) {
|
||||
/// bool hover = false;
|
||||
/// auto button_hover = Hoverable(button, &hover);
|
||||
/// ```
|
||||
// NOLINTNEXTLINE
|
||||
Component Hoverable(Component component, bool* hover) {
|
||||
class Impl : public ComponentBase {
|
||||
public:
|
||||
Impl(Component component, bool* hover)
|
||||
: component_(component), hover_(hover) {
|
||||
: component_(std::move(component)), hover_(hover) {
|
||||
Add(component_);
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ Component Hoverable(Component component,
|
||||
|
||||
bool OnEvent(Event event) override {
|
||||
if (event.is_mouse()) {
|
||||
bool hover = box_.Contain(event.mouse().x, event.mouse().y) &&
|
||||
CaptureMouse(event);
|
||||
const bool hover = box_.Contain(event.mouse().x, event.mouse().y) &&
|
||||
CaptureMouse(event);
|
||||
if (hover != hover_) {
|
||||
Post(hover ? on_enter_ : on_leave_);
|
||||
}
|
||||
@@ -120,7 +120,8 @@ Component Hoverable(Component component,
|
||||
std::function<void()> on_leave_;
|
||||
};
|
||||
|
||||
return Make<Impl>(component, on_enter, on_leave);
|
||||
return Make<Impl>(std::move(component), std::move(on_enter),
|
||||
std::move(on_leave));
|
||||
}
|
||||
|
||||
/// @brief Wrap a component. Gives the ability to know if it is hovered by the
|
||||
@@ -136,7 +137,9 @@ Component Hoverable(Component component,
|
||||
/// button |= Hoverable(&hover);
|
||||
/// ```
|
||||
ComponentDecorator Hoverable(bool* hover) {
|
||||
return [hover](Component component) { return Hoverable(component, hover); };
|
||||
return [hover](Component component) {
|
||||
return Hoverable(std::move(component), hover);
|
||||
};
|
||||
}
|
||||
|
||||
/// @brief Wrap a component. Gives the ability to know if it is hovered by the
|
||||
@@ -152,14 +155,16 @@ ComponentDecorator Hoverable(bool* hover) {
|
||||
/// int on_enter_cnt = 0;
|
||||
/// int on_leave_cnt = 0;
|
||||
/// button |= Hoverable(
|
||||
/// [&]{ on_enter_cnt++; },
|
||||
/// [&]{ on_enter_cnt++; },
|
||||
/// [&]{ on_leave_cnt++; }
|
||||
// );
|
||||
/// ```
|
||||
// NOLINTNEXTLINE
|
||||
ComponentDecorator Hoverable(std::function<void()> on_enter,
|
||||
// NOLINTNEXTLINE
|
||||
std::function<void()> on_leave) {
|
||||
return [on_enter, on_leave](Component component) {
|
||||
return Hoverable(component, on_enter, on_leave);
|
||||
return Hoverable(std::move(component), on_enter, on_leave);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -177,9 +182,10 @@ ComponentDecorator Hoverable(std::function<void()> on_enter,
|
||||
/// auto button_hoverable = Hoverable(button,
|
||||
// [&](bool hover) { hovered = hover;});
|
||||
/// ```
|
||||
// NOLINTNEXTLINE
|
||||
Component Hoverable(Component component, std::function<void(bool)> on_change) {
|
||||
return Hoverable(
|
||||
component, //
|
||||
std::move(component), //
|
||||
[on_change] { on_change(true); }, //
|
||||
[on_change] { on_change(false); } //
|
||||
);
|
||||
@@ -197,9 +203,10 @@ Component Hoverable(Component component, std::function<void(bool)> on_change) {
|
||||
/// bool hovered = false;
|
||||
/// button |= Hoverable([&](bool hover) { hovered = hover;});
|
||||
/// ```
|
||||
// NOLINTNEXTLINE
|
||||
ComponentDecorator Hoverable(std::function<void(bool)> on_change) {
|
||||
return [on_change](Component component) {
|
||||
return Hoverable(component, on_change);
|
||||
return Hoverable(std::move(component), on_change);
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,13 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
|
||||
#include <string> // for string
|
||||
#include <gtest/gtest.h> // for AssertionResult, Message, TestPartResult, EXPECT_FALSE, EXPECT_EQ, Test, EXPECT_TRUE, TestInfo (ptr only), TEST
|
||||
#include <ftxui/dom/elements.hpp> // for Element, text
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access, allocator
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Input
|
||||
#include "ftxui/component/component.hpp" // for Hoverable, Horizontal, operator|=, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
|
||||
#include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Backspace, Event::Delete, Event::End, Event::Home
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Button, Mouse::Left, Mouse::Motion, Mouse::Pressed
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Released
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include <algorithm> // for max, min
|
||||
#include <cstddef> // for size_t
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string, allocator
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector
|
||||
@@ -9,14 +10,14 @@
|
||||
#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/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Backspace, Event::Custom, Event::Delete, Event::End, Event::Home, Event::Return
|
||||
#include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowLeftCtrl, Event::ArrowRight, Event::ArrowRightCtrl, 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
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, text, Element, reflect, inverted, Decorator, flex, focus, hbox, size, bold, dim, frame, select, EQUAL, HEIGHT
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, text, Element, reflect, operator|=, flex, inverted, hbox, size, bold, dim, focus, focusCursorBarBlinking, frame, select, Decorator, EQUAL, HEIGHT
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/screen/string.hpp" // for GlyphPosition, GlyphCount, CellToGlyphIndex
|
||||
#include "ftxui/screen/util.hpp" // for clamp
|
||||
#include "ftxui/util/ref.hpp" // for StringRef, Ref, ConstStringRef
|
||||
#include "ftxui/screen/string.hpp" // for GlyphPosition, WordBreakProperty, GlyphCount, Utf8ToWordBreakProperty, CellToGlyphIndex, WordBreakProperty::ALetter, WordBreakProperty::CR, WordBreakProperty::Double_Quote, WordBreakProperty::Extend, WordBreakProperty::ExtendNumLet, WordBreakProperty::Format, WordBreakProperty::Hebrew_Letter, WordBreakProperty::Katakana, WordBreakProperty::LF, WordBreakProperty::MidLetter, WordBreakProperty::MidNum, WordBreakProperty::MidNumLet, WordBreakProperty::Newline, WordBreakProperty::Numeric, WordBreakProperty::Regional_Indicator, WordBreakProperty::Single_Quote, WordBreakProperty::WSegSpace, WordBreakProperty::ZWJ
|
||||
#include "ftxui/screen/util.hpp" // for clamp
|
||||
#include "ftxui/util/ref.hpp" // for StringRef, Ref, ConstStringRef
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -49,7 +50,7 @@ bool IsWordCharacter(WordBreakProperty property) {
|
||||
case WordBreakProperty::ZWJ:
|
||||
return false;
|
||||
}
|
||||
return true; // NOT_REACHED();
|
||||
return true; // NOT_REACHED();
|
||||
}
|
||||
|
||||
std::string PasswordField(size_t size) {
|
||||
@@ -86,13 +87,14 @@ class InputBase : public ComponentBase {
|
||||
if (option_->password()) {
|
||||
password_content = PasswordField(content_->size());
|
||||
}
|
||||
std::string& content = option_->password() ? password_content : *content_;
|
||||
const std::string& content =
|
||||
option_->password() ? password_content : *content_;
|
||||
|
||||
int size = GlyphCount(content);
|
||||
const int size = GlyphCount(content);
|
||||
|
||||
cursor_position() = std::max(0, std::min<int>(size, cursor_position()));
|
||||
auto main_decorator = flex | ftxui::size(HEIGHT, EQUAL, 1);
|
||||
bool is_focused = Focused();
|
||||
const bool is_focused = Focused();
|
||||
|
||||
// placeholder.
|
||||
if (size == 0) {
|
||||
@@ -100,7 +102,7 @@ class InputBase : public ComponentBase {
|
||||
if (is_focused) {
|
||||
element |= focus;
|
||||
}
|
||||
if (hovered_|| is_focused) {
|
||||
if (hovered_ || is_focused) {
|
||||
element |= inverted;
|
||||
}
|
||||
return element;
|
||||
@@ -111,19 +113,21 @@ class InputBase : public ComponentBase {
|
||||
auto element = text(content) | main_decorator | reflect(box_);
|
||||
if (hovered_) {
|
||||
element |= inverted;
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
int index_before_cursor = GlyphPosition(content, cursor_position());
|
||||
int index_after_cursor = GlyphPosition(content, 1, index_before_cursor);
|
||||
std::string part_before_cursor = content.substr(0, index_before_cursor);
|
||||
const int index_before_cursor = GlyphPosition(content, cursor_position());
|
||||
const int index_after_cursor =
|
||||
GlyphPosition(content, 1, index_before_cursor);
|
||||
const std::string part_before_cursor =
|
||||
content.substr(0, index_before_cursor);
|
||||
std::string part_at_cursor = " ";
|
||||
if (cursor_position() < size) {
|
||||
part_at_cursor = content.substr(index_before_cursor,
|
||||
index_after_cursor - index_before_cursor);
|
||||
}
|
||||
std::string part_after_cursor = content.substr(index_after_cursor);
|
||||
const std::string part_after_cursor = content.substr(index_after_cursor);
|
||||
auto focused = (is_focused || hovered_) ? focusCursorBarBlinking : select;
|
||||
return hbox({
|
||||
text(part_before_cursor),
|
||||
@@ -140,15 +144,14 @@ class InputBase : public ComponentBase {
|
||||
if (event.is_mouse()) {
|
||||
return OnMouseEvent(event);
|
||||
}
|
||||
std::string c;
|
||||
|
||||
// Backspace.
|
||||
if (event == Event::Backspace) {
|
||||
if (cursor_position() == 0) {
|
||||
return false;
|
||||
}
|
||||
size_t start = GlyphPosition(*content_, cursor_position() - 1);
|
||||
size_t end = GlyphPosition(*content_, cursor_position());
|
||||
const size_t start = GlyphPosition(*content_, cursor_position() - 1);
|
||||
const size_t end = GlyphPosition(*content_, cursor_position());
|
||||
content_->erase(start, end - start);
|
||||
cursor_position()--;
|
||||
option_->on_change();
|
||||
@@ -160,8 +163,8 @@ class InputBase : public ComponentBase {
|
||||
if (cursor_position() == int(content_->size())) {
|
||||
return false;
|
||||
}
|
||||
size_t start = GlyphPosition(*content_, cursor_position());
|
||||
size_t end = GlyphPosition(*content_, cursor_position() + 1);
|
||||
const size_t start = GlyphPosition(*content_, cursor_position());
|
||||
const size_t end = GlyphPosition(*content_, cursor_position() + 1);
|
||||
content_->erase(start, end - start);
|
||||
option_->on_change();
|
||||
return true;
|
||||
@@ -211,7 +214,7 @@ class InputBase : public ComponentBase {
|
||||
|
||||
// Content
|
||||
if (event.is_character()) {
|
||||
size_t start = GlyphPosition(*content_, cursor_position());
|
||||
const size_t start = GlyphPosition(*content_, cursor_position());
|
||||
content_->insert(start, event.character());
|
||||
cursor_position()++;
|
||||
option_->on_change();
|
||||
@@ -239,7 +242,7 @@ class InputBase : public ComponentBase {
|
||||
|
||||
void HandleRightCtrl() {
|
||||
auto properties = Utf8ToWordBreakProperty(*content_);
|
||||
int max = (int)properties.size();
|
||||
const int max = (int)properties.size();
|
||||
|
||||
// Move right, as long as right is not a word character.
|
||||
while (cursor_position() < max &&
|
||||
@@ -284,7 +287,8 @@ class InputBase : public ComponentBase {
|
||||
if (mapping[original_cell] != original_glyph) {
|
||||
original_cell = mapping.size();
|
||||
}
|
||||
int target_cell = int(original_cell) + event.mouse().x - cursor_box_.x_min;
|
||||
const int target_cell =
|
||||
int(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 = util::clamp(target_glyph, 0, GlyphCount(*content_));
|
||||
|
@@ -1,5 +1,8 @@
|
||||
#include "ftxui/component/loop.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include <functional> // for function
|
||||
#include <memory> // for make_unique, __shared_ptr_access, __shared_ptr_access<>::element_type, shared_ptr
|
||||
#include <utility> // for move
|
||||
#include <type_traits> // for remove_reference, remove_reference<>::type
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/component/component.hpp" // for ComponentDecorator, Maybe, Make
|
||||
#include "ftxui/component/component_base.hpp" // for Component, ComponentBase
|
||||
|
@@ -1,16 +1,16 @@
|
||||
#include <algorithm> // for max, reverse
|
||||
#include <algorithm> // for max, fill_n, reverse
|
||||
#include <chrono> // for milliseconds
|
||||
#include <functional> // for function
|
||||
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type, swap
|
||||
#include <string> // for char_traits, operator+, string, basic_string
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector, __alloc_traits<>::value_type
|
||||
#include <memory> // for allocator_traits<>::value_type, swap
|
||||
#include <string> // for operator+, string
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector, __alloc_traits<>::value_type
|
||||
|
||||
#include "ftxui/component/animation.hpp" // for Animator, Linear, Params (ptr only)
|
||||
#include "ftxui/component/animation.hpp" // for Animator, Linear
|
||||
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
||||
#include "ftxui/component/component.hpp" // for Make, Menu, MenuEntry, Toggle
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component_options.hpp" // for MenuOption, MenuEntryOption, MenuOption::Direction, UnderlineOption, AnimatedColorOption, AnimatedColorsOption, MenuOption::Down, MenuOption::Left, MenuOption::Right, MenuOption::Up
|
||||
#include "ftxui/component/component_options.hpp" // for MenuOption, MenuEntryOption, MenuOption::Direction, UnderlineOption, AnimatedColorOption, AnimatedColorsOption, EntryState, MenuOption::Down, MenuOption::Left, MenuOption::Right, MenuOption::Up
|
||||
#include "ftxui/component/event.hpp" // for Event, Event::ArrowDown, Event::ArrowLeft, Event::ArrowRight, Event::ArrowUp, Event::End, Event::Home, Event::PageDown, Event::PageUp, Event::Return, Event::Tab, Event::TabReverse
|
||||
#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
|
||||
@@ -109,7 +109,7 @@ class MenuBase : public ComponentBase {
|
||||
UpdateAnimationTarget();
|
||||
|
||||
Elements elements;
|
||||
bool is_menu_focused = Focused();
|
||||
const bool is_menu_focused = Focused();
|
||||
if (option_->elements_prefix) {
|
||||
elements.push_back(option_->elements_prefix());
|
||||
}
|
||||
@@ -117,10 +117,10 @@ class MenuBase : public ComponentBase {
|
||||
if (i != 0 && option_->elements_infix) {
|
||||
elements.push_back(option_->elements_infix());
|
||||
}
|
||||
bool is_focused = (focused_entry() == i) && is_menu_focused;
|
||||
bool is_selected = (*selected_ == i);
|
||||
const bool is_focused = (focused_entry() == i) && is_menu_focused;
|
||||
const bool is_selected = (*selected_ == i);
|
||||
|
||||
EntryState state = {
|
||||
const EntryState state = {
|
||||
entries_[i],
|
||||
false,
|
||||
is_selected,
|
||||
@@ -130,7 +130,7 @@ class MenuBase : public ComponentBase {
|
||||
auto focus_management =
|
||||
is_menu_focused && (selected_focus_ == i) ? focus : nothing;
|
||||
|
||||
Element element =
|
||||
const Element element =
|
||||
(option_->entries.transform ? option_->entries.transform
|
||||
: DefaultOptionTransform) //
|
||||
(state);
|
||||
@@ -145,7 +145,7 @@ class MenuBase : public ComponentBase {
|
||||
std::reverse(elements.begin(), elements.end());
|
||||
}
|
||||
|
||||
Element bar =
|
||||
const Element bar =
|
||||
IsHorizontal() ? hbox(std::move(elements)) : vbox(std::move(elements));
|
||||
|
||||
if (!option_->underline.enabled) {
|
||||
@@ -244,7 +244,7 @@ class MenuBase : public ComponentBase {
|
||||
}
|
||||
|
||||
if (Focused()) {
|
||||
int old_selected = *selected_;
|
||||
const int old_selected = *selected_;
|
||||
if (event == Event::ArrowUp || event == Event::Character('k')) {
|
||||
OnUp();
|
||||
}
|
||||
@@ -331,7 +331,7 @@ class MenuBase : public ComponentBase {
|
||||
if (!box_.Contain(event.mouse().x, event.mouse().y)) {
|
||||
return false;
|
||||
}
|
||||
int old_selected = *selected_;
|
||||
const int old_selected = *selected_;
|
||||
|
||||
if (event.mouse().button == Mouse::WheelUp) {
|
||||
(*selected_)--;
|
||||
@@ -373,10 +373,10 @@ class MenuBase : public ComponentBase {
|
||||
}
|
||||
}
|
||||
|
||||
bool is_menu_focused = Focused();
|
||||
const bool is_menu_focused = Focused();
|
||||
for (int i = 0; i < size(); ++i) {
|
||||
bool is_focused = (focused_entry() == i) && is_menu_focused;
|
||||
bool is_selected = (*selected_ == i);
|
||||
const bool is_focused = (focused_entry() == i) && is_menu_focused;
|
||||
const bool is_selected = (*selected_ == i);
|
||||
float target = is_selected ? 1.F : is_focused ? 0.5F : 0.F; // NOLINT
|
||||
if (animator_background_[i].to() != target) {
|
||||
animator_background_[i] = animation::Animator(
|
||||
@@ -447,16 +447,16 @@ class MenuBase : public ComponentBase {
|
||||
if (boxes_.empty()) {
|
||||
return 0.F;
|
||||
}
|
||||
int value = IsHorizontal() ? boxes_[*selected_].x_min - box_.x_min
|
||||
: boxes_[*selected_].y_min - box_.y_min;
|
||||
const int value = IsHorizontal() ? boxes_[*selected_].x_min - box_.x_min
|
||||
: boxes_[*selected_].y_min - box_.y_min;
|
||||
return float(value);
|
||||
}
|
||||
float SecondTarget() {
|
||||
if (boxes_.empty()) {
|
||||
return 0.F;
|
||||
}
|
||||
int value = IsHorizontal() ? boxes_[*selected_].x_max - box_.x_min
|
||||
: boxes_[*selected_].y_max - box_.y_min;
|
||||
const int value = IsHorizontal() ? boxes_[*selected_].x_max - box_.x_min
|
||||
: boxes_[*selected_].y_max - box_.y_min;
|
||||
return float(value);
|
||||
}
|
||||
|
||||
@@ -557,17 +557,17 @@ Component MenuEntry(ConstStringRef label, Ref<MenuEntryOption> option) {
|
||||
|
||||
private:
|
||||
Element Render() override {
|
||||
bool focused = Focused();
|
||||
const bool focused = Focused();
|
||||
UpdateAnimationTarget();
|
||||
|
||||
EntryState state = {
|
||||
const EntryState state = {
|
||||
*label_,
|
||||
false,
|
||||
hovered_,
|
||||
focused,
|
||||
};
|
||||
|
||||
Element element =
|
||||
const Element element =
|
||||
(option_->transform ? option_->transform : DefaultOptionTransform) //
|
||||
(state);
|
||||
|
||||
@@ -576,7 +576,7 @@ Component MenuEntry(ConstStringRef label, Ref<MenuEntryOption> option) {
|
||||
}
|
||||
|
||||
void UpdateAnimationTarget() {
|
||||
bool focused = Focused();
|
||||
const bool focused = Focused();
|
||||
float target = focused ? 1.F : hovered_ ? 0.5F : 0.F; // NOLINT
|
||||
if (target == animator_background_.to()) {
|
||||
return;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gtest/gtest.h> // for Test, EXPECT_EQ, Message, TestPartResult, TestInfo (ptr only), TEST
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
|
||||
#include <string> // for string
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/animation.hpp" // for Duration, Params
|
||||
|
@@ -32,10 +32,10 @@ class RadioboxBase : public ComponentBase {
|
||||
Element Render() override {
|
||||
Clamp();
|
||||
Elements elements;
|
||||
bool is_menu_focused = Focused();
|
||||
const bool is_menu_focused = Focused();
|
||||
for (int i = 0; i < size(); ++i) {
|
||||
bool is_focused = (focused_entry() == i) && is_menu_focused;
|
||||
bool is_selected = (hovered_ == i);
|
||||
const bool is_focused = (focused_entry() == i) && is_menu_focused;
|
||||
const bool is_selected = (hovered_ == i);
|
||||
auto focus_management = !is_selected ? nothing
|
||||
: is_menu_focused ? focus
|
||||
: select;
|
||||
@@ -66,7 +66,7 @@ class RadioboxBase : public ComponentBase {
|
||||
}
|
||||
|
||||
if (Focused()) {
|
||||
int old_hovered = hovered_;
|
||||
const int old_hovered = hovered_;
|
||||
if (event == Event::ArrowUp || event == Event::Character('k')) {
|
||||
(hovered_)--;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ class RadioboxBase : public ComponentBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
int old_hovered = hovered_;
|
||||
const int old_hovered = hovered_;
|
||||
|
||||
if (event.mouse().button == Mouse::WheelUp) {
|
||||
(hovered_)--;
|
||||
|
@@ -1,12 +1,15 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gtest/gtest.h> // for AssertionResult, Message, TestPartResult, EXPECT_EQ, EXPECT_TRUE, Test, TestInfo (ptr only), EXPECT_FALSE, TEST
|
||||
#include <ftxui/dom/elements.hpp> // for yframe
|
||||
#include <ftxui/dom/node.hpp> // for Render
|
||||
#include <ftxui/screen/screen.hpp> // for Screen
|
||||
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
|
||||
#include <string> // for string
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Radiobox
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component.hpp" // for Radiobox, operator|
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
|
||||
#include "ftxui/component/component_options.hpp" // for RadioboxOption
|
||||
#include "ftxui/component/event.hpp" // for Event, Event::Return, Event::ArrowDown, Event::ArrowUp, Event::Tab, Event::TabReverse
|
||||
#include "ftxui/component/event.hpp" // for Event, Event::Return, Event::ArrowDown, Event::End, Event::Home, Event::Tab, Event::TabReverse, Event::PageDown, Event::PageUp, Event::ArrowUp
|
||||
#include "ftxui/util/ref.hpp" // for Ref
|
||||
|
||||
namespace ftxui {
|
||||
|
@@ -1,19 +1,19 @@
|
||||
#include <algorithm> // for copy, max, min
|
||||
#include <array> // for array
|
||||
#include <chrono> // for operator-, milliseconds, duration, operator>=, time_point, common_type<>::type
|
||||
#include <csignal> // for signal, raise, SIGTSTP, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, SIGWINCH
|
||||
#include <cstdio> // for fileno, size_t, stdin
|
||||
#include <chrono> // for operator-, milliseconds, operator>=, duration, common_type<>::type, time_point
|
||||
#include <csignal> // for signal, SIGTSTP, SIGABRT, SIGWINCH, raise, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, __sighandler_t, size_t
|
||||
#include <cstdio> // for fileno, stdin
|
||||
#include <ftxui/component/task.hpp> // for Task, Closure, AnimationTask
|
||||
#include <ftxui/screen/screen.hpp> // for Pixel, Screen::Cursor, Screen
|
||||
#include <functional> // for function
|
||||
#include <initializer_list> // for initializer_list
|
||||
#include <iostream> // for cout, ostream, basic_ostream, operator<<, endl, flush
|
||||
#include <ftxui/screen/screen.hpp> // for Pixel, Screen::Cursor, Screen, Screen::Cursor::Hidden
|
||||
#include <functional> // for function
|
||||
#include <initializer_list> // for initializer_list
|
||||
#include <iostream> // for cout, ostream, operator<<, basic_ostream, endl, flush
|
||||
#include <stack> // for stack
|
||||
#include <thread> // for thread, sleep_for
|
||||
#include <tuple>
|
||||
#include <tuple> // for _Swallow_assign, ignore
|
||||
#include <type_traits> // for decay_t
|
||||
#include <utility> // for move, swap
|
||||
#include <variant> // for visit
|
||||
#include <variant> // for visit, variant
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/animation.hpp" // for TimePoint, Clock, Duration, Params, RequestAnimationFrame
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
#include "ftxui/component/loop.hpp" // for Loop
|
||||
#include "ftxui/component/receiver.hpp" // for Sender, ReceiverImpl, MakeReceiver, SenderImpl, Receiver
|
||||
#include "ftxui/component/receiver.hpp" // for ReceiverImpl, Sender, MakeReceiver, SenderImpl, Receiver
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
#include "ftxui/component/terminal_input_parser.hpp" // for TerminalInputParser
|
||||
#include "ftxui/dom/node.hpp" // for Node, Render
|
||||
@@ -39,7 +39,7 @@
|
||||
#error Must be compiled in UNICODE mode
|
||||
#endif
|
||||
#else
|
||||
#include <sys/select.h> // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set
|
||||
#include <sys/select.h> // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set, timeval
|
||||
#include <termios.h> // for tcsetattr, termios, tcgetattr, TCSANOW, cc_t, ECHO, ICANON, VMIN, VTIME
|
||||
#include <unistd.h> // for STDIN_FILENO, read
|
||||
#endif
|
||||
@@ -150,8 +150,6 @@ void ftxui_on_resize(int columns, int rows) {
|
||||
|
||||
#else // POSIX (Linux & Mac)
|
||||
|
||||
#include <sys/time.h> // for timeval
|
||||
|
||||
int CheckStdinReady(int usec_timeout) {
|
||||
timeval tv = {0, usec_timeout};
|
||||
fd_set fds;
|
||||
@@ -189,10 +187,10 @@ void OnExit() {
|
||||
}
|
||||
}
|
||||
|
||||
std::atomic<int> g_signal_exit_count = 0;
|
||||
std::atomic<int> g_signal_exit_count = 0; // NOLINT
|
||||
#if !defined(_WIN32)
|
||||
std::atomic<int> g_signal_stop_count = 0;
|
||||
std::atomic<int> g_signal_resize_count = 0;
|
||||
std::atomic<int> g_signal_stop_count = 0; // NOLINT
|
||||
std::atomic<int> g_signal_resize_count = 0; // NOLINT
|
||||
#endif
|
||||
|
||||
// Async signal safe function
|
||||
@@ -276,7 +274,7 @@ enum class DSRMode {
|
||||
std::string Serialize(const std::vector<DECMode>& parameters) {
|
||||
bool first = true;
|
||||
std::string out;
|
||||
for (DECMode parameter : parameters) {
|
||||
for (const DECMode parameter : parameters) {
|
||||
if (!first) {
|
||||
out += ";";
|
||||
}
|
||||
@@ -491,7 +489,7 @@ void ScreenInteractive::Install() {
|
||||
|
||||
// Install signal handlers to restore the terminal state on exit. The default
|
||||
// signal handlers are restored on exit.
|
||||
for (int signal : {SIGTERM, SIGSEGV, SIGINT, SIGILL, SIGABRT, SIGFPE}) {
|
||||
for (const int signal : {SIGTERM, SIGSEGV, SIGINT, SIGILL, SIGABRT, SIGFPE}) {
|
||||
InstallSignalHandler(signal);
|
||||
}
|
||||
|
||||
@@ -527,7 +525,7 @@ void ScreenInteractive::Install() {
|
||||
SetConsoleMode(stdin_handle, in_mode);
|
||||
SetConsoleMode(stdout_handle, out_mode);
|
||||
#else
|
||||
for (int signal : {SIGWINCH, SIGTSTP}) {
|
||||
for (const int signal : {SIGWINCH, SIGTSTP}) {
|
||||
InstallSignalHandler(signal);
|
||||
}
|
||||
|
||||
@@ -653,8 +651,8 @@ void ScreenInteractive::HandleTask(Component component, Task& task) {
|
||||
}
|
||||
|
||||
animation_requested_ = false;
|
||||
animation::TimePoint now = animation::Clock::now();
|
||||
animation::Duration delta = now - previous_animation_time_;
|
||||
const animation::TimePoint now = animation::Clock::now();
|
||||
const animation::Duration delta = now - previous_animation_time_;
|
||||
previous_animation_time_ = now;
|
||||
|
||||
animation::Params params(delta);
|
||||
@@ -697,7 +695,7 @@ void ScreenInteractive::Draw(Component component) {
|
||||
break;
|
||||
}
|
||||
|
||||
bool resized = (dimx != dimx_) || (dimy != dimy_);
|
||||
const bool resized = (dimx != dimx_) || (dimy != dimy_);
|
||||
ResetCursorPosition();
|
||||
std::cout << ResetPosition(/*clear=*/resized);
|
||||
|
||||
@@ -742,8 +740,8 @@ void ScreenInteractive::Draw(Component component) {
|
||||
reset_cursor_position = "";
|
||||
|
||||
{
|
||||
int dx = dimx_ - 1 - cursor_.x;
|
||||
int dy = dimy_ - 1 - cursor_.y;
|
||||
const int dx = dimx_ - 1 - cursor_.x;
|
||||
const int dy = dimy_ - 1 - cursor_.y;
|
||||
|
||||
if (dy != 0) {
|
||||
set_cursor_position += "\x1B[" + std::to_string(dy) + "A";
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include <algorithm> // for max, min
|
||||
#include <ftxui/component/component_options.hpp> // for SliderOption
|
||||
#include <string> // for allocator
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
||||
#include "ftxui/component/component.hpp" // for Make, Slider
|
||||
@@ -12,7 +13,7 @@
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::GrayDark, Color::White
|
||||
#include "ftxui/screen/util.hpp" // for clamp
|
||||
#include "ftxui/util/ref.hpp" // for ConstRef, ConstStringRef, Ref
|
||||
#include "ftxui/util/ref.hpp" // for ConstRef, Ref, ConstStringRef
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -43,7 +44,7 @@ class SliderBase : public ComponentBase {
|
||||
Element Render() override {
|
||||
auto gauge_color = Focused() ? color(options_->color_active)
|
||||
: color(options_->color_inactive);
|
||||
float percent = float(value_() - min_()) / float(max_() - min_());
|
||||
const float percent = float(value_() - min_()) / float(max_() - min_());
|
||||
return gaugeDirection(percent, options_->direction) |
|
||||
flexDirection(options_->direction) | reflect(gauge_box_) |
|
||||
gauge_color;
|
||||
|
Reference in New Issue
Block a user