From 765c51776be8151ee89a04fb3de23e2ee4b11501 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 5 Sep 2019 18:16:21 -0400 Subject: [PATCH] General: Use std::make_unique where applicable No behavior change. --- specter/lib/Button.cpp | 22 ++++++----- specter/lib/FileBrowser.cpp | 61 +++++++++++++++---------------- specter/lib/Menu.cpp | 18 ++++----- specter/lib/MessageWindow.cpp | 16 ++++---- specter/lib/ModalWindow.cpp | 6 +-- specter/lib/MultiLineTextView.cpp | 14 +++---- specter/lib/PathButtons.cpp | 4 +- specter/lib/RootView.cpp | 14 +++---- specter/lib/ScrollView.cpp | 4 +- specter/lib/Space.cpp | 10 +++-- specter/lib/Table.cpp | 38 +++++++++++-------- specter/lib/TextField.cpp | 7 ++-- specter/lib/Tooltip.cpp | 8 ++-- specter/zeus | 2 +- 14 files changed, 118 insertions(+), 106 deletions(-) diff --git a/specter/lib/Button.cpp b/specter/lib/Button.cpp index 4af7183a3..01172d6f8 100644 --- a/specter/lib/Button.cpp +++ b/specter/lib/Button.cpp @@ -68,8 +68,8 @@ Button::Button(ViewResources& res, View& parentView, IButtonBinding* controlBind return true; }); - m_buttonTarget.m_view.reset(new ButtonTarget(res, *this)); - m_menuTarget.m_view.reset(new MenuTarget(res, *this)); + m_buttonTarget.m_view = std::make_unique(res, *this); + m_menuTarget.m_view = std::make_unique(res, *this); if (style == Style::Block) { zeus::CColor c1 = res.themeData().button1Inactive() * bgColor; @@ -97,13 +97,15 @@ Button::Button(ViewResources& res, View& parentView, IButtonBinding* controlBind m_verts[i].m_color = m_textColor; _loadVerts(); - if (controlBinding) + if (controlBinding != nullptr) { m_menuStyle = controlBinding->menuStyle(this); + } - if (icon) - m_icon.reset(new IconView(res, *this, *icon)); + if (icon != nullptr) { + m_icon = std::make_unique(res, *this, *icon); + } - m_text.reset(new TextView(res, *this, res.m_mainFont, TextView::Alignment::Center)); + m_text = std::make_unique(res, *this, res.m_mainFont, TextView::Alignment::Center); setText(m_textStr); } @@ -227,10 +229,12 @@ void Button::setText(std::string_view text, const zeus::CColor& textColor) { } void Button::setIcon(Icon* icon) { - if (icon) - m_icon.reset(new IconView(rootView().viewRes(), *this, *icon)); - else + if (icon != nullptr) { + m_icon = std::make_unique(rootView().viewRes(), *this, *icon); + } else { m_icon.reset(); + } + setText(m_textStr); updateSize(); } diff --git a/specter/lib/FileBrowser.cpp b/specter/lib/FileBrowser.cpp index 4bdad43ae..8bd40d402 100644 --- a/specter/lib/FileBrowser.cpp +++ b/specter/lib/FileBrowser.cpp @@ -60,23 +60,21 @@ FileBrowser::FileBrowser(ViewResources& res, View& parentView, std::string_view , m_systemBookmarkBind(*this) , m_projectBookmarkBind(*this) , m_recentBookmarkBind(*this) -, m_returnFunc(returnFunc) { +, m_returnFunc(std::move(returnFunc)) { setBackground({0, 0, 0, 0.5}); IViewManager& vm = rootView().viewManager(); - m_pathButtons.m_view.reset(new PathButtons(res, *this, *this)); - m_fileField.m_view.reset(new TextField(res, *this, &m_fileFieldBind)); - m_fileListing.m_view.reset(new Table(res, *this, &m_fileListingBind, &m_fileListingBind, 3)); - m_systemBookmarks.m_view.reset(new Table(res, *this, &m_systemBookmarkBind, &m_systemBookmarkBind, 1)); - m_systemBookmarksLabel.reset(new TextView(res, *this, res.m_mainFont)); - m_systemBookmarksLabel->typesetGlyphs(vm.translate(), - res.themeData().uiText()); - m_projectBookmarks.m_view.reset(new Table(res, *this, &m_projectBookmarkBind, &m_projectBookmarkBind, 1)); - m_projectBookmarksLabel.reset(new TextView(res, *this, res.m_mainFont)); - m_projectBookmarksLabel->typesetGlyphs(vm.translate(), - res.themeData().uiText()); - m_recentBookmarks.m_view.reset(new Table(res, *this, &m_recentBookmarkBind, &m_recentBookmarkBind, 1)); - m_recentBookmarksLabel.reset(new TextView(res, *this, res.m_mainFont)); + m_pathButtons.m_view = std::make_unique(res, *this, *this); + m_fileField.m_view = std::make_unique(res, *this, &m_fileFieldBind); + m_fileListing.m_view = std::make_unique(res, *this, &m_fileListingBind, &m_fileListingBind, 3); + m_systemBookmarks.m_view = std::make_unique
(res, *this, &m_systemBookmarkBind, &m_systemBookmarkBind, 1); + m_systemBookmarksLabel = std::make_unique(res, *this, res.m_mainFont); + m_systemBookmarksLabel->typesetGlyphs(vm.translate(), res.themeData().uiText()); + m_projectBookmarks.m_view = std::make_unique
(res, *this, &m_projectBookmarkBind, &m_projectBookmarkBind, 1); + m_projectBookmarksLabel = std::make_unique(res, *this, res.m_mainFont); + m_projectBookmarksLabel->typesetGlyphs(vm.translate(), res.themeData().uiText()); + m_recentBookmarks.m_view = std::make_unique
(res, *this, &m_recentBookmarkBind, &m_recentBookmarkBind, 1); + m_recentBookmarksLabel = std::make_unique(res, *this, res.m_mainFont); m_recentBookmarksLabel->typesetGlyphs(vm.translate(), res.themeData().uiText()); /* Populate system bookmarks */ @@ -99,8 +97,8 @@ FileBrowser::FileBrowser(ViewResources& res, View& parentView, std::string_view navigateToPath(initialPath); - m_split.m_view.reset(new SplitView(res, *this, nullptr, SplitView::Axis::Vertical, 0.2, 200 * res.pixelFactor(), - 400 * res.pixelFactor())); + m_split.m_view = std::make_unique(res, *this, nullptr, SplitView::Axis::Vertical, 0.2, + 200 * res.pixelFactor(), 400 * res.pixelFactor()); m_split.m_view->setContentView(0, &m_left); m_split.m_view->setContentView(1, &m_right); @@ -208,17 +206,16 @@ void FileBrowser::okActivated(bool viaButton) { return; } if (!err && !S_ISDIR(theStat.st_mode)) { - m_confirmWindow.reset( - new MessageWindow(rootView().viewRes(), *this, MessageWindow::Type::ConfirmOkCancel, - vm.translate(hecl::SystemUTF8Conv(path)), - [&, path](bool ok) { - if (ok) { - m_returnFunc(true, path); - m_confirmWindow->close(); - close(); - } else - m_confirmWindow->close(); - })); + m_confirmWindow = std::make_unique( + rootView().viewRes(), *this, MessageWindow::Type::ConfirmOkCancel, + vm.translate(hecl::SystemUTF8Conv(path)), [&, path](bool ok) { + if (ok) { + m_returnFunc(true, path); + m_confirmWindow->close(); + close(); + } else + m_confirmWindow->close(); + }); updateSize(); return; } @@ -587,16 +584,16 @@ void FileBrowser::RightSide::draw(boo::IGraphicsCommandQueue* gfxQ) { } FileBrowser::OKButton::OKButton(FileBrowser& fb, ViewResources& res, std::string_view text) : m_fb(fb), m_text(text) { - m_button.m_view.reset( - new Button(res, fb, this, text, nullptr, Button::Style::Block, zeus::skWhite, - RectangleConstraint(100 * res.pixelFactor(), -1, RectangleConstraint::Test::Minimum))); + m_button.m_view = + std::make_unique