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