reduce explicit calls to make_unique by having app::push and options::add call it for us.

this commit doesn't change the codegen. it just cleans up the code slightly.
This commit is contained in:
ITotalJustice
2025-06-25 19:17:01 +01:00
parent 38f19ec778
commit 4e3927bbd0
20 changed files with 466 additions and 461 deletions

View File

@@ -18,6 +18,7 @@
#include <string>
#include <span>
#include <optional>
#include <utility>
namespace sphaira {
@@ -58,7 +59,14 @@ public:
static void Exit();
static void ExitRestart();
static auto GetVg() -> NVGcontext*;
static void Push(std::unique_ptr<ui::Widget>&&);
template<ui::DerivedFromWidget T, typename... Args>
static void Push(Args&&... args) {
Push(std::make_unique<T>(std::forward<Args>(args)...));
}
// pops all widgets above a menu
static void PopToMenu();

View File

@@ -3,6 +3,8 @@
#include "ui/widget.hpp"
#include "ui/list.hpp"
#include <memory>
#include <concepts>
#include <utility>
namespace sphaira::ui {
@@ -15,6 +17,9 @@ protected:
std::string m_title;
};
template<typename T>
concept DerivedFromSidebarBase = std::is_base_of_v<SidebarEntryBase, T>;
class SidebarEntryBool final : public SidebarEntryBase {
public:
using Callback = std::function<void(bool&)>;
@@ -110,17 +115,11 @@ public:
void Add(std::unique_ptr<SidebarEntryBase>&& entry);
template<typename T>
void AddMove(T entry) {
Add(std::move(entry));
template<DerivedFromSidebarBase T, typename... Args>
void Add(Args&&... args) {
Add(std::make_unique<T>(std::forward<Args>(args)...));
}
// template<typename _Tp>
// [[nodiscrad,gnu::always_inline]]
// constexpr typename std::remove_reference<_Tp>::type&&
// move(_Tp&& t) noexcept
// { return static_cast<typename std::remove_reference<_Tp>::type&&>(t); }
private:
void SetIndex(s64 index);
void SetupButtons();

View File

@@ -5,6 +5,7 @@
#include <memory>
#include <map>
#include <unordered_map>
#include <concepts>
namespace sphaira::ui {
@@ -90,4 +91,7 @@ struct Widget : public Object {
bool m_pop{false};
};
template<typename T>
concept DerivedFromWidget = std::is_base_of_v<Widget, T>;
} // namespace sphaira::ui