MeshLib C++ Docs
Loading...
Searching...
No Matches
MRRibbonFontManager.h
Go to the documentation of this file.
1#pragma once
2#include "exports.h"
3#include "MRImGui.h"
4#include <array>
5#include <filesystem>
6
7namespace MR
8{
9
10class MRVIEWER_CLASS RibbonFontManager
11{
12public:
13
14 // Font types used in current design
15 enum class FontType
16 {
17 Default,
18 Small,
19 SemiBold,
20 Icons,
21 Big,
22 BigSemiBold,
23 Headline,
24 Monospace,
25 Count
26 };
27
28 // Unique fonts that are used for different FontTypes
29 enum class FontFile
30 {
31 Regular,
32#ifndef __EMSCRIPTEN__
33 RegularSC, // Regular with Simple Chinese
34#endif
35 SemiBold,
36 Monospace,
37 Icons,
38 Count
39 };
40
41 using FontFilePaths = std::array<std::filesystem::path, size_t( FontFile::Count )>;
42
43 MRVIEWER_API RibbonFontManager();
44
46 MRVIEWER_API void loadAllFonts( ImWchar* charRanges );
47
49 MRVIEWER_API ImFont* getFontByType( FontType type ) const;
51 MRVIEWER_API static float getFontSizeByType( FontType type );
52
54 MRVIEWER_API std::filesystem::path getMenuFontPath() const;
55
57 const FontFilePaths& getAllFontPaths() const { return fontPaths_; }
58
61 MRVIEWER_API void setNewFontPaths( const FontFilePaths& paths );
62
65 MRVIEWER_API static ImFont* getFontByTypeStatic( FontType type );
66
69 MRVIEWER_API static void initFontManagerInstance( RibbonFontManager* ribbonFontManager );
70
71private:
72
73#ifndef __EMSCRIPTEN__
74 static constexpr RibbonFontManager::FontFile cFontFileRegular_ = RibbonFontManager::FontFile::RegularSC;
75#else
76 static constexpr RibbonFontManager::FontFile cFontFileRegular_ = RibbonFontManager::FontFile::Regular;
77#endif
78
79 FontFilePaths fontPaths_;
80 struct FontData
81 {
82 FontFile fontFile{ cFontFileRegular_ }; // what file type to use for this font
83 Vector2f scaledOffset; // offset that is used for each glyph while creating atlas (updates in `updateFontsScaledOffset_`), should respect font size with scaling
84 ImFont* fontPtr{ nullptr }; // pointer to loaded font, nullptr means that font was not loaded
85 };
86 std::array<FontData, size_t( FontType::Count )> fonts_;
87
89 static RibbonFontManager*& getFontManagerInstance_();
90
92 void updateFontsScaledOffset_();
93
94 void loadFont_( FontType type, const ImWchar* ranges );
95
96 struct CustomGlyph
97 {
98 std::function<void( unsigned char* texData, int texW )> render;
99 };
100 void addCustomGlyphs_( FontType font, std::vector<CustomGlyph>& glyphs );
101 void renderCustomGlyphsToAtlas_( const std::vector<CustomGlyph>& glyphs );
102};
103
104}
Definition MRRibbonFontManager.h:11
static MRVIEWER_API void initFontManagerInstance(RibbonFontManager *ribbonFontManager)
static MRVIEWER_API float getFontSizeByType(FontType type)
get font size by font type
FontFile
Definition MRRibbonFontManager.h:30
static MRVIEWER_API ImFont * getFontByTypeStatic(FontType type)
MRVIEWER_API void setNewFontPaths(const FontFilePaths &paths)
const FontFilePaths & getAllFontPaths() const
returns list of all font paths
Definition MRRibbonFontManager.h:57
std::array< std::filesystem::path, size_t(FontFile::Count)> FontFilePaths
Definition MRRibbonFontManager.h:41
FontType
Definition MRRibbonFontManager.h:16
MRVIEWER_API RibbonFontManager()
MRVIEWER_API ImFont * getFontByType(FontType type) const
get font by font type
MRVIEWER_API void loadAllFonts(ImWchar *charRanges)
load all fonts using in ribbon menu
MRVIEWER_API std::filesystem::path getMenuFontPath() const
get ribbon menu font path
Definition MRCameraOrientationPlugin.h:8