xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
theme_base.h
1 #pragma once
2 #include <xtd/environment.h>
3 #include <xtd/strings.h>
4 #include "../forms_export.h"
5 #include "theme_style.h"
6 
8 namespace xtd {
10  namespace forms {
11  class forms_export_ theme_base {
12  public:
14  theme_base(const theme_base&) = default;
15  theme_base& operator=(const theme_base&) = default;
16  bool operator==(const theme_base& value) const {return name_ == value.name_ && theme_style_ == value.theme_style_ && is_default_ == value.is_default();}
17  bool operator!=(const theme_base& value) const {return !operator==(value);}
18  virtual ~theme_base() = default;
19  friend std::ostream& operator<<(std::ostream& os, const theme_base& theme) noexcept {return os << theme.to_string();}
21 
22  using theme_name_collection = std::vector<std::string>;
23 
24  virtual const std::string& name() const {return name_;}
25  theme_base& name(const std::string& name) {
26  name_ = name;
27  return *this;
28  }
29 
30  xtd::forms::theme_style theme_style() const {return theme_style_;}
32  theme_style_ = theme_style;
33  return *this;
34  }
35 
36  bool is_default() const {return is_default_;}
37 
38  std::string to_string() const {return xtd::strings::format("[name={}, style={}, is_default={}] ", name_, theme_style_, is_default_);}
39 
40  static std::string default_theme_name() {return xtd::environment::os_version().desktop_environment() == "" ? fallback_theme_name() : xtd::environment::os_version().desktop_environment();}
41 
42  static std::string fallback_theme_name() {return "symbolic";}
43 
44  static const theme_name_collection& theme_names() {return theme_names_;}
45 
46  static const theme_base empty;
47 
48  protected:
49  theme_base() = default;
50  explicit theme_base(const std::string& name) : name_(name) {}
51  theme_base(const std::string& name, xtd::forms::theme_style theme_style) : name_(name), theme_style_(theme_style) {}
52  theme_base(const std::string& name, xtd::forms::theme_style theme_style, bool is_default) : name_(name), theme_style_(theme_style), is_default_(is_default) {}
53 
54  theme_base& is_default(bool is_default) {
55  is_default_ = is_default;
56  return *this;
57  }
58 
59 
60  private:
61  std::string name_;
62  xtd::forms::theme_style theme_style_ = xtd::forms::theme_style::undefined;
63  bool is_default_ = false;
64  static theme_name_collection theme_names_;
65  };
66  }
67 }
68 
69 /* Include file :
70  --------------
71 #pragma once
72 #include "theme_base.h"
73 
75 namespace xtd {
77  namespace forms {
78  class theme final : public theme_base {
79  public:
80  theme() = default;
81  explicit theme(const std::string& name) : theme_base(name) {}
82  theme(const std::string& name, xtd::forms::theme_style theme_style) : theme_base(name, theme_style) {}
84  theme(const theme&) = default;
85  theme& operator=(const theme&) = default;
86  bool operator==(const theme& value) const {return theme_base::operator==(value);}
87  bool operator!=(const theme& value) const {return !operator==(value);}
89 
90  static const theme empty;
91 
92  static theme current_theme() {
93  if (current_theme_ == theme::empty) current_theme_ = default_theme();
94  return current_theme_;
95  }
96  static void current_theme(const theme& theme) {current_theme_ = theme;}
97  static void current_theme(const std::string& name) {current_theme_ = theme_from_name(name);}
98 
99  static theme default_theme() {return theme_from_name(default_theme_name());}
100 
101  static theme theme_from_name(const std::string& theme_name);
102 
103  private:
104  theme(const std::string& name, xtd::forms::theme_style theme_style, bool is_default) : theme_base(name, theme_style, is_default) {}
105  static theme current_theme_;
106  };
107  }
108 }
109 */
110 
111 
112 /* Source file :
113  ---------------
114 #include "../../../include/xtd/forms/theme.h"
115 
116 using namespace xtd::forms;
117 
118 const theme theme::empty {};
119 theme theme::current_theme_;
120 
121 theme theme::theme_from_name(const std::string& name) {
122  if (name == default_theme_name()) return theme(default_theme_name(), theme_style::system_auto);
123  if (name == "gnome") return theme("gnome", theme_style::system_auto);
124  if (name == "gnome (dark)") return theme("gnome (dark)", theme_style::dark);
125  if (name == "gnome (light)") return theme("gnome (light)", theme_style::light);
126  if (name == "kde") return theme("kde", theme_style::system_auto);
127  if (name == "kde (dark)") return theme("kde (dark)", theme_style::dark);
128  if (name == "kde (light)") return theme("kde (light)", theme_style::light);
129  if (name == "macos") return theme("macos", theme_style::system_auto);
130  if (name == "macos (dark)") return theme("macos (dark)", theme_style::dark);
131  if (name == "macos (light)") return theme("macos (light)", theme_style::light);
132  if (name == "symbolic") return theme("symbolic", theme_style::system_auto);
133  if (name == "symbolic (dark)") return theme("symbolic (dark)", theme_style::dark);
134  if (name == "symbolic (light)") return theme("symbolic (light)", theme_style::light);
135  if (name == "windows") return theme("windows", theme_style::system_auto);
136  if (name == "windows (dark)") return theme("windows (dark)", theme_style::dark);
137  if (name == "windows (light)") return theme("windows (light)", theme_style::light);
138  if (name == "xtd") return theme("xtd", theme_style::system_auto);
139  if (name == "xtd (dark)") return theme("xtd (dark)", theme_style::dark);
140  if (name == "xtd (light)") return theme("xtd (light)", theme_style::light);
141  return default_theme();
142 }
143 
144 */
Contains xtd::strings class.
static xtd::operating_system os_version() noexcept
Gets an operating_system object that contains the current platform identifier and version number...
Definition: environment.h:382
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:15
std::string desktop_environment() const
Gets the desktop environment .
Definition: operating_system.h:61
Definition: theme.h:11
static std::basic_string< char_t > format(const std::basic_string< char_t > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: strings.h:612
Contains xtd::environment class.
Definition: theme_base.h:11
theme_style
Specifies the style of theme.
Definition: theme_style.h:10