Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
EnumSelector.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <map>
5#include <string>
6
7#include <glm/glm.hpp>
8#include "imgui.h"
9
10namespace shkyera {
11
12template <typename EnumType>
14 public:
15 EnumSelector(const std::string& title, EnumType value, const std::map<EnumType, std::string>& options)
17
19
20 void draw() {
22 ImGui::PushItemWidth(50);
23 ImGui::TextUnformatted(_title.c_str());
24 ImGui::PopItemWidth();
25
26 ImGui::SameLine(130);
27 ImGui::PushItemWidth(190);
28
29 if (ImGui::BeginCombo((std::string("##" + _title + "EnumSelectorCombo").c_str()), _options.at(_value).c_str())) {
30 for (const auto& [value, name] : _options) {
31 if (ImGui::Selectable(name.c_str())) {
32 _value = value;
33 }
34 }
35
36 ImGui::EndCombo();
37 }
38
39 ImGui::PopItemWidth();
40
41 if (oldValue != _value) {
42 if (_updateCallback) {
44 }
45 }
46 }
47
48 private:
49 std::string _title;
51 std::map<EnumType, std::string> _options;
53};
54
55} // namespace shkyera
Definition EnumSelector.hpp:13
void draw()
Definition EnumSelector.hpp:20
void setUpdateCallback(std::function< void(EnumType value)> callback)
Definition EnumSelector.hpp:18
EnumSelector(const std::string &title, EnumType value, const std::map< EnumType, std::string > &options)
Definition EnumSelector.hpp:15
std::map< EnumType, std::string > _options
Definition EnumSelector.hpp:51
std::string _title
Definition EnumSelector.hpp:49
std::function< void(EnumType value)> _updateCallback
Definition EnumSelector.hpp:52
EnumType _value
Definition EnumSelector.hpp:50
Definition Asset.hpp:6
Definition Clock.hpp:9