diff --git a/src/sandbox/layers/test_panel/test_panel.cpp b/src/sandbox/layers/test_panel/test_panel.cpp index 7844574..db44612 100644 --- a/src/sandbox/layers/test_panel/test_panel.cpp +++ b/src/sandbox/layers/test_panel/test_panel.cpp @@ -21,6 +21,16 @@ namespace tr::layers 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(); } diff --git a/src/sandbox/layers/test_panel/test_panel.hpp b/src/sandbox/layers/test_panel/test_panel.hpp index 33081b7..c0e56c0 100644 --- a/src/sandbox/layers/test_panel/test_panel.hpp +++ b/src/sandbox/layers/test_panel/test_panel.hpp @@ -6,6 +6,8 @@ namespace tr::layers { class test_panel : public try_engine::layer { + using font_type = try_engine::style::fonts::font_type; + BASE_TYPE_DEFINE(); public: diff --git a/src/try_engine/gui/style/fonts.hpp b/src/try_engine/gui/style/fonts.hpp index 91427f2..d355c97 100644 --- a/src/try_engine/gui/style/fonts.hpp +++ b/src/try_engine/gui/style/fonts.hpp @@ -16,93 +16,92 @@ namespace try_engine::style::fonts enum font_type { 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 // эту порнографию с путями нужно решить 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 fonts_path { - FONT_PATH + "Montserrat-Black.ttf", - FONT_PATH + "Montserrat-BlackItalic.ttf", + FONT_PATH + "Montserrat/Montserrat-Black.ttf", + FONT_PATH + "Montserrat/Montserrat-BlackItalic.ttf", - FONT_PATH + "Montserrat-Bold.ttf", - FONT_PATH + "Montserrat-BoldItalic.ttf", + FONT_PATH + "Montserrat/Montserrat-Bold.ttf", + FONT_PATH + "Montserrat/Montserrat-BoldItalic.ttf", - FONT_PATH + "Montserrat-ExtraBold.ttf", - FONT_PATH + "Montserrat-ExtraBoldItalic.ttf", + FONT_PATH + "Montserrat/Montserrat-ExtraBold.ttf", + FONT_PATH + "Montserrat/Montserrat-ExtraBoldItalic.ttf", - FONT_PATH + "Montserrat-ExtraLight.ttf", - FONT_PATH + "Montserrat-ExtraLightItalic.ttf", + FONT_PATH + "Montserrat/Montserrat-ExtraLight.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-LightItalic.ttf", + FONT_PATH + "Montserrat/Montserrat-Light.ttf", + FONT_PATH + "Montserrat/Montserrat-LightItalic.ttf", - FONT_PATH + "Montserrat-Medium.ttf", - FONT_PATH + "Montserrat-MediumItalic.ttf", + FONT_PATH + "Montserrat/Montserrat-Medium.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-SemiBoldItalic.ttf", + FONT_PATH + "Montserrat/Montserrat-SemiBold.ttf", + FONT_PATH + "Montserrat/Montserrat-SemiBoldItalic.ttf", - FONT_PATH + "Montserrat-Thin.ttf", - FONT_PATH + "Montserrat-ThinItalic.ttf" + FONT_PATH + "Montserrat/Montserrat-Thin.ttf", + FONT_PATH + "Montserrat/Montserrat-ThinItalic.ttf" + }; + + inline std::map font_step + { + { font_type::BLACK, 0 }, + { font_type::BLACK_ITALIC, 26 }, + { font_type::BOLD, 52 }, + { font_type::BOLD_ITALIC, 78 }, + { font_type::EXTRA_BOLD, 104 }, + { font_type::EXTRA_BOLD_ITALIC, 130 }, + { font_type::EXTRA_LIGHT, 156 }, + { font_type::EXTRA_LIGHT_ITALIC, 182 }, + { font_type::ITALIC, 208 }, + { font_type::LIGHT, 234 }, + { font_type::LIGHT_ITALIC, 260 }, + { font_type::MEDIUM, 286 }, + { font_type::MEDIUM_ITALIC, 312 }, + { font_type::REGULAR, 338 }, + { font_type::SEMI_BOLD, 364 }, + { font_type::SEMI_BOLD_ITALIC, 390 }, + { font_type::THIN, 416 }, + { font_type::THIN_ITALIC, 442 }, + { font_type::ICON, 468 }, }; inline void init() { 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); + // 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 + size -= 8; // т.к. font_size начинается с 8.f ImGuiIO& io = ImGui::GetIO(); ImFontAtlas* atlas = io.Fonts; - std::map font_step - { - { font_type::BLACK, 0 }, - { font_type::BLACK_ITALIC, 26 }, - { font_type::BOLD, 52 }, - { font_type::BOLD_ITALIC, 78 }, - { font_type::EXTRA_BOLD, 104 }, - { font_type::EXTRA_BOLD_ITALIC, 130 }, - { font_type::EXTRA_LIGHT, 156 }, - { font_type::EXTRA_LIGHT_ITALIC, 182 }, - { font_type::ITALIC, 208 }, - { font_type::LIGHT, 234 }, - { font_type::LIGHT_ITALIC, 260 }, - { font_type::MEDIUM, 286 }, - { font_type::MEDIUM_ITALIC, 312 }, - { font_type::REGULAR, 338 }, - { font_type::SEMI_BOLD, 364 }, - { font_type::SEMI_BOLD_ITALIC, 390 }, - { font_type::THIN, 416 }, - { font_type::THIN_ITALIC, 442 }, - }; - auto pos = font_step[type] + size; - return atlas->Fonts[pos]; }; }