SDOM - Simple SDL Document Object Model
A lightweight, extensible Document Object Model for SDL-based applications.
Loading...
Searching...
No Matches
SDOM_IconIndex.hpp
Go to the documentation of this file.
1// SDOM_IconIndex.hpp
2
3#pragma once
4
5#include <unordered_map>
6#include <string>
7#include <optional>
8
9namespace SDOM
10{
42
43 inline static const std::unordered_map<int, std::string> icon_index_to_string = {
44 { static_cast<int>(IconIndex::Hamburger), "hamburger" },
45 { static_cast<int>(IconIndex::Arrow_Left_Raised), "arrow_left_raised" },
46 { static_cast<int>(IconIndex::Arrow_Right_Raised), "arrow_right_raised" },
47 { static_cast<int>(IconIndex::Arrow_Up_Raised), "arrow_up_raised" },
48 { static_cast<int>(IconIndex::Arrow_Down_Raised), "arrow_down_raised" },
49 { static_cast<int>(IconIndex::Arrow_Left_Depressed), "arrow_left_depressed" },
50 { static_cast<int>(IconIndex::Arrow_Right_Depressed), "arrow_right_depressed" },
51 { static_cast<int>(IconIndex::Arrow_Up_Depressed), "arrow_up_depressed" },
52 { static_cast<int>(IconIndex::Arrow_Down_Depressed), "arrow_down_depressed" },
53 { static_cast<int>(IconIndex::Knob_Horizontal), "knob_horizontal" },
54 { static_cast<int>(IconIndex::Knob_Vertical), "knob_vertical" },
55 { static_cast<int>(IconIndex::Slider_Tick), "slider_tick" },
56 { static_cast<int>(IconIndex::HSlider_Rail), "hslider_rail" },
57 { static_cast<int>(IconIndex::VSlider_Rail), "vslider_rail" },
58 { static_cast<int>(IconIndex::Checkbox_Empty), "empty_checkbox" },
59 { static_cast<int>(IconIndex::Checkbox_Checked), "checked_checkbox" },
60 { static_cast<int>(IconIndex::Checkbox_X), "x_checkbox" },
61 { static_cast<int>(IconIndex::Radiobox_Unselected), "radiobox_unselected" },
62 { static_cast<int>(IconIndex::Radiobox_Selected), "radiobox_selected" },
63 { static_cast<int>(IconIndex::HProgress_Left), "hprogress_left" },
64 { static_cast<int>(IconIndex::HProgress_Empty), "hprogress_empty" },
65 { static_cast<int>(IconIndex::HProgress_Thumb), "hprogress_thumb" },
66 { static_cast<int>(IconIndex::HProgress_Right), "hprogress_right" },
67 { static_cast<int>(IconIndex::VProgress_Top), "vprogress_top" },
68 { static_cast<int>(IconIndex::VProgress_Empty), "vprogress_empty" },
69 { static_cast<int>(IconIndex::VProgress_Thumb), "vprogress_thumb" },
70 { static_cast<int>(IconIndex::VProgress_Bottom), "vprogress_bottom" }
71 };
72
73 inline static const std::unordered_map<std::string, int> icon_string_to_index = []{
74 std::unordered_map<std::string,int> m;
75 for (auto &p : icon_index_to_string) {
76 std::string key = p.second;
77 std::transform(key.begin(), key.end(), key.begin(), [](unsigned char c){
78 return static_cast<char>(std::tolower(c));
79 });
80 m.emplace(std::move(key), p.first);
81 }
82 return m;
83 }();
84
85 inline static std::optional<std::string> icon_name_from_index(IconIndex idx)
86 {
87 auto it = icon_index_to_string.find(static_cast<int>(idx));
88 if (it == icon_index_to_string.end()) return std::nullopt;
89 std::string name = it->second;
90 std::transform(name.begin(), name.end(), name.begin(), [](unsigned char c){
91 return static_cast<char>(std::tolower(c));
92 });
93 return name;
94 }
95
96 inline static std::optional<IconIndex> icon_index_from_name(const std::string &name)
97 {
98 std::string key = name;
99 std::transform(key.begin(), key.end(), key.begin(), [](unsigned char c){
100 return static_cast<char>(std::tolower(c));
101 });
102 auto it = icon_string_to_index.find(key);
103 if (it == icon_string_to_index.end()) return std::nullopt;
104 return static_cast<IconIndex>(it->second);
105 }
106} // END: namespace SDOM
Contains all core classes and utilities for the SDOM library.
Definition lua_BindHelpers.hpp:7
IconIndex
Definition SDOM_IconIndex.hpp:12
static const std::unordered_map< std::string, int > icon_string_to_index
Definition SDOM_IconIndex.hpp:73
static std::optional< std::string > icon_name_from_index(IconIndex idx)
Definition SDOM_IconIndex.hpp:85
static std::optional< IconIndex > icon_index_from_name(const std::string &name)
Definition SDOM_IconIndex.hpp:96
static const std::unordered_map< int, std::string > icon_index_to_string
Definition SDOM_IconIndex.hpp:43