From b6252045a1340a42a39426dfbb877d2a1f357b7f Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 15 Aug 2024 11:25:30 +0200 Subject: adw: add Toast and ToastOverlay classes --- adw/include/turns/adw/helpers/gobj_cast.hpp | 37 +++++++++ adw/include/turns/adw/helpers/properties.hpp | 35 ++++++++ adw/include/turns/adw/toast.hpp | 120 +++++++++++++++++++++++++++ adw/include/turns/adw/toastoverlay.hpp | 64 ++++++++++++++ 4 files changed, 256 insertions(+) create mode 100644 adw/include/turns/adw/helpers/gobj_cast.hpp create mode 100644 adw/include/turns/adw/helpers/properties.hpp create mode 100644 adw/include/turns/adw/toast.hpp create mode 100644 adw/include/turns/adw/toastoverlay.hpp (limited to 'adw/include/turns') diff --git a/adw/include/turns/adw/helpers/gobj_cast.hpp b/adw/include/turns/adw/helpers/gobj_cast.hpp new file mode 100644 index 0000000..1ef9089 --- /dev/null +++ b/adw/include/turns/adw/helpers/gobj_cast.hpp @@ -0,0 +1,37 @@ +#ifndef TURNS_ADW_HELPERS_GOBJ_CAST_HPP +#define TURNS_ADW_HELPERS_GOBJ_CAST_HPP + +#include + +#include + +namespace turns::adw::helpers +{ + + template + struct gobj_mixin + { + template + auto gobj(this Self && self) noexcept + { + using clean_type = std::remove_reference_t; + using gobj_type = std::conditional_t, std::add_const_t, Glib::Object>; + using cast_type = std::conditional_t, std::add_const_t, AdwType>; + + return reinterpret_cast(static_cast(self).gobj()); + } + + template + auto gobj_copy(this Self && self) noexcept -> AdwType * + { + using clean_type = std::remove_reference_t; + using gobj_type = std::conditional_t, std::add_const_t, Glib::Object>; + + static_cast(self).reference(); + return self.gobj(); + } + }; + +} // namespace turns::adw::helpers + +#endif \ No newline at end of file diff --git a/adw/include/turns/adw/helpers/properties.hpp b/adw/include/turns/adw/helpers/properties.hpp new file mode 100644 index 0000000..6cc602a --- /dev/null +++ b/adw/include/turns/adw/helpers/properties.hpp @@ -0,0 +1,35 @@ +#ifndef TURNS_ADW_HELPERS_PROPERTIES_HPP +#define TURNS_ADW_HELPERS_PROPERTIES_HPP + +#include +#include + +#include + +namespace turns::adw::helpers +{ + + template + struct deduced_property_proxy + { + using type = Glib::PropertyProxy; + }; + + template + struct deduced_property_proxy + { + using type = Glib::PropertyProxy_ReadOnly; + }; + + template + using deduced_property_proxy_t = typename deduced_property_proxy::type; + + template + auto make_property_proxy(ObjectType && object, char const * property) + { + return deduced_property_proxy_t>{&object, property}; + } + +} // namespace turns::adw::helpers + +#endif \ No newline at end of file diff --git a/adw/include/turns/adw/toast.hpp b/adw/include/turns/adw/toast.hpp new file mode 100644 index 0000000..21ccdef --- /dev/null +++ b/adw/include/turns/adw/toast.hpp @@ -0,0 +1,120 @@ +#ifndef TURNS_ADW_TOAST_HPP +#define TURNS_ADW_TOAST_HPP + +#include "turns/adw/helpers/gobj_cast.hpp" +#include "turns/adw/helpers/properties.hpp" + +#include +#include +#include +#include + +#include + +using AdwToast = struct _AdwToast; + +namespace turns::adw +{ + struct Toast_Class; + + struct Toast : Glib::Object, + helpers::gobj_mixin + { + enum class Priority + { + NORMAL, + HIGH, + }; + + using helpers::gobj_mixin::gobj; + using helpers::gobj_mixin::gobj_copy; + + Toast(Toast && other) noexcept = default; + auto operator=(Toast && other) noexcept -> Toast & = default; + + Toast(Toast const & other) = delete; + auto operator=(Toast const & other) noexcept -> Toast & = delete; + + explicit Toast(Glib::ustring const & title); + + auto static get_type() -> GType; + auto static get_base_type() -> GType; + + auto dismiss() -> void; + + // clang-format off + template auto property_action_name(this Self && self); + template auto property_action_target(this Self && self); + template auto property_button_label(this Self && self); + template auto property_custom_title(this Self && self); + template auto property_priority(this Self && self); + template auto property_timeout(this Self && self); + template auto property_title(this Self && self); + template auto property_use_markup(this Self && self); + // clang-format on + + protected: + explicit Toast(Glib::ConstructParams const & params); + explicit Toast(AdwToast * gobj); + + private: + friend Toast_Class; + static Toast_Class s_class; + }; + + template + auto Toast::property_action_name(this Self && self) + { + return helpers::make_property_proxy(self, "action-name"); + } + + template + auto Toast::property_action_target(this Self && self) + { + return helpers::make_property_proxy(self, "action-target"); + } + + template + auto Toast::property_button_label(this Self && self) + { + return helpers::make_property_proxy(self, "button-label"); + } + + template + auto Toast::property_custom_title(this Self && self) + { + return helpers::make_property_proxy(self, "custom-title"); + } + + template + auto Toast::property_priority(this Self && self) + { + return helpers::make_property_proxy(self, "priority"); + } + + template + auto Toast::property_timeout(this Self && self) + { + return helpers::make_property_proxy(self, "timeout"); + } + + template + auto Toast::property_title(this Self && self) + { + return helpers::make_property_proxy(self, "title"); + } + + template + auto Toast::property_use_markup(this Self && self) + { + return helpers::make_property_proxy(self, "use-markup"); + } + +} // namespace turns::adw + +namespace Glib +{ + auto wrap(AdwToast * object, bool copy = false) -> Glib::RefPtr; +} // namespace Glib + +#endif \ No newline at end of file diff --git a/adw/include/turns/adw/toastoverlay.hpp b/adw/include/turns/adw/toastoverlay.hpp new file mode 100644 index 0000000..bd5402f --- /dev/null +++ b/adw/include/turns/adw/toastoverlay.hpp @@ -0,0 +1,64 @@ +#ifndef TURNS_ADW_TOASTOVERLAY_HPP +#define TURNS_ADW_TOASTOVERLAY_HPP + +#include "turns/adw/helpers/gobj_cast.hpp" +#include "turns/adw/helpers/properties.hpp" + +#include + +#include + +using AdwToastOverlay = struct _AdwToastOverlay; + +namespace turns::adw +{ + struct ToastOverlay_Class; + + struct Toast; + + struct ToastOverlay : Gtk::Widget, + helpers::gobj_mixin + { + using helpers::gobj_mixin::gobj; + using helpers::gobj_mixin::gobj_copy; + + ToastOverlay(ToastOverlay && other) noexcept = default; + auto operator=(ToastOverlay && other) noexcept -> ToastOverlay & = default; + + ToastOverlay(ToastOverlay const & other) = delete; + auto operator=(ToastOverlay const & other) noexcept -> ToastOverlay & = delete; + + explicit ToastOverlay(); + + auto static get_type() -> GType; + auto static get_base_type() -> GType; + + auto add(Toast && toast) -> void; + + // clang-format off + template auto property_child(this Self && self); + // clang-format on + + protected: + explicit ToastOverlay(Glib::ConstructParams const & params); + explicit ToastOverlay(AdwToastOverlay * gobj); + + private: + friend ToastOverlay_Class; + static ToastOverlay_Class s_class; + }; + + template + auto ToastOverlay::property_child(this Self && self) + { + return helpers::make_property_proxy(self, "child"); + } + +} // namespace turns::adw + +namespace Glib +{ + auto wrap(AdwToastOverlay * object, bool copy = false) -> Glib::RefPtr; +} // namespace Glib + +#endif \ No newline at end of file -- cgit v1.2.3