MeshLib Documentation
Loading...
Searching...
No Matches
MRRibbonFontManager.h
Go to the documentation of this file.
1#pragma once
2#include "imgui.h"
3#include <array>
4#include "exports.h"
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 SemiBold,
33 Monospace,
34 Icons,
35 Count
36 };
37
38 using FontFilePaths = std::array<std::filesystem::path, size_t( FontFile::Count )>;
39
40 MRVIEWER_API RibbonFontManager();
41
43 MRVIEWER_API void loadAllFonts( ImWchar* charRanges, float scaling );
44
46 MRVIEWER_API ImFont* getFontByType( FontType type ) const;
48 MRVIEWER_API static float getFontSizeByType( FontType type );
49
51 MRVIEWER_API std::filesystem::path getMenuFontPath() const;
52
54 const FontFilePaths& getAllFontPaths() const { return fontPaths_; }
55
58 MRVIEWER_API void setNewFontPaths( const FontFilePaths& paths );
59
62 MRVIEWER_API static ImFont* getFontByTypeStatic( FontType type );
63
66 MRVIEWER_API static void initFontManagerInstance( RibbonFontManager* ribbonFontManager );
67
68private:
69 FontFilePaths fontPaths_;
70 struct FontData
71 {
72 FontFile fontFile{ FontFile::Regular }; // what file type to use for this font
73 Vector2f scaledOffset; // offset that is used for each glyph while creating atlas (updates in `updateFontsScaledOffset_`), should respect font size with scaling
74 ImFont* fontPtr{ nullptr }; // pointer to loaded font, nullptr means that font was not loaded
75 };
76 std::array<FontData, size_t( FontType::Count )> fonts_;
77
79 static RibbonFontManager*& getFontManagerInstance_();
80
82 void updateFontsScaledOffset_( float scaling );
83
84 void loadFont_( FontType type, const ImWchar* ranges, float scaling );
85
86 struct CustomGlyph
87 {
88 std::function<void( unsigned char* texData, int texW )> render;
89 };
90 void addCustomGlyphs_( FontType font, float scaling, std::vector<CustomGlyph>& glyphs );
91 void renderCustomGlyphsToAtlas_( const std::vector<CustomGlyph>& glyphs );
92};
93
94}
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:54
std::array< std::filesystem::path, size_t(FontFile::Count)> FontFilePaths
Definition MRRibbonFontManager.h:38
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, float scaling)
load all fonts using in ribbon menu
MRVIEWER_API std::filesystem::path getMenuFontPath() const
get ribbon menu font path
Definition MRCameraOrientationPlugin.h:8