From bc682d25a62d3da7fe198af44c409f7c9d0506d6 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 22 Mar 2025 17:30:34 +0100 Subject: [PATCH] Fix compiler nits. --- src/ftxui/component/component.cpp | 1 + src/ftxui/component/container.cpp | 2 +- src/ftxui/component/slider.cpp | 1 - src/ftxui/dom/dbox.cpp | 1 - src/ftxui/dom/flexbox.cpp | 8 +++++--- src/ftxui/dom/flexbox_helper.hpp | 1 - src/ftxui/dom/hbox.cpp | 2 +- src/ftxui/dom/node.cpp | 6 ++++-- src/ftxui/dom/paragraph.cpp | 9 +++++---- src/ftxui/dom/selection.cpp | 17 +++++++++++------ src/ftxui/dom/selection_style.cpp | 15 +++++++++------ src/ftxui/dom/table.cpp | 3 ++- src/ftxui/dom/text.cpp | 3 ++- src/ftxui/dom/vbox.cpp | 1 + src/ftxui/screen/screen.cpp | 2 +- 15 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/ftxui/component/component.cpp b/src/ftxui/component/component.cpp index e4177d67..825865ae 100644 --- a/src/ftxui/component/component.cpp +++ b/src/ftxui/component/component.cpp @@ -16,6 +16,7 @@ #include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive #include "ftxui/dom/elements.hpp" // for text, Element #include "ftxui/dom/node.hpp" // for Node, Elements +#include "ftxui/screen/box.hpp" // for Box namespace ftxui::animation { class Params; diff --git a/src/ftxui/component/container.cpp b/src/ftxui/component/container.cpp index 3e32c744..68de8b43 100644 --- a/src/ftxui/component/container.cpp +++ b/src/ftxui/component/container.cpp @@ -163,7 +163,7 @@ class VerticalContainer : public ContainerBase { return false; } - int old_selected = *selector_; + const int old_selected = *selector_; if (event.mouse().button == Mouse::WheelUp) { MoveSelector(-1); } diff --git a/src/ftxui/component/slider.cpp b/src/ftxui/component/slider.cpp index 0815c6b8..adbb7203 100644 --- a/src/ftxui/component/slider.cpp +++ b/src/ftxui/component/slider.cpp @@ -16,7 +16,6 @@ #include "ftxui/dom/elements.hpp" // for operator|, text, Element, xflex, hbox, color, underlined, reflect, Decorator, dim, vcenter, focus, nothing, select, yflex, gaugeDirection #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, Ref, ConstStringRef namespace ftxui { diff --git a/src/ftxui/dom/dbox.cpp b/src/ftxui/dom/dbox.cpp index ce65f8e2..2c9994a2 100644 --- a/src/ftxui/dom/dbox.cpp +++ b/src/ftxui/dom/dbox.cpp @@ -23,7 +23,6 @@ class DBox : public Node { void ComputeRequirement() override { requirement_ = Requirement{}; for (auto& child : children_) { - child->ComputeRequirement(); // Propagate the focused requirement. diff --git a/src/ftxui/dom/flexbox.cpp b/src/ftxui/dom/flexbox.cpp index 89d10c27..00780d2e 100644 --- a/src/ftxui/dom/flexbox.cpp +++ b/src/ftxui/dom/flexbox.cpp @@ -4,6 +4,7 @@ #include // for min, max #include // for size_t #include // for __shared_ptr_access, shared_ptr, allocator_traits<>::value_type, make_shared +#include // for ignore #include // for move, swap #include // for vector @@ -12,6 +13,7 @@ #include "ftxui/dom/flexbox_helper.hpp" // for Block, Global, Compute #include "ftxui/dom/node.hpp" // for Node, Elements, Node::Status #include "ftxui/dom/requirement.hpp" // for Requirement +#include "ftxui/dom/selection.hpp" // for Selection #include "ftxui/screen/box.hpp" // for Box namespace ftxui { @@ -192,9 +194,9 @@ class Flexbox : public Node { continue; } - Selection selection_line = - IsColumnOriented() ? selection_lines.SaturateHorizontal(box) - : selection_lines.SaturateVertical(box); + Selection selection_line = IsColumnOriented() + ? selection_lines.SaturateHorizontal(box) + : selection_lines.SaturateVertical(box); for (auto& block : line.blocks) { std::ignore = block; diff --git a/src/ftxui/dom/flexbox_helper.hpp b/src/ftxui/dom/flexbox_helper.hpp index 1c80f06e..9f9313e4 100644 --- a/src/ftxui/dom/flexbox_helper.hpp +++ b/src/ftxui/dom/flexbox_helper.hpp @@ -46,7 +46,6 @@ struct Global { int size_y; }; - void Compute(Global& global); } // namespace ftxui::flexbox_helper diff --git a/src/ftxui/dom/hbox.cpp b/src/ftxui/dom/hbox.cpp index a86bef10..46f9ef81 100644 --- a/src/ftxui/dom/hbox.cpp +++ b/src/ftxui/dom/hbox.cpp @@ -11,8 +11,8 @@ #include "ftxui/dom/elements.hpp" // for Element, Elements, hbox #include "ftxui/dom/node.hpp" // for Node, Elements #include "ftxui/dom/requirement.hpp" // for Requirement +#include "ftxui/dom/selection.hpp" // for Selection #include "ftxui/screen/box.hpp" // for Box - namespace ftxui { namespace { diff --git a/src/ftxui/dom/node.cpp b/src/ftxui/dom/node.cpp index 8be88ce6..10401a3a 100644 --- a/src/ftxui/dom/node.cpp +++ b/src/ftxui/dom/node.cpp @@ -2,11 +2,13 @@ // Use of this source code is governed by the MIT license that can be found in // the LICENSE file. #include // for Box -#include // for move +#include +#include // for move +#include #include "ftxui/dom/node.hpp" +#include "ftxui/dom/selection.hpp" // for Selection #include "ftxui/screen/screen.hpp" // for Screen -#include "ftxui/screen/util.hpp" // for clamp namespace ftxui { diff --git a/src/ftxui/dom/paragraph.cpp b/src/ftxui/dom/paragraph.cpp index 482e7e3b..4d2c154c 100644 --- a/src/ftxui/dom/paragraph.cpp +++ b/src/ftxui/dom/paragraph.cpp @@ -1,9 +1,10 @@ // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in // the LICENSE file. -#include // for basic_istream, stringstream -#include // for string, allocator, getline -#include // for move +#include // for function +#include // for basic_istream, stringstream +#include // for string, allocator, getline +#include // for move #include "ftxui/dom/elements.hpp" // for flexbox, Element, text, Elements, operator|, xflex, paragraph, paragraphAlignCenter, paragraphAlignJustify, paragraphAlignLeft, paragraphAlignRight #include "ftxui/dom/flexbox_config.hpp" // for FlexboxConfig, FlexboxConfig::JustifyContent, FlexboxConfig::JustifyContent::Center, FlexboxConfig::JustifyContent::FlexEnd, FlexboxConfig::JustifyContent::SpaceBetween @@ -22,7 +23,7 @@ Elements Split(const std::string& the_text) { } Element Split(const std::string& paragraph, - std::function f) { + const std::function& f) { Elements output; std::stringstream ss(paragraph); std::string line; diff --git a/src/ftxui/dom/selection.cpp b/src/ftxui/dom/selection.cpp index feb60b07..ff55fc41 100644 --- a/src/ftxui/dom/selection.cpp +++ b/src/ftxui/dom/selection.cpp @@ -4,8 +4,9 @@ #include "ftxui/dom/selection.hpp" // for Selection #include // for max, min +#include // for string +#include // for ignore -#include "ftxui/dom/elements.hpp" // for Element, inverted #include "ftxui/dom/node_decorator.hpp" // for NodeDecorator namespace ftxui { @@ -15,14 +16,15 @@ class Unselectable : public NodeDecorator { public: using NodeDecorator::NodeDecorator; - void Select(Selection&) override { + void Select(Selection& ignored) override { + std::ignore = ignored; // Overwrite the select method to do nothing. } }; } // namespace /// @brief Create an empty selection. -Selection::Selection() : empty_(true) {} +Selection::Selection() = default; /// @brief Create a selection. /// @param start_x The x coordinate of the start of the selection. @@ -99,7 +101,9 @@ Selection Selection::SaturateHorizontal(Box box) { end_y = box.y_min; } } - return Selection(start_x, start_y, end_x, end_y, parent_); + return { + start_x, start_y, end_x, end_y, parent_, + }; } /// @brief Saturate the selection to be inside the box. @@ -136,12 +140,13 @@ Selection Selection::SaturateVertical(Box box) { end_y = box.y_min; } } - return Selection(start_x, start_y, end_x, end_y, parent_); + return {start_x, start_y, end_x, end_y, parent_}; } void Selection::AddPart(const std::string& part, int y, int left, int right) { if (parent_ != this) { - return parent_->AddPart(part, y, left, right); + parent_->AddPart(part, y, left, right); + return; } [&] { if (parts_.str().empty()) { diff --git a/src/ftxui/dom/selection_style.cpp b/src/ftxui/dom/selection_style.cpp index 6ee95f79..202c3ba7 100644 --- a/src/ftxui/dom/selection_style.cpp +++ b/src/ftxui/dom/selection_style.cpp @@ -1,14 +1,15 @@ // Copyright 2024 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in // the LICENSE file. -#include // for make_shared -#include // for move +#include // for function +#include // for make_shared +#include // for move #include "ftxui/dom/elements.hpp" // for Element, Decorator, bgcolor, color #include "ftxui/dom/node_decorator.hpp" // for NodeDecorator -#include "ftxui/screen/box.hpp" // for Box #include "ftxui/screen/color.hpp" // for Color -#include "ftxui/screen/screen.hpp" // for Pixel, Screen +#include "ftxui/screen/pixel.hpp" // for Pixel +#include "ftxui/screen/screen.hpp" // for Screen namespace ftxui { @@ -16,7 +17,8 @@ namespace { class SelectionStyleReset : public NodeDecorator { public: - SelectionStyleReset(Element child) : NodeDecorator(std::move(child)) {} + explicit SelectionStyleReset(Element child) + : NodeDecorator(std::move(child)) {} void Render(Screen& screen) final { auto old_style = screen.GetSelectionStyle(); @@ -28,7 +30,7 @@ class SelectionStyleReset : public NodeDecorator { class SelectionStyle : public NodeDecorator { public: - SelectionStyle(Element child, std::function style) + SelectionStyle(Element child, const std::function& style) : NodeDecorator(std::move(child)), style_(style) {} void Render(Screen& screen) final { @@ -80,6 +82,7 @@ Decorator selectionColor(Color foreground) { /// @brief Set the style of an element when selected. /// @param style The style to be applied. /// Note that the style is applied on top of the existing style. +// NOLINTNEXTLINE Decorator selectionStyle(std::function style) { return [style](Element child) -> Element { return std::make_shared(std::move(child), style); diff --git a/src/ftxui/dom/table.cpp b/src/ftxui/dom/table.cpp index 18583aa7..52bc8094 100644 --- a/src/ftxui/dom/table.cpp +++ b/src/ftxui/dom/table.cpp @@ -3,7 +3,8 @@ // the LICENSE file. #include "ftxui/dom/table.hpp" -#include // for max +#include // for max +#include // for initializer_list #include // for allocator, shared_ptr, allocator_traits<>::value_type #include // for move, swap #include // for vector diff --git a/src/ftxui/dom/text.cpp b/src/ftxui/dom/text.cpp index b6b534a1..4b7a483c 100644 --- a/src/ftxui/dom/text.cpp +++ b/src/ftxui/dom/text.cpp @@ -11,6 +11,7 @@ #include "ftxui/dom/elements.hpp" // for Element, text, vtext #include "ftxui/dom/node.hpp" // for Node #include "ftxui/dom/requirement.hpp" // for Requirement +#include "ftxui/dom/selection.hpp" // for Selection #include "ftxui/screen/box.hpp" // for Box #include "ftxui/screen/screen.hpp" // for Pixel, Screen #include "ftxui/screen/string.hpp" // for string_width, Utf8ToGlyphs, to_string @@ -35,7 +36,7 @@ class Text : public Node { return; } - Selection selection_saturated = selection.SaturateHorizontal(box_); + const Selection selection_saturated = selection.SaturateHorizontal(box_); has_selection = true; selection_start_ = selection_saturated.GetBox().x_min; diff --git a/src/ftxui/dom/vbox.cpp b/src/ftxui/dom/vbox.cpp index 1fcb819e..4b936d17 100644 --- a/src/ftxui/dom/vbox.cpp +++ b/src/ftxui/dom/vbox.cpp @@ -11,6 +11,7 @@ #include "ftxui/dom/elements.hpp" // for Element, Elements, vbox #include "ftxui/dom/node.hpp" // for Node, Elements #include "ftxui/dom/requirement.hpp" // for Requirement +#include "ftxui/dom/selection.hpp" // for Selection #include "ftxui/screen/box.hpp" // for Box namespace ftxui { diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index beb3870a..ac815399 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -553,7 +553,7 @@ const Screen::SelectionStyle& Screen::GetSelectionStyle() const { /// @brief Set the current selection style. /// @see GetSelectionStyle void Screen::SetSelectionStyle(SelectionStyle decorator) { - selection_style_ = decorator; + selection_style_ = std::move(decorator); } } // namespace ftxui