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 "MRViewerFwd.h"
4#include "MRImGui.h"
5#include <array>
6#include <filesystem>
7
8namespace MR
9{
10
11class MRVIEWER_CLASS RibbonFontManager
12{
13public:
14
15 // Font types used in current design
16 enum class FontType
17 {
18 Default,
19 Small,
20 Middle,
21 SemiBold,
22 Icons,
23 Big,
24 BigSemiBold,
25 Headline,
26 Monospace,
27 Count
28 };
29
30 // Unique fonts that are used for different FontTypes
31 enum class FontFile
32 {
33 Regular,
34#ifndef __EMSCRIPTEN__
35 RegularSC, // Regular with Simple Chinese
36#endif
37 SemiBold,
38 Monospace,
39 Icons,
40 Count
41 };
42
43 using FontFilePaths = std::array<std::filesystem::path, size_t( FontFile::Count )>;
44
45 MRVIEWER_API RibbonFontManager();
46
48 MRVIEWER_API void loadAllFonts( ImWchar* charRanges );
49
51 MRVIEWER_API ImFont* getFontByType( FontType type ) const;
53 MRVIEWER_API static float getFontSizeByType( FontType type );
54
56 MRVIEWER_API std::filesystem::path getMenuFontPath() const;
57
59 const FontFilePaths& getAllFontPaths() const { return fontPaths_; }
60
63 MRVIEWER_API void setNewFontPaths( const FontFilePaths& paths );
64
67 MRVIEWER_API static ImFont* getFontByTypeStatic( FontType type );
68
71 MRVIEWER_API static FontAndSize getFontAndSizeByTypeStatic( FontType type );
72
75 MRVIEWER_API static void initFontManagerInstance( RibbonFontManager* ribbonFontManager );
76
77private:
78
79#ifndef __EMSCRIPTEN__
80 static constexpr RibbonFontManager::FontFile cFontFileRegular_ = RibbonFontManager::FontFile::RegularSC;
81#else
82 static constexpr RibbonFontManager::FontFile cFontFileRegular_ = RibbonFontManager::FontFile::Regular;
83#endif
84
85 FontFilePaths fontPaths_;
86 struct FontData
87 {
88 FontFile fontFile{ cFontFileRegular_ }; // what file type to use for this font
89 Vector2f scaledOffset; // offset that is used for each glyph while creating atlas (updates in `updateFontsScaledOffset_`), should respect font size with scaling
90 ImFont* fontPtr{ nullptr }; // pointer to loaded font, nullptr means that font was not loaded
91 };
92 std::array<FontData, size_t( FontType::Count )> fonts_;
93
95 static RibbonFontManager*& getFontManagerInstance_();
96
98 void updateFontsScaledOffset_();
99
100 void loadFont_( FontType type, const ImWchar* ranges );
101};
102
103}
Definition MRRibbonFontManager.h:12
static MRVIEWER_API void initFontManagerInstance(RibbonFontManager *ribbonFontManager)
static MRVIEWER_API float getFontSizeByType(FontType type)
get font size by font type
FontFile
Definition MRRibbonFontManager.h:32
static MRVIEWER_API FontAndSize getFontAndSizeByTypeStatic(FontType type)
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:59
std::array< std::filesystem::path, size_t(FontFile::Count)> FontFilePaths
Definition MRRibbonFontManager.h:43
FontType
Definition MRRibbonFontManager.h:17
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
std::pair< ImFont *, float > FontAndSize
Definition MRViewerFwd.h:89