diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2024-08-17 11:41:43 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2024-08-17 11:41:43 +0200 |
| commit | 97cb30337429a6849c276693ddf7fb40fec1aa14 (patch) | |
| tree | 5f42489d34deb3076677996ce10269d78af9cfa2 /include/turns/adw/helpers/gobj_mixin.hpp | |
| parent | 6fb8667b9848c8fe0989bb665e2f4ddc09179983 (diff) | |
| download | libadwaitamm-97cb30337429a6849c276693ddf7fb40fec1aa14.tar.xz libadwaitamm-97cb30337429a6849c276693ddf7fb40fec1aa14.zip | |
ui: add participant shading color preferences
Diffstat (limited to 'include/turns/adw/helpers/gobj_mixin.hpp')
| -rw-r--r-- | include/turns/adw/helpers/gobj_mixin.hpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/include/turns/adw/helpers/gobj_mixin.hpp b/include/turns/adw/helpers/gobj_mixin.hpp new file mode 100644 index 0000000..d9e5097 --- /dev/null +++ b/include/turns/adw/helpers/gobj_mixin.hpp @@ -0,0 +1,37 @@ +#ifndef TURNS_ADW_HELPERS_GOBJ_MIXIN_HPP +#define TURNS_ADW_HELPERS_GOBJ_MIXIN_HPP + +#include <glibmm/object.h> + +#include <type_traits> + +namespace turns::adw::helpers +{ + + template<typename Type, typename AdwType> + struct gobj_mixin + { + template<typename Self> + auto gobj(this Self && self) noexcept + { + using clean_type = std::remove_reference_t<Self>; + using gobj_type = std::conditional_t<std::is_const_v<clean_type>, std::add_const_t<Glib::Object>, Glib::Object>; + using cast_type = std::conditional_t<std::is_const_v<clean_type>, std::add_const_t<AdwType>, AdwType>; + + return reinterpret_cast<cast_type *>(static_cast<gobj_type &&>(self).gobj()); + } + + template<typename Self> + auto gobj_copy(this Self && self) noexcept -> AdwType * + { + using clean_type = std::remove_reference_t<Self>; + using gobj_type = std::conditional_t<std::is_const_v<clean_type>, std::add_const_t<Glib::Object>, Glib::Object>; + + static_cast<gobj_type &&>(self).reference(); + return self.gobj(); + } + }; + +} // namespace turns::adw::helpers + +#endif
\ No newline at end of file |
