RADLib
RADical C++ application framework
RADTheme.h
Go to the documentation of this file.
1 #ifndef RADTHEME_H
2 #define RADTHEME_H
3 
9 #pragma once
10 
11 #include <RADCore/RADCore.h>
12 
13 #include <map>
14 #include <string>
15 
16 namespace RADUi {
17 
19  enum class ThemeMode {
21  Light,
23  Dark,
25  System
26  };
27 
29  struct ThemeColors {
31  std::string window = "#f6f7f9";
33  std::string panel = "#ffffff";
35  std::string panelAlt = "#eef1f5";
37  std::string text = "#1d2733";
39  std::string mutedText = "#667085";
41  std::string border = "#cfd6df";
43  std::string accent = "#2563eb";
45  std::string success = "#15803d";
47  std::string warning = "#b45309";
49  std::string error = "#b91c1c";
50  };
51 
53  struct ThemeMetrics {
55  int gapSmall = 4;
57  int gap = 8;
59  int gapLarge = 12;
61  int padding = 10;
63  int radius = 6;
65  int toolbarHeight = 36;
67  int statusBarHeight = 26;
68  };
69 
71  struct ThemeTypography {
73  int bodySize = 13;
75  int labelSize = 12;
77  int headingSize = 17;
79  int monoSize = 13;
81  std::string bodyFamily = "Inter, Sans";
83  std::string monoFamily = "Monospace";
84  };
85 
87  struct Theme {
89  std::string id = "light";
91  std::string name = "Light";
99  std::map<std::string, std::string> icons;
100  };
101 
104  public:
105  RADEvents:
108 
111 
113  ThemeMode mode() const;
117  const Theme& theme() const;
120 
122  bool loadFromFile(const std::string& path, std::string* error = nullptr);
124  bool saveToFile(const std::string& path, std::string* error = nullptr) const;
125 
127  static Theme lightTheme();
129  static Theme darkTheme();
133  static Theme fromJson(const RADCore::RADJsonValue& value, const Theme& defaults = lightTheme());
135  static std::string modeName(ThemeMode mode);
137  static ThemeMode modeFromName(const std::string& name);
138 
139  private:
140  ThemeMode mode_ = ThemeMode::Light;
141  Theme theme_;
142  };
143 
144 } // namespace RADUi
145 
146 #endif
#define RAD_EVENT(Name, Signature)
Declares a typed RADCore event; example: RAD_EVENT(done, (int)).
Definition: RADCore.h:97
#define RADEvents
Marks a public event declaration block in RADObject-derived classes.
Definition: RADCore.h:75
JSON value supporting null, bool, number, string, array, and object.
Definition: RADCore.h:541
Base class for event receivers, senders, and thread-affinity aware objects.
Definition: RADCore.h:963
Process/application theme manager with RADCore events.
Definition: RADTheme.h:103
bool saveToFile(const std::string &path, std::string *error=nullptr) const
Saves current theme JSON to path.
static std::string modeName(ThemeMode mode)
Converts ThemeMode to stable text.
static Theme darkTheme()
Returns RADUi's default dark theme.
const Theme & theme() const
Returns active theme tokens.
static RADCore::RADJsonValue toJson(const Theme &theme)
Converts a theme to JSON.
ThemeManager()
Creates a manager using the default light theme.
ThemeMode mode() const
Returns current mode.
static Theme fromJson(const RADCore::RADJsonValue &value, const Theme &defaults=lightTheme())
Converts JSON to a theme, using defaults for missing fields.
static ThemeMode modeFromName(const std::string &name)
Parses ThemeMode text.
void setMode(ThemeMode mode)
Sets current theme mode.
bool loadFromFile(const std::string &path, std::string *error=nullptr)
Loads theme JSON from path.
void setTheme(Theme theme)
Replaces active theme tokens.
RADCore::Event< void() > changed
Raised when mode or theme tokens change.
Definition: RADTheme.h:107
static Theme lightTheme()
Returns RADUi's default light theme.
Definition: RADAppKit.h:20
ThemeMode
Theme selection mode.
Definition: RADTheme.h:19
@ Light
Use light theme tokens.
@ Dark
Use dark theme tokens.
@ System
Use the system preference when a backend can report it.
Named UI color tokens encoded as CSS-style strings.
Definition: RADTheme.h:29
std::string panel
Raised panel background.
Definition: RADTheme.h:33
std::string window
Main window background.
Definition: RADTheme.h:31
std::string warning
Warning state color.
Definition: RADTheme.h:47
std::string success
Success state color.
Definition: RADTheme.h:45
std::string panelAlt
Alternate panel background.
Definition: RADTheme.h:35
std::string error
Error state color.
Definition: RADTheme.h:49
std::string border
Border and separator color.
Definition: RADTheme.h:41
std::string mutedText
Muted secondary text color.
Definition: RADTheme.h:39
std::string text
Primary text color.
Definition: RADTheme.h:37
std::string accent
Primary accent color.
Definition: RADTheme.h:43
Spacing/radius tokens in logical pixels.
Definition: RADTheme.h:53
int gapSmall
Small gap.
Definition: RADTheme.h:55
int gap
Normal gap.
Definition: RADTheme.h:57
int padding
Panel/content padding.
Definition: RADTheme.h:61
int toolbarHeight
Standard toolbar height.
Definition: RADTheme.h:65
int statusBarHeight
Standard status bar height.
Definition: RADTheme.h:67
int gapLarge
Large gap.
Definition: RADTheme.h:59
int radius
Border radius.
Definition: RADTheme.h:63
Typography tokens.
Definition: RADTheme.h:71
std::string monoFamily
Preferred monospace font family.
Definition: RADTheme.h:83
int monoSize
Monospace text size.
Definition: RADTheme.h:79
int headingSize
Heading size.
Definition: RADTheme.h:77
std::string bodyFamily
Preferred normal font family.
Definition: RADTheme.h:81
int bodySize
Normal text size.
Definition: RADTheme.h:73
int labelSize
Compact label size.
Definition: RADTheme.h:75
Complete RADUi theme definition.
Definition: RADTheme.h:87
std::string name
Display name.
Definition: RADTheme.h:91
ThemeTypography typography
Typography tokens.
Definition: RADTheme.h:97
ThemeColors colors
Color tokens.
Definition: RADTheme.h:93
std::map< std::string, std::string > icons
Icon name aliases.
Definition: RADTheme.h:99
ThemeMetrics metrics
Metrics tokens.
Definition: RADTheme.h:95