Files
sphaira/sphaira/include/ui/popup_list.hpp
ITotalJustice 54d73a6d3b optimise: pass all large objects (std::function, std::string, structs) by const ref rather than value.
really, these functions should be passed by && and using std::forward on assignment.
however, this means writing a lot of extra code for every single class, as well as explicitly calling move
in a lot of cases.

In the case of std::string, passing by value and calling std::move is the correct approach, especially if the
string is created as an rvalue, then it is only created once and moved into the dest.
Whereas with a const ref, the string is created and then copied into the dst, basically creating 2 copies.
The same thing happens std::function, and well any object.

However, accepting everything by value sucks if you call a constructor from within a constructor, as now you need to create 2 impls
that accept by value and the other by rvalue. All of this extra code to have a more efficent impl just isn't worth it when, going by
the benchmarks, makes no measurable difference (i count anything within >= 1ms as measurable).
2025-08-04 18:58:20 +01:00

51 lines
1.6 KiB
C++

#pragma once
#include "ui/widget.hpp"
#include "ui/scrolling_text.hpp"
#include "ui/list.hpp"
#include <optional>
namespace sphaira::ui {
class PopupList final : public Widget {
public:
using Items = std::vector<std::string>;
using Callback = std::function<void(std::optional<s64>)>;
public:
explicit PopupList(const std::string& title, const Items& items, const Callback& cb, s64 index = 0);
PopupList(const std::string& title, const Items& items, const Callback& cb, const std::string& index);
PopupList(const std::string& title, const Items& items, std::string& index_str_ref, s64& index);
PopupList(const std::string& title, const Items& items, std::string& index_ref);
PopupList(const std::string& title, const Items& items, s64& index_ref);
auto Update(Controller* controller, TouchInfo* touch) -> void override;
auto Draw(NVGcontext* vg, Theme* theme) -> void override;
auto OnFocusGained() noexcept -> void override;
auto OnFocusLost() noexcept -> void override;
private:
void SetIndex(s64 index);
private:
static constexpr Vec2 m_title_pos{70.f, 28.f};
static constexpr Vec4 m_block{280.f, 110.f, SCREEN_HEIGHT, 60.f};
static constexpr float m_text_xoffset{15.f};
static constexpr float m_line_width{1220.f};
const std::string m_title;
const Items m_items;
Callback m_callback{};
s64 m_index{}; // index in list array
s64 m_starting_index{};
std::unique_ptr<List> m_list{};
ScrollingText m_scroll_text{};
float m_yoff{};
float m_line_top{};
float m_line_bottom{};
};
} // namespace sphaira::ui