Plutonium framework API  0.3
Simple UI framework for libnx and SDL2
elm_Menu.hpp
Go to the documentation of this file.
1 
2 /*
3 
4  Plutonium library
5 
6  @file Menu.hpp
7  @brief A Menu is a very useful Element for option browsing or selecting.
8  @author XorTroll
9 
10  @copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
11 
12 */
13 
14 #pragma once
15 #include <pu/pu_String.hpp>
17 #include <vector>
18 #include <chrono>
19 #include <functional>
20 
21 namespace pu::ui::elm
22 {
23  class MenuItem
24  {
25  public:
26  MenuItem(String Name);
28 
29  String GetName();
30  void SetName(String Name);
31  Color GetColor();
32  void SetColor(Color Color);
33  void AddOnClick(std::function<void()> Callback, u64 Key = KEY_A);
35  std::function<void()> GetCallback(i32 Index);
36  u64 GetCallbackKey(i32 Index);
37  std::string GetIcon();
38  void SetIcon(std::string Icon);
39  bool HasIcon();
40  private:
41  String name;
42  Color clr;
43  bool hasicon;
44  std::string icon;
45  std::vector<std::function<void()>> cbs;
46  std::vector<u64> cbipts;
47  };
48 
49  class Menu : public Element
50  {
51  public:
52  Menu(i32 X, i32 Y, i32 Width, Color OptionColor, i32 ItemSize, i32 ItemsToShow);
54 
55  i32 GetX();
56  void SetX(i32 X);
57  i32 GetY();
58  void SetY(i32 Y);
59  i32 GetWidth();
60  void SetWidth(i32 Width);
61  i32 GetHeight();
62  i32 GetItemSize();
63  void SetItemSize(i32 ItemSize);
64  i32 GetNumberOfItemsToShow();
65  void SetNumberOfItemsToShow(i32 ItemsToShow);
66  Color GetColor();
67  void SetColor(Color Color);
68  Color GetOnFocusColor();
69  void SetOnFocusColor(Color Color);
70  Color GetScrollbarColor();
71  void SetScrollbarColor(Color Color);
72  void SetOnSelectionChanged(std::function<void()> Callback);
73  void AddItem(MenuItem::Ref &Item);
74  void ClearItems();
75  void SetCooldownEnabled(bool Cooldown);
76  MenuItem::Ref &GetSelectedItem();
77  std::vector<MenuItem::Ref> &GetItems();
78  i32 GetSelectedIndex();
79  void SetSelectedIndex(i32 Index);
80  void OnRender(render::Renderer::Ref &Drawer, i32 X, i32 Y);
81  void OnInput(u64 Down, u64 Up, u64 Held, Touch Pos);
82  private:
83  void ReloadItemRenders();
84  bool dtouch;
85  i32 x;
86  i32 y;
87  i32 w;
88  i32 isize;
89  i32 ishow;
90  i32 previsel;
91  i32 fisel;
92  i32 isel;
93  i32 pselfact;
94  i32 selfact;
95  Color scb;
96  Color clr;
97  Color fcs;
98  bool icdown;
99  int basestatus;
100  std::chrono::time_point<std::chrono::steady_clock> basetime;
101  std::function<void()> onselch;
102  std::vector<MenuItem::Ref> itms;
103  String font_name;
104  std::vector<sdl2::Texture> loadednames;
105  std::vector<sdl2::Texture> loadedicons;
106  };
107 }
Definition: elm_Button.hpp:19
Definition: elm_Menu.hpp:49
void AddOnClick(std::function< void()> Callback, u64 Key=KEY_A)
Definition: pu_String.hpp:21
void SetIcon(std::string Icon)
Definition: ui_Types.hpp:24
void SetName(String Name)
Definition: ui_Types.hpp:38
u64 GetCallbackKey(i32 Index)
void SetColor(Color Color)
MenuItem(String Name)
Definition: elm_Menu.hpp:23
s32 i32
Definition: pu_Macros.hpp:17
#define PU_SMART_CTOR(type)
Definition: pu_Macros.hpp:8
std::string GetIcon()
Definition: elm_Element.hpp:34
std::function< void()> GetCallback(i32 Index)