Тьомчик
-
Автор темы
- #1
Я не знаю зачем
C++:
enum e_mode {
activated,
hovered,
disabled,
count
};
using color_map = std::unordered_map<std::string, ImColor>;
class theme_colors_t {
protected:
color_map activated = {
{ "text", ImColor(255, 255, 255, 255) }
};
color_map hovered = {
{ "text", ImColor(200, 200, 200, 255) }
};
color_map disabled = {
{ "text", ImColor(0, 0, 0, 255) }
};
color_map colors[count];
private:
void setup_colors(e_mode state, const color_map& color_map) {
colors[state] = color_map;
}
void setup_activated_colors() {
setup_colors(e_mode::activated, activated);
}
void setup_hovered_colors() {
setup_colors(e_mode::hovered, hovered);
}
void setup_disabled_colors() {
setup_colors(e_mode::disabled, disabled);
}
public:
theme_colors_t() {
setup_activated_colors();
setup_hovered_colors();
setup_disabled_colors();
}
ImColor get_color(e_mode state, const std::string& element) const {
auto it = colors[state].find(element);
if (it != colors[state].end()) {
return ImGui::ColorConvertFloat4ToU32(it->second);
}
return ImGui::ColorConvertFloat4ToU32(ImColor(255, 255, 255, 255));
}
};
взаимодействие:
get_color(e_mode::disabled, "text");
Последнее редактирование: