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/src/toast.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ adw/src/toastoverlay.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++ adw/src/wrap_init.cpp | 16 +++++++++ 3 files changed, 188 insertions(+) create mode 100644 adw/src/toast.cpp create mode 100644 adw/src/toastoverlay.cpp (limited to 'adw/src') diff --git a/adw/src/toast.cpp b/adw/src/toast.cpp new file mode 100644 index 0000000..4f8d28a --- /dev/null +++ b/adw/src/toast.cpp @@ -0,0 +1,87 @@ +#include "turns/adw/toast.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +namespace turns::adw +{ + static_assert(static_cast(Toast::Priority::NORMAL) == ADW_TOAST_PRIORITY_NORMAL); + static_assert(static_cast(Toast::Priority::HIGH) == ADW_TOAST_PRIORITY_HIGH); + + struct Toast_Class : Glib::Class + { + auto init() -> Glib::Class const &; + auto static class_init_function(void * gclass, void * data) -> void; + auto static wrap_new(GObject * object) -> Glib::ObjectBase *; + }; + + auto Toast_Class::init() -> Glib::Class const & + { + if (!gtype_) + { + gtype_ = adw_toast_get_type(); + } + return *this; + } + + auto Toast_Class::wrap_new(GObject * object) -> Glib::ObjectBase * + { + return new Toast(ADW_TOAST(object)); + } + + Toast_Class Toast::s_class{}; + + Toast::Toast(Glib::ustring const & title) + : Glib::ObjectBase{nullptr} + , Glib::Object{Glib::ConstructParams{s_class.init(), "title", Glib::c_str_or_nullptr(title), nullptr}} + { + } + + auto Toast::get_type() -> GType + { + return s_class.init().get_type(); + } + + auto Toast::get_base_type() -> GType + { + return adw_toast_get_type(); + } + + auto Toast::dismiss() -> void + { + return adw_toast_dismiss(gobj()); + } + + Toast::Toast(Glib::ConstructParams const & params) + : Glib::Object{params} + { + } + + Toast::Toast(AdwToast * gobj) + : Glib::ObjectBase{nullptr} + , Glib::Object((GObject *)gobj) + { + } + +} // namespace turns::adw + +namespace Glib +{ + auto wrap(AdwToast * object, bool copy) -> Glib::RefPtr + { + return Glib::make_refptr_for_instance(dynamic_cast(Glib::wrap_auto(G_OBJECT(object), copy))); + } +} // namespace Glib \ No newline at end of file diff --git a/adw/src/toastoverlay.cpp b/adw/src/toastoverlay.cpp new file mode 100644 index 0000000..ca877a6 --- /dev/null +++ b/adw/src/toastoverlay.cpp @@ -0,0 +1,85 @@ +#include "turns/adw/toastoverlay.hpp" + +#include "turns/adw/toast.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +namespace turns::adw +{ + struct ToastOverlay_Class : Glib::Class + { + auto init() -> Glib::Class const &; + auto static wrap_new(GObject * object) -> Glib::ObjectBase *; + }; + + auto ToastOverlay_Class::init() -> Glib::Class const & + { + if (!gtype_) + { + gtype_ = adw_toast_overlay_get_type(); + } + return *this; + } + + auto ToastOverlay_Class::wrap_new(GObject * object) -> Glib::ObjectBase * + { + return new ToastOverlay(ADW_TOAST_OVERLAY(object)); + } + + ToastOverlay_Class ToastOverlay::s_class{}; + + auto ToastOverlay::get_type() -> GType + { + return s_class.init().get_type(); + } + + auto ToastOverlay::get_base_type() -> GType + { + return adw_toast_overlay_get_type(); + } + + auto ToastOverlay::add(Toast && toast) -> void + { + adw_toast_overlay_add_toast(gobj(), toast.gobj_copy()); + } + + ToastOverlay::ToastOverlay(Glib::ConstructParams const & params) + : Gtk::Widget{params} + { + } + + ToastOverlay::ToastOverlay(AdwToastOverlay * gobj) + : Glib::ObjectBase{nullptr} + , Gtk::Widget((GtkWidget *)gobj) + { + } + + ToastOverlay::ToastOverlay() + : Glib::ObjectBase{nullptr} + , Gtk::Widget{Glib::ConstructParams{s_class.init()}} + { + } + +} // namespace turns::adw + +namespace Glib +{ + auto wrap(AdwToastOverlay * object, bool copy) -> Glib::RefPtr + { + return Glib::make_refptr_for_instance( + dynamic_cast(Glib::wrap_auto(G_OBJECT(object), copy))); + } +} // namespace Glib \ No newline at end of file diff --git a/adw/src/wrap_init.cpp b/adw/src/wrap_init.cpp index 24bfad9..546f31e 100644 --- a/adw/src/wrap_init.cpp +++ b/adw/src/wrap_init.cpp @@ -1,6 +1,8 @@ #include "turns/adw/wrap_init.hpp" #include "turns/adw/application.hpp" +#include "turns/adw/toast.hpp" +#include "turns/adw/toastoverlay.hpp" #include @@ -14,11 +16,25 @@ namespace turns::adw auto static wrap_new(GObject * object) -> Glib::ObjectBase *; }; + struct Toast_Class + { + auto static wrap_new(GObject * object) -> Glib::ObjectBase *; + }; + + struct ToastOverlay_Class + { + auto static wrap_new(GObject * object) -> Glib::ObjectBase *; + }; + auto wrap_init() -> void { adw_init(); Glib::wrap_register(adw_application_get_type(), &Application_Class::wrap_new); g_type_ensure(Application::get_type()); + Glib::wrap_register(adw_toast_get_type(), &Toast_Class::wrap_new); + g_type_ensure(Toast::get_type()); + Glib::wrap_register(adw_toast_overlay_get_type(), &ToastOverlay_Class::wrap_new); + g_type_ensure(ToastOverlay::get_type()); } } // namespace turns::adw \ No newline at end of file -- cgit v1.2.3