add font icont init

This commit is contained in:
chatlanin 2023-03-21 13:50:16 +03:00
parent 116fda7579
commit 2ac50173a3
3 changed files with 60 additions and 49 deletions

View File

@ -21,6 +21,16 @@ namespace tr::layers
BEGIN_IMGUI_WIN(); BEGIN_IMGUI_WIN();
ImFont* font = try_engine::style::fonts::get_font(font_type::ICON, 18);
ImGui::PushFont(font);
if (ImGui::Button(try_engine::style::icon::ICON_STOP, ImVec2(28, 30))) {}
// ImGui::Text(try_engine::style::icon::ICON_PAINT_BRUSH " Paint" );
ImGui::Text("\xef\x87\xbc");
ImGui::PopFont();
END_IMGUI_WIN(); END_IMGUI_WIN();
} }

View File

@ -6,6 +6,8 @@ namespace tr::layers
{ {
class test_panel : public try_engine::layer class test_panel : public try_engine::layer
{ {
using font_type = try_engine::style::fonts::font_type;
BASE_TYPE_DEFINE(); BASE_TYPE_DEFINE();
public: public:

View File

@ -16,70 +16,46 @@ namespace try_engine::style::fonts
enum font_type enum font_type
{ {
BLACK, BLACK_ITALIC, BOLD, BOLD_ITALIC, EXTRA_BOLD, EXTRA_BOLD_ITALIC, EXTRA_LIGHT, EXTRA_LIGHT_ITALIC, BLACK, BLACK_ITALIC, BOLD, BOLD_ITALIC, EXTRA_BOLD, EXTRA_BOLD_ITALIC, EXTRA_LIGHT, EXTRA_LIGHT_ITALIC,
ITALIC, LIGHT, LIGHT_ITALIC, MEDIUM, MEDIUM_ITALIC, REGULAR, SEMI_BOLD, SEMI_BOLD_ITALIC, THIN, THIN_ITALIC ITALIC, LIGHT, LIGHT_ITALIC, MEDIUM, MEDIUM_ITALIC, REGULAR, SEMI_BOLD, SEMI_BOLD_ITALIC, THIN, THIN_ITALIC, ICON
}; };
// HERE // HERE
// эту порнографию с путями нужно решить // эту порнографию с путями нужно решить
inline const std::string ICONS_PATH = "/mnt/develop/projects/cpp/try_engine/src/try_engine/internal/fonts/FontAwesome/forkawesome-webfont.ttf"; inline const std::string ICONS_PATH = "/mnt/develop/projects/cpp/try_engine/src/try_engine/internal/fonts/FontAwesome/forkawesome-webfont.ttf";
inline const std::string FONT_PATH = "/mnt/develop/projects/cpp/try_engine/src/try_engine/internal/fonts/Montserrat/"; inline const std::string FONT_PATH = "/mnt/develop/projects/cpp/try_engine/src/try_engine/internal/fonts/";
inline std::vector<std::string> fonts_path inline std::vector<std::string> fonts_path
{ {
FONT_PATH + "Montserrat-Black.ttf", FONT_PATH + "Montserrat/Montserrat-Black.ttf",
FONT_PATH + "Montserrat-BlackItalic.ttf", FONT_PATH + "Montserrat/Montserrat-BlackItalic.ttf",
FONT_PATH + "Montserrat-Bold.ttf", FONT_PATH + "Montserrat/Montserrat-Bold.ttf",
FONT_PATH + "Montserrat-BoldItalic.ttf", FONT_PATH + "Montserrat/Montserrat-BoldItalic.ttf",
FONT_PATH + "Montserrat-ExtraBold.ttf", FONT_PATH + "Montserrat/Montserrat-ExtraBold.ttf",
FONT_PATH + "Montserrat-ExtraBoldItalic.ttf", FONT_PATH + "Montserrat/Montserrat-ExtraBoldItalic.ttf",
FONT_PATH + "Montserrat-ExtraLight.ttf", FONT_PATH + "Montserrat/Montserrat-ExtraLight.ttf",
FONT_PATH + "Montserrat-ExtraLightItalic.ttf", FONT_PATH + "Montserrat/Montserrat-ExtraLightItalic.ttf",
FONT_PATH + "Montserrat-Italic.ttf", FONT_PATH + "Montserrat/Montserrat-Italic.ttf",
FONT_PATH + "Montserrat-Light.ttf", FONT_PATH + "Montserrat/Montserrat-Light.ttf",
FONT_PATH + "Montserrat-LightItalic.ttf", FONT_PATH + "Montserrat/Montserrat-LightItalic.ttf",
FONT_PATH + "Montserrat-Medium.ttf", FONT_PATH + "Montserrat/Montserrat-Medium.ttf",
FONT_PATH + "Montserrat-MediumItalic.ttf", FONT_PATH + "Montserrat/Montserrat-MediumItalic.ttf",
FONT_PATH + "Montserrat-Regular.ttf", FONT_PATH + "Montserrat/Montserrat-Regular.ttf",
FONT_PATH + "Montserrat-SemiBold.ttf", FONT_PATH + "Montserrat/Montserrat-SemiBold.ttf",
FONT_PATH + "Montserrat-SemiBoldItalic.ttf", FONT_PATH + "Montserrat/Montserrat-SemiBoldItalic.ttf",
FONT_PATH + "Montserrat-Thin.ttf", FONT_PATH + "Montserrat/Montserrat-Thin.ttf",
FONT_PATH + "Montserrat-ThinItalic.ttf" FONT_PATH + "Montserrat/Montserrat-ThinItalic.ttf"
}; };
inline void init() inline std::map<font_type, int> font_step
{
ImGuiIO& io = ImGui::GetIO();
float size_pixels = 16.0f;
static const ImWchar icon_ranges[] = { ICON_MIN_FK, ICON_MAX_FK, 0 };
for (auto& p : fonts_path)
for (auto size : font_size)
io.Fonts->AddFontFromFileTTF(p.c_str(), size, NULL, io.Fonts->GetGlyphRangesCyrillic());
// icons
// HERE а будет ли без этого показываться иконки ???
io.Fonts->AddFontFromFileTTF(ICONS_PATH.c_str(), size_pixels, NULL, icon_ranges);
};
inline ImFont* get_font(font_type type = font_type::REGULAR, int size = 16)
{
if (size < 0) size = 8;
if (size > 33) size = 33;
size -= 8; // т.к. font_size насинается с 8.f
ImGuiIO& io = ImGui::GetIO();
ImFontAtlas* atlas = io.Fonts;
std::map<font_type, int> font_step
{ {
{ font_type::BLACK, 0 }, { font_type::BLACK, 0 },
{ font_type::BLACK_ITALIC, 26 }, { font_type::BLACK_ITALIC, 26 },
@ -99,10 +75,33 @@ namespace try_engine::style::fonts
{ font_type::SEMI_BOLD_ITALIC, 390 }, { font_type::SEMI_BOLD_ITALIC, 390 },
{ font_type::THIN, 416 }, { font_type::THIN, 416 },
{ font_type::THIN_ITALIC, 442 }, { font_type::THIN_ITALIC, 442 },
{ font_type::ICON, 468 },
}; };
auto pos = font_step[type] + size; inline void init()
{
ImGuiIO& io = ImGui::GetIO();
for (auto& p : fonts_path)
for (auto size : font_size)
io.Fonts->AddFontFromFileTTF(p.c_str(), size, NULL, io.Fonts->GetGlyphRangesCyrillic());
// add icon font size
static const ImWchar icon_ranges[] = { ICON_MIN_FK, ICON_MAX_FK, 0 };
for (auto size : font_size)
io.Fonts->AddFontFromFileTTF(ICONS_PATH.c_str(), size, NULL, icon_ranges);
};
inline ImFont* get_font(font_type type = font_type::REGULAR, int size = 16)
{
if (size < 0) size = 8;
if (size > 33) size = 33;
size -= 8; // т.к. font_size начинается с 8.f
ImGuiIO& io = ImGui::GetIO();
ImFontAtlas* atlas = io.Fonts;
auto pos = font_step[type] + size;
return atlas->Fonts[pos]; return atlas->Fonts[pos];
}; };
} }