Plutonium framework API  0.1
Simple UI framework for libnx and SDL2
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/element/Element.hpp>
16 #include <vector>
17 #include <functional>
18 
19 namespace pu::element
20 {
21  class MenuItem
22  {
23  public:
24  MenuItem(std::string Name);
25  ~MenuItem();
26  std::string GetName();
27  void SetName(std::string Name);
29  void SetColor(draw::Color Color);
30  void AddOnClick(std::function<void()> Callback, u64 Key = KEY_A);
31  u32 GetCallbackCount();
32  std::function<void()> GetCallback(u32 Index);
33  u64 GetCallbackKey(u32 Index);
34  std::string GetIcon();
35  void SetIcon(std::string Icon);
36  bool HasIcon();
40  private:
41  std::string name;
42  draw::Color clr;
43  bool hasicon;
44  std::string icon;
45  std::vector<std::function<void()>> cbs;
46  std::vector<u64> cbipts;
47  render::NativeFont font;
50  };
51 
52  class Menu : public Element
53  {
54  public:
55  Menu(u32 X, u32 Y, u32 Width, draw::Color OptionColor, u32 ItemSize, u32 ItemsToShow);
56  ~Menu();
57  u32 GetX();
58  void SetX(u32 X);
59  u32 GetY();
60  void SetY(u32 Y);
61  u32 GetWidth();
62  void SetWidth(u32 Width);
63  u32 GetHeight();
64  u32 GetItemSize();
65  void SetItemSize(u32 ItemSize);
67  void SetNumberOfItemsToShow(u32 ItemsToShow);
69  void SetColor(draw::Color Color);
71  void SetOnFocusColor(draw::Color Color);
73  void SetScrollbarColor(draw::Color Color);
74  void SetOnSelectionChanged(std::function<void()> Callback);
75  void AddItem(MenuItem *Item);
76  void ClearItems();
77  void SetCooldownEnabled(bool Cooldown);
79  u32 GetSelectedIndex();
80  void SetSelectedIndex(u32 Index);
81  void OnRender(render::Renderer *Drawer);
82  void OnInput(u64 Down, u64 Up, u64 Held, bool Touch, bool Focus);
83  private:
84  bool dtouch;
85  u32 x;
86  u32 y;
87  u32 w;
88  u32 isize;
89  u32 ishow;
90  u32 previsel;
91  u32 fisel;
92  u32 isel;
93  s32 pselfact;
94  s32 selfact;
95  draw::Color scb;
96  draw::Color clr;
97  draw::Color fcs;
98  bool icdown;
99  std::function<void()> onselch;
100  std::vector<MenuItem*> itms;
101  };
102 }
u32 GetNumberOfItemsToShow()
void SetIcon(std::string Icon)
Definition: Renderer.hpp:22
Menu(u32 X, u32 Y, u32 Width, draw::Color OptionColor, u32 ItemSize, u32 ItemsToShow)
Definition: Menu.hpp:21
draw::Color GetColor()
void SetScrollbarColor(draw::Color Color)
std::function< void()> GetCallback(u32 Index)
draw::Color GetOnFocusColor()
draw::Color GetColor()
void SetY(u32 Y)
std::string GetName()
TTF_Font * NativeFont
Definition: SDL2.hpp:17
Definition: Button.hpp:18
void SetItemSize(u32 ItemSize)
void SetColor(draw::Color Color)
void SetName(std::string Name)
Definition: Element.hpp:27
void SetOnSelectionChanged(std::function< void()> Callback)
void SetColor(draw::Color Color)
void SetSelectedIndex(u32 Index)
void SetWidth(u32 Width)
void SetNumberOfItemsToShow(u32 ItemsToShow)
render::NativeTexture GetIconTexture()
Definition: Menu.hpp:52
draw::Color GetScrollbarColor()
void OnInput(u64 Down, u64 Up, u64 Held, bool Touch, bool Focus)
u64 GetCallbackKey(u32 Index)
std::string GetIcon()
MenuItem * GetSelectedItem()
void SetX(u32 X)
SDL_Texture * NativeTexture
Definition: SDL2.hpp:16
void AddOnClick(std::function< void()> Callback, u64 Key=KEY_A)
void SetCooldownEnabled(bool Cooldown)
void AddItem(MenuItem *Item)
MenuItem(std::string Name)
Definition: Color.hpp:19
render::NativeFont GetFont()
render::NativeTexture GetNameTexture()
void SetOnFocusColor(draw::Color Color)
void OnRender(render::Renderer *Drawer)