Polyphase Game Engine
Loading...
Searching...
No Matches
ComboBox.h
Go to the documentation of this file.
1#pragma once
2
4
5class Texture;
6class Quad;
7class Text;
8class Button;
9class Canvas;
10
12{
13public:
14
16
17 virtual void Create() override;
18 virtual void GatherProperties(std::vector<Property>& props) override;
19 virtual void Tick(float deltaTime) override;
20 virtual void EditorTick(float deltaTime) override;
21 virtual void PreRender() override;
22
23 // Options
24 void AddOption(const std::string& option);
25 void RemoveOption(int32_t index);
26 void ClearOptions();
27 void SetOptions(const std::vector<std::string>& options);
28 const std::vector<std::string>& GetOptions() const;
29 int32_t GetOptionCount() const;
30
31 // Selection
32 void SetSelectedIndex(int32_t index);
33 int32_t GetSelectedIndex() const;
34 std::string GetSelectedOption() const;
35
36 // State
37 bool IsOpen() const;
38 void Open();
39 void Close();
40 void Toggle();
41
42 // Visual
43 void SetBackgroundColor(glm::vec4 color);
44 glm::vec4 GetBackgroundColor();
45 void SetTextColor(glm::vec4 color);
46 glm::vec4 GetTextColor();
47 void SetDropdownColor(glm::vec4 color);
48 glm::vec4 GetDropdownColor();
49 void SetHoveredColor(glm::vec4 color);
50 glm::vec4 GetHoveredColor();
51 void SetMaxVisibleItems(int32_t count);
52 int32_t GetMaxVisibleItems() const;
53
54 // Children
55 Quad* GetBackground();
56 Text* GetTextWidget();
57
58 // Input handling
59 static void SetHandleMouse(bool inHandle);
60 static void SetHandleKeyboard(bool inHandle);
61 static void SetHandleGamepad(bool inHandle);
62
63protected:
64
65 void CycleSelectedIndex(int32_t delta);
66 void CycleHoveredIndex(int32_t delta);
67
68 static bool HandlePropChange(Datum* datum, uint32_t index, const void* newValue);
69
70 void UpdateAppearance();
71 void UpdateDropdown();
72 void CreateDropdownItems();
73 void DestroyDropdownItems();
74 void SyncOptionsString();
75
76 // Options
77 std::vector<std::string> mOptions;
78 std::string mOptionsString; // Newline-separated options for editor
79 int32_t mSelectedIndex = -1;
80
81 // State
82 bool mIsOpen = false;
83 int32_t mHoveredIndex = -1;
84 int32_t mScrollOffset = 0; // First visible item index in dropdown
85
86 // Visual
88 glm::vec4 mBackgroundColor = { 0.25f, 0.25f, 0.25f, 1.0f };
89 glm::vec4 mTextColor = { 1.0f, 1.0f, 1.0f, 1.0f };
90 glm::vec4 mDropdownColor = { 0.2f, 0.2f, 0.2f, 1.0f };
91 glm::vec4 mHoveredColor = { 0.35f, 0.35f, 0.35f, 1.0f };
92 glm::vec4 mArrowColor = { 0.7f, 0.7f, 0.7f, 1.0f };
93 float mArrowWidth = 20.0f;
94 float mItemHeight = 24.0f;
95 int32_t mMaxVisibleItems = 5;
96
97 // Children
98 Quad* mBackground = nullptr;
99 Text* mText = nullptr;
100 Quad* mArrow = nullptr;
101
102 // Dropdown (created dynamically when open)
103 Canvas* mDropdownCanvas = nullptr;
104 std::vector<Quad*> mDropdownItems;
105 std::vector<Text*> mDropdownTexts;
106
107 // Static input flags
108 static bool sHandleMouseInput;
111};
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
Definition AssetRef.h:18
Definition Button.h:21
Definition Canvas.h:9
Definition ComboBox.h:12
std::string mOptionsString
Definition ComboBox.h:78
static bool sHandleKeyboardInput
Definition ComboBox.h:109
TextureRef mBackgroundTexture
Definition ComboBox.h:87
DECLARE_NODE(ComboBox, Widget)
std::vector< std::string > mOptions
Definition ComboBox.h:77
std::vector< Quad * > mDropdownItems
Definition ComboBox.h:104
static bool sHandleMouseInput
Definition ComboBox.h:108
static bool sHandleGamepadInput
Definition ComboBox.h:110
std::vector< Text * > mDropdownTexts
Definition ComboBox.h:105
Definition Datum.h:164
virtual void EditorTick(float deltaTime)
Definition Node.cpp:563
virtual void Create()
Definition Node.cpp:220
virtual void Tick(float deltaTime)
Definition Node.cpp:558
Definition Quad.h:20
Definition Text.h:24
Definition Texture.h:10
Definition Widget.h:53
static bool HandlePropChange(Datum *datum, uint32_t index, const void *newValue)
Definition Widget.cpp:45
virtual void GatherProperties(std::vector< Property > &outProps) override
Definition Widget.cpp:115
virtual void PreRender()
Definition Widget.cpp:226