From 3391c0cb208104058a6ce5b364de740e34f34d19 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sat, 19 Nov 2022 04:21:01 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20possible=20fixes=20reported=20by?= =?UTF-8?q?=20GCC=20analyzer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/widgets.cpp | 34 +++++++++++++++++----------------- src/widgets.hpp | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/widgets.cpp b/src/widgets.cpp index eac4a2a..92a0ff4 100644 --- a/src/widgets.cpp +++ b/src/widgets.cpp @@ -28,15 +28,15 @@ Element centered_widget(Component& container, const std::string_view& title, con text(title.data()) | bold, filler(), // -------- Center Menu -------------- - hbox({ + std::move(hbox({ filler(), - border(vbox({ + border(std::move(vbox({ widget, separator(), container->Render() | hcenter | size(HEIGHT, LESS_THAN, 3) | size(WIDTH, GREATER_THAN, 25), - })), + }))), filler(), - }) | center, + })) | center, filler(), }); } @@ -47,11 +47,11 @@ Element centered_widget_nocontrols(const std::string_view& title, const Element& text(title.data()) | bold, filler(), // -------- Center Menu -------------- - hbox({ + std::move(hbox({ filler(), - border(vbox({widget})), + border(std::move(vbox({widget}))), filler(), - }) | center, + })) | center, filler(), }); } @@ -77,13 +77,13 @@ Element centered_interative_multi(const std::string_view& title, Component& widg text(title.data()) | bold, filler(), // -------- Center Menu -------------- - hbox({ + std::move(hbox({ filler(), - border(vbox({ + border(std::move(vbox({ widgets->Render(), - })), + }))), filler(), - }) | center, + })) | center, filler(), }); } @@ -92,16 +92,16 @@ Element multiline_text(const std::vector& lines) noexcept { Elements multiline; std::transform(lines.cbegin(), lines.cend(), std::back_inserter(multiline), - [=](const std::string& line) -> Element { return text(line); }); - return vbox(std::move(multiline)) | frame; + [=](auto&& line) -> Element { return std::move(text(line)); }); + return std::move(vbox(std::move(multiline))) | frame; } Components from_vector_checklist(const std::vector& opts, bool* opts_state) noexcept { Components components; for (size_t i = 0; i < opts.size(); ++i) { - auto component = Checkbox(&opts[i], &opts_state[i]); - components.emplace_back(component); + auto&& component = Checkbox(&opts[i], &opts_state[i]); + components.emplace_back(std::move(component)); } return components; } @@ -285,7 +285,7 @@ void menu_widget(const std::vector& entries, const std::functionLoop(renderer); } -void radiolist_widget(const std::vector& entries, const std::function&& ok_callback, std::int32_t* selected, ScreenInteractive* screen, const WidgetBoxRes widget_res, const WidgetBoxSize widget_sizes) noexcept { +void radiolist_widget(const std::vector& entries, const std::function&& ok_callback, std::int32_t* selected, ScreenInteractive* screen, const WidgetBoxRes& widget_res, const WidgetBoxSize widget_sizes) noexcept { auto radiolist = Container::Vertical({ Radiobox(&entries, selected), }); @@ -338,7 +338,7 @@ void checklist_widget(const std::vector& opts, const std::function< Components children{}; if (!text.empty()) { children = { - Renderer([&] { return detail::multiline_text(utils::make_multiline(text)) | widget_sizes.text_size; }), + Renderer([&] { return std::move(detail::multiline_text(utils::make_multiline(text))) | widget_sizes.text_size; }), Renderer([] { return separator(); }), content, Renderer([] { return separator(); }), diff --git a/src/widgets.hpp b/src/widgets.hpp index a487cc0..589016e 100644 --- a/src/widgets.hpp +++ b/src/widgets.hpp @@ -40,7 +40,7 @@ namespace detail { bool yesno_widget(const std::string_view& content, ftxui::Decorator boxsize = size(ftxui::HEIGHT, ftxui::GREATER_THAN, 5)) noexcept; bool yesno_widget(ftxui::Component& container, ftxui::Decorator boxsize = size(ftxui::HEIGHT, ftxui::GREATER_THAN, 5)) noexcept; void menu_widget(const std::vector& entries, const std::function&& ok_callback, std::int32_t* selected, ftxui::ScreenInteractive* screen, const std::string_view& text = "", const WidgetBoxSize widget_sizes = {}) noexcept; - void radiolist_widget(const std::vector& entries, const std::function&& ok_callback, std::int32_t* selected, ftxui::ScreenInteractive* screen, const WidgetBoxRes widget_res = {}, const WidgetBoxSize widget_sizes = {}) noexcept; + void radiolist_widget(const std::vector& entries, const std::function&& ok_callback, std::int32_t* selected, ftxui::ScreenInteractive* screen, const WidgetBoxRes& widget_res = {}, const WidgetBoxSize widget_sizes = {}) noexcept; void checklist_widget(const std::vector& opts, const std::function&& ok_callback, bool* opts_state, ftxui::ScreenInteractive* screen, const std::string_view& text = "", const std::string_view& title = "New CLI Installer", const WidgetBoxSize widget_sizes = {}) noexcept; } // namespace detail } // namespace tui