diff options
author | crupest <crupest@outlook.com> | 2018-09-22 22:57:44 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-22 22:57:44 +0800 |
commit | 5d91d1e5594e37ca5c282e602407eaeb34c6d986 (patch) | |
tree | 0086bb88c152b8ea9eb31e86906afcd238309cda /CruUI/ui/control.h | |
parent | dc293cef8f25ba70c5d99d73aa472277484ca879 (diff) | |
download | cru-5d91d1e5594e37ca5c282e602407eaeb34c6d986.tar.gz cru-5d91d1e5594e37ca5c282e602407eaeb34c6d986.tar.bz2 cru-5d91d1e5594e37ca5c282e602407eaeb34c6d986.zip |
Done 3 things:
1. Add some helper functions for create controls with layout params.
2. Fix a bug in measure of linear layout.
3. Fix a bug in exception.
Diffstat (limited to 'CruUI/ui/control.h')
-rw-r--r-- | CruUI/ui/control.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/CruUI/ui/control.h b/CruUI/ui/control.h index 2f23fd21..3810f5ac 100644 --- a/CruUI/ui/control.h +++ b/CruUI/ui/control.h @@ -4,6 +4,7 @@ #include <unordered_map> #include <any> #include <typeinfo> +#include <utility> #include <fmt/format.h> #include "base.h" @@ -348,5 +349,15 @@ namespace cru // Return the ancestor if one control is the ancestor of the other one, otherwise nullptr. Control* IsAncestorOrDescendant(Control* left, Control* right); + + template <typename TControl, typename... Args> + TControl* CreateWithLayout(const LayoutLength& width, const LayoutLength& height, Args&&... args) + { + static_assert(std::is_base_of_v<Control, TControl>, "TControl is not a control class."); + TControl* control = TControl::Create(std::forward<Args>(args)...); + control->GetLayoutParams()->width = width; + control->GetLayoutParams()->height = height; + return control; + } } } |