aboutsummaryrefslogtreecommitdiff
path: root/src/ui/control.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-09 19:59:57 +0800
committercrupest <crupest@outlook.com>2018-11-09 19:59:57 +0800
commit6515948e3f5b97f90446536f72e99d71e96f9de7 (patch)
tree2c962abc3447529e10e0b1d255757f60aaf9f2c6 /src/ui/control.hpp
parentefdce672123284847bd7fb6f12ac1ec96f28f3ef (diff)
downloadcru-6515948e3f5b97f90446536f72e99d71e96f9de7.tar.gz
cru-6515948e3f5b97f90446536f72e99d71e96f9de7.tar.bz2
cru-6515948e3f5b97f90446536f72e99d71e96f9de7.zip
Add AnyMap.
Diffstat (limited to 'src/ui/control.hpp')
-rw-r--r--src/ui/control.hpp33
1 files changed, 4 insertions, 29 deletions
diff --git a/src/ui/control.hpp b/src/ui/control.hpp
index 26be653a..0e078da2 100644
--- a/src/ui/control.hpp
+++ b/src/ui/control.hpp
@@ -3,16 +3,15 @@
#include "system_headers.hpp"
#include <unordered_map>
#include <any>
-#include <typeinfo>
#include <utility>
#include "base.hpp"
-#include "format.hpp"
#include "ui_base.hpp"
#include "layout_base.hpp"
#include "events/ui_event.hpp"
#include "border_property.hpp"
#include "cursor.hpp"
+#include "any_map.h"
namespace cru::ui
{
@@ -183,33 +182,9 @@ namespace cru::ui
//*************** region: additional properties ***************
- template <typename T>
- std::optional<T> GetAdditionalProperty(const String& key)
+ AnyMap* GetAdditionalPropertyMap()
{
- try
- {
- const auto find_result = additional_properties_.find(key);
- if (find_result != additional_properties_.cend())
- return std::any_cast<T>(find_result->second);
- else
- return std::nullopt;
- }
- catch (const std::bad_any_cast&)
- {
- throw std::runtime_error(Format("Key \"{}\" is not of the type {}.", ToUtf8String(key), typeid(T).name()));
- }
- }
-
- template <typename T>
- void SetAdditionalProperty(const String& key, const T& value)
- {
- additional_properties_[key] = std::make_any<T>(value);
- }
-
- template <typename T>
- void SetAdditionalProperty(const String& key, T&& value)
- {
- additional_properties_[key] = std::make_any<T>(std::move(value));
+ return &additional_property_map_;
}
@@ -389,7 +364,7 @@ namespace cru::ui
bool is_bordered_ = false;
BorderProperty border_property_;
- std::unordered_map<String, std::any> additional_properties_{};
+ AnyMap additional_property_map_{};
bool is_focus_on_pressed_ = true;