aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/ThemeManager.hpp
blob: 9908658c90489f60ad906b72181789e4c6cee33e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "Base.hpp"
#include "cru/common/Base.hpp"
#include "cru/common/Event.hpp"
#include "cru/platform/graphics/Brush.hpp"

#include <boost/property_tree/ptree.hpp>
#include <cstddef>
#include <memory>
#include <stdexcept>
#include <string_view>
#include <unordered_map>

namespace cru::ui {
class BadThemeResourceException : public std::runtime_error {
 public:
  using std::runtime_error::runtime_error;
};

class ThemeManager : public Object {
 public:
  static ThemeManager* GetInstance();

 private:
  ThemeManager();

 public:
  CRU_DELETE_COPY(ThemeManager)
  CRU_DELETE_MOVE(ThemeManager)

  ~ThemeManager() override = default;

  IEvent<std::nullptr_t>* ThemeResourceChangeEvent() {
    return &theme_resource_change_event_;
  }

  gsl::not_null<std::shared_ptr<platform::graphics::IBrush>> GetBrush(
      StringView key);

 private:
  void Init();

 private:
  Event<std::nullptr_t> theme_resource_change_event_;
  boost::property_tree::ptree theme_tree_;
  std::unordered_map<String, std::shared_ptr<platform::graphics::IBrush>>
      brushes_;
};
}  // namespace cru::ui