MeshLib C++ Docs
Loading...
Searching...
No Matches
MRColorTheme.h
Go to the documentation of this file.
1#pragma once
2#include "exports.h"
3#include "MRMesh/MRColor.h"
4#include "MRMesh/MRSignal.h"
5#include <json/forwards.h>
6#include <filesystem>
7#include <vector>
8#include <array>
9#include <optional>
10
11namespace MR
12{
13
14// This singleton is born to manage color-themes loading and saving, and apply it to app
15// It can handle scene colors (default mesh colors, etc.) and Dear ImGui colors
17{
18public:
19 MRVIEWER_API static ColorTheme& instance();
20
21 enum class Preset
22 {
23 Dark,
24 Default = Dark,
25 Light,
26 Count
27 };
28 MRVIEWER_API static Preset getPreset();
29 MRVIEWER_API static const char* getPresetName( Preset type );
30
31
32 enum class Type
33 {
34 Default,
35 User
36 };
37
38 MRVIEWER_API static Type getThemeType();
39 MRVIEWER_API static const std::string& getThemeName();
40
41 // Setup this struct
42 MRVIEWER_API static void setupByTypeName( Type type, const std::string& name );
43 MRVIEWER_API static void setupDefaultDark();
44 MRVIEWER_API static void setupDefaultLight();
45 MRVIEWER_API static void setupUserTheme( const std::string& themeName );
46 // Setup this struct from serialized color-theme file
47 MRVIEWER_API static void setupFromFile( const std::filesystem::path& path, Type type = Type::User );
48 // Setup this struct from Json value
49 MRVIEWER_API static void setupFromJson( const Json::Value& value, Type type = Type::User );
50
51 // Setup this struct from current application colors, and serialize them to file
52 // gets scene colors from first ObjectMesh, if it is present
53 // gets active viewport background color
54 MRVIEWER_API static void serializeCurrentToFile( const std::filesystem::path& path );
55 // Setup this struct from current application colors, and serialize them to jsonValue
56 // gets scene colors from first ObjectMesh, if it is present
57 // gets active viewport background color
58 MRVIEWER_API static void serializeCurrentToJson( Json::Value& root );
59
60 // Applies colors stored in this struct to application
61 // really some colors of this theme are applied deferred on next frame because of ImGui::PushStyleColor problem
62 // note that struct should be initialized when apply is called
63 // initialized in this scope means that structure has it's own values for colors
64 MRVIEWER_API static void apply();
65 // True if this structure is filled with colors, false if empty
66 MRVIEWER_API static bool isInitialized();
67
68 // Color types used in ribbon
145 // Getter and setter for ribbon colors
146 MRVIEWER_API static void setRibbonColor( const Color& color, RibbonColorsType type );
147 MRVIEWER_API static const Color& getRibbonColor( RibbonColorsType type );
148 MRVIEWER_API static const char* getRibbonColorTypeName( RibbonColorsType type );
149
151 {
153 Borders,
154 Count
155 };
156
157 // Getter and setter for viewport colors
158 MRVIEWER_API static void setViewportColor( const Color& color, ViewportColorsType type );
159 MRVIEWER_API static const Color& getViewportColor( ViewportColorsType type );
160 MRVIEWER_API static const char* getViewportColorTypeName( ViewportColorsType type );
161
162 // Returns directory where user's custom themes are stored
163 MRVIEWER_API static std::filesystem::path getUserThemesDirectory();
164
165 // Find available custom themes
166 MRVIEWER_API static void updateUserThemesList();
167 // Return list of found custom themes
168 MRVIEWER_API static std::vector<std::string> foundUserThemes();
169
170 // Reset ImGui style sizes and colors, and apply menu scaling to it
171 MRVIEWER_API static void resetImGuiStyle();
172
174 MRVIEWER_API static boost::signals2::connection onChanged( const std::function<void()>& slot, boost::signals2::connect_position position = boost::signals2::at_back );
175
176private:
177 ColorTheme() = default;
178 ~ColorTheme() = default;
179
180
181 std::vector<Color> sceneColors_;
182 Preset themePreset_ = Preset::Dark;
183 std::array<Color, size_t( RibbonColorsType::Count )> newUIColors_;
184 std::array<Color, size_t( ViewportColorsType::Count )> viewportColors_;
185
186 Type type_{ Type::Default };
187 std::string themeName_;
188
189 std::vector<std::string> foundUserThemes_;
190
191 using ChangedSignal = Signal<void()>;
192 ChangedSignal changedSignal_;
193};
194
195}
Definition MRColorTheme.h:17
static MRVIEWER_API void updateUserThemesList()
static MRVIEWER_API void setupUserTheme(const std::string &themeName)
static MRVIEWER_API bool isInitialized()
static MRVIEWER_API ColorTheme & instance()
static MRVIEWER_API void setupFromJson(const Json::Value &value, Type type=Type::User)
static MRVIEWER_API boost::signals2::connection onChanged(const std::function< void()> &slot, boost::signals2::connect_position position=boost::signals2::at_back)
Connects given slot to receive signal on every Color Theme change, triggered in apply.
static MRVIEWER_API const char * getPresetName(Preset type)
static MRVIEWER_API const char * getRibbonColorTypeName(RibbonColorsType type)
static MRVIEWER_API void setupFromFile(const std::filesystem::path &path, Type type=Type::User)
static MRVIEWER_API void setRibbonColor(const Color &color, RibbonColorsType type)
static MRVIEWER_API std::filesystem::path getUserThemesDirectory()
static MRVIEWER_API std::vector< std::string > foundUserThemes()
static MRVIEWER_API void setupByTypeName(Type type, const std::string &name)
static MRVIEWER_API Preset getPreset()
static MRVIEWER_API void setupDefaultLight()
static MRVIEWER_API void setupDefaultDark()
ViewportColorsType
Definition MRColorTheme.h:151
static MRVIEWER_API void apply()
static MRVIEWER_API const char * getViewportColorTypeName(ViewportColorsType type)
static MRVIEWER_API void serializeCurrentToFile(const std::filesystem::path &path)
static MRVIEWER_API const Color & getRibbonColor(RibbonColorsType type)
static MRVIEWER_API void setViewportColor(const Color &color, ViewportColorsType type)
Preset
Definition MRColorTheme.h:22
static MRVIEWER_API const Color & getViewportColor(ViewportColorsType type)
Type
Definition MRColorTheme.h:33
static MRVIEWER_API Type getThemeType()
RibbonColorsType
Definition MRColorTheme.h:70
static MRVIEWER_API void serializeCurrentToJson(Json::Value &root)
static MRVIEWER_API void resetImGuiStyle()
static MRVIEWER_API const std::string & getThemeName()
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh/MRColor.h:9
Definition MRSignal.h:24