summaryrefslogtreecommitdiff
path: root/adw/include/turns
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-08-15 11:25:30 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-08-15 11:25:30 +0200
commitb6252045a1340a42a39426dfbb877d2a1f357b7f (patch)
tree53c78490bc035595f16ca7f8b416f825df952e13 /adw/include/turns
parenta2cc1d08fdb5b991e5a47e74e6e534747e330c7c (diff)
downloadturns-b6252045a1340a42a39426dfbb877d2a1f357b7f.tar.xz
turns-b6252045a1340a42a39426dfbb877d2a1f357b7f.zip
adw: add Toast and ToastOverlay classes
Diffstat (limited to 'adw/include/turns')
-rw-r--r--adw/include/turns/adw/helpers/gobj_cast.hpp37
-rw-r--r--adw/include/turns/adw/helpers/properties.hpp35
-rw-r--r--adw/include/turns/adw/toast.hpp120
-rw-r--r--adw/include/turns/adw/toastoverlay.hpp64
4 files changed, 256 insertions, 0 deletions
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 <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
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 <glibmm/propertyproxy.h>
+#include <glibmm/ustring.h>
+
+#include <type_traits>
+
+namespace turns::adw::helpers
+{
+
+ template<typename ProxiedType, typename ObjectType>
+ struct deduced_property_proxy
+ {
+ using type = Glib::PropertyProxy<ProxiedType>;
+ };
+
+ template<typename ProxiedType, typename ObjectType>
+ struct deduced_property_proxy<ProxiedType, ObjectType const>
+ {
+ using type = Glib::PropertyProxy_ReadOnly<ProxiedType>;
+ };
+
+ template<typename ProxiedType, typename ObjectType>
+ using deduced_property_proxy_t = typename deduced_property_proxy<ProxiedType, ObjectType>::type;
+
+ template<typename ProxiedType, typename ObjectType>
+ auto make_property_proxy(ObjectType && object, char const * property)
+ {
+ return deduced_property_proxy_t<ProxiedType, std::remove_reference_t<ObjectType>>{&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 <glibmm/object.h>
+#include <glibmm/refptr.h>
+#include <glibmm/ustring.h>
+#include <glibmm/variant.h>
+
+#include <gtkmm/widget.h>
+
+using AdwToast = struct _AdwToast;
+
+namespace turns::adw
+{
+ struct Toast_Class;
+
+ struct Toast : Glib::Object,
+ helpers::gobj_mixin<Toast, AdwToast>
+ {
+ enum class Priority
+ {
+ NORMAL,
+ HIGH,
+ };
+
+ using helpers::gobj_mixin<Toast, AdwToast>::gobj;
+ using helpers::gobj_mixin<Toast, AdwToast>::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<typename Self> auto property_action_name(this Self && self);
+ template<typename Self> auto property_action_target(this Self && self);
+ template<typename Self> auto property_button_label(this Self && self);
+ template<typename Self> auto property_custom_title(this Self && self);
+ template<typename Self> auto property_priority(this Self && self);
+ template<typename Self> auto property_timeout(this Self && self);
+ template<typename Self> auto property_title(this Self && self);
+ template<typename Self> 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<typename Self>
+ auto Toast::property_action_name(this Self && self)
+ {
+ return helpers::make_property_proxy<Glib::ustring>(self, "action-name");
+ }
+
+ template<typename Self>
+ auto Toast::property_action_target(this Self && self)
+ {
+ return helpers::make_property_proxy<Glib::VariantBase>(self, "action-target");
+ }
+
+ template<typename Self>
+ auto Toast::property_button_label(this Self && self)
+ {
+ return helpers::make_property_proxy<Glib::ustring>(self, "button-label");
+ }
+
+ template<typename Self>
+ auto Toast::property_custom_title(this Self && self)
+ {
+ return helpers::make_property_proxy<Gtk::Widget *>(self, "custom-title");
+ }
+
+ template<typename Self>
+ auto Toast::property_priority(this Self && self)
+ {
+ return helpers::make_property_proxy<Priority>(self, "priority");
+ }
+
+ template<typename Self>
+ auto Toast::property_timeout(this Self && self)
+ {
+ return helpers::make_property_proxy<unsigned>(self, "timeout");
+ }
+
+ template<typename Self>
+ auto Toast::property_title(this Self && self)
+ {
+ return helpers::make_property_proxy<Glib::ustring>(self, "title");
+ }
+
+ template<typename Self>
+ auto Toast::property_use_markup(this Self && self)
+ {
+ return helpers::make_property_proxy<bool>(self, "use-markup");
+ }
+
+} // namespace turns::adw
+
+namespace Glib
+{
+ auto wrap(AdwToast * object, bool copy = false) -> Glib::RefPtr<turns::adw::Toast>;
+} // 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 <glibmm/refptr.h>
+
+#include <gtkmm/widget.h>
+
+using AdwToastOverlay = struct _AdwToastOverlay;
+
+namespace turns::adw
+{
+ struct ToastOverlay_Class;
+
+ struct Toast;
+
+ struct ToastOverlay : Gtk::Widget,
+ helpers::gobj_mixin<ToastOverlay, AdwToastOverlay>
+ {
+ using helpers::gobj_mixin<ToastOverlay, AdwToastOverlay>::gobj;
+ using helpers::gobj_mixin<ToastOverlay, AdwToastOverlay>::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<typename Self> 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<typename Self>
+ auto ToastOverlay::property_child(this Self && self)
+ {
+ return helpers::make_property_proxy<Gtk::Widget *>(self, "child");
+ }
+
+} // namespace turns::adw
+
+namespace Glib
+{
+ auto wrap(AdwToastOverlay * object, bool copy = false) -> Glib::RefPtr<turns::adw::ToastOverlay>;
+} // namespace Glib
+
+#endif \ No newline at end of file