Files
vertex_engine/src/vertex_engine/utils/func.hpp
2026-02-25 14:11:04 +03:00

46 lines
1.0 KiB
C++

#pragma once
#include <string>
#include <imgui.h>
namespace VE::func
{
inline auto name(std::string n, std::string key_no_name = "##")
{
return key_no_name + n;
}
inline ImU32 color(std::string hex, unsigned char alpha = 255)
{
if (hex[0] == '#') hex.erase(0, 1);
unsigned int r = 255;
unsigned int g = 255;
unsigned int b = 255;
if (hex.length() == 6) std::sscanf(hex.c_str(), "%2x%2x%2x", &r, &g, &b);
return IM_COL32(r, g, b, alpha);
}
inline ImVec4 color(std::string hex, float alpha = 1.f)
{
// Удаляем # если есть
if (!hex.empty() && hex[0] == '#') hex.erase(0, 1);
// Значения по умолчанию (белый)
unsigned int r = 255, g = 255, b = 255;
// Парсим HEX
if (hex.length() >= 6) std::sscanf(hex.c_str(), "%2x%2x%2x", &r, &g, &b);
// Конвертируем в float (0.0-1.0)
return ImVec4(
r / 255.0f,
g / 255.0f,
b / 255.0f,
alpha
);
}
}