cgv
Loading...
Searching...
No Matches
theme_info.h
1#pragma once
2
3#include <cgv/media/color.h>
4#include <cgv/signal/signal.h>
5
6#include "lib_begin.h"
7
8namespace cgv {
9namespace gui {
10
11#define DEF_COLOR_MEMBER_METHODS(FIELD) \
12void FIELD(unsigned char r, unsigned char g, unsigned char b) { \
13 FIELD##_col = rgb( \
14 static_cast<float>(r) / 255.0f, \
15 static_cast<float>(g) / 255.0f, \
16 static_cast<float>(b) / 255.0f \
17 ); \
18} \
19rgb FIELD() const { \
20 return FIELD##_col; \
21}\
22std::string FIELD##_hex() const { \
23 return cgv::media::to_hex(FIELD##_col); \
24}
25
26class CGV_API theme_info {
27protected:
28 int index_ = -1;
29
30 // the spacing between user interface groups (usually a 1px wide border)
31 int spacing_ = 1;
32 // the scaling of user interface elements (used for DPI-adjustment); currently not supported by fltk controls
33 float scaling_ = 1.0f;
34
35 rgb background_col;
36 rgb group_col;
37 rgb control_col;
38 rgb border_col;
39 rgb text_col;
40 rgb text_background_col;
41 rgb selection_col;
42 rgb highlight_col;
43 rgb warning_col;
44 rgb shadow_col;
45
46public:
47 static theme_info& instance();
48
49 theme_info(const theme_info&) = delete;
50 void operator=(const theme_info&) = delete;
51
53 theme_info();
56
57 // general info
58 void index(int index) { index_ = index; }
59 int index() const { return index_; }
60 bool is_dark() const;
61
62 // layout variables
63 int spacing() const { return spacing_; }
64 void spacing(int i) { spacing_ = i; }
65
66 float scaling() const { return scaling_; }
67 void scaling(float f) { scaling_ = f; }
68
69 // theme colors
70 DEF_COLOR_MEMBER_METHODS(background);
71 DEF_COLOR_MEMBER_METHODS(group);
72 DEF_COLOR_MEMBER_METHODS(control);
73 DEF_COLOR_MEMBER_METHODS(border);
74 DEF_COLOR_MEMBER_METHODS(text);
75 DEF_COLOR_MEMBER_METHODS(text_background);
76 DEF_COLOR_MEMBER_METHODS(selection);
77 DEF_COLOR_MEMBER_METHODS(highlight);
78 DEF_COLOR_MEMBER_METHODS(warning);
79 DEF_COLOR_MEMBER_METHODS(shadow);
80
81 // calls the on_change signal to notify theme_observers upon theme changes
82 void notify_observers() const;
83
84 cgv::signal::signal<const theme_info&> on_change;
85};
86
87#undef DEF_COLOR_MEMBER_METHODS
88
89// derive from this class to handle theme changes whenever theme_info::notify_changes is called
90class CGV_API theme_observer : virtual public cgv::signal::tacker {
91public:
93 cgv::gui::theme_info& theme = cgv::gui::theme_info::instance();
94 cgv::signal::connect(theme.on_change, this, &theme_observer::handle_theme_change);
95 }
96
98 cgv::gui::theme_info& theme = cgv::gui::theme_info::instance();
99 cgv::signal::disconnect(theme.on_change, this, &theme_observer::handle_theme_change);
100 }
101
103 virtual void handle_theme_change(const cgv::gui::theme_info& theme) {}
104};
105
106}
107}
108
109#include <cgv/config/lib_end.h>
~theme_info()
destruct
Definition theme_info.h:55
virtual void handle_theme_change(const cgv::gui::theme_info &theme)
override in your class to handle theme changes
Definition theme_info.h:103
the cgv namespace
Definition print.h:11