diff options
Diffstat (limited to 'adw')
| -rw-r--r-- | adw/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | adw/include/turns/adw/switchrow.hpp | 80 | ||||
| -rw-r--r-- | adw/src/switchrow.cpp | 72 | ||||
| -rw-r--r-- | adw/src/wrap_init.cpp | 3 |
4 files changed, 156 insertions, 0 deletions
diff --git a/adw/CMakeLists.txt b/adw/CMakeLists.txt index ce0323f..f1ac616 100644 --- a/adw/CMakeLists.txt +++ b/adw/CMakeLists.txt @@ -5,6 +5,7 @@ add_library("adw" "src/preferencesdialog.cpp" "src/preferencespage.cpp" "src/preferencesrow.cpp" + "src/switchrow.cpp" "src/toast.cpp" "src/toastoverlay.cpp" "src/wrap_init.cpp" diff --git a/adw/include/turns/adw/switchrow.hpp b/adw/include/turns/adw/switchrow.hpp new file mode 100644 index 0000000..ed5190a --- /dev/null +++ b/adw/include/turns/adw/switchrow.hpp @@ -0,0 +1,80 @@ +#ifndef TURNS_ADW_SWITCH_ROW_HPP +#define TURNS_ADW_SWITCH_ROW_HPP + +#include "helpers/gobj_mixin.hpp" +#include "turns/adw/actionrow.hpp" +#include "turns/adw/helpers/properties.hpp" + +#include <glibmm/class.h> +#include <glibmm/refptr.h> +#include <glibmm/ustring.h> + +#include <gtkmm/widget.h> + +using AdwSwitchRow = struct _AdwSwitchRow; + +namespace turns::adw +{ + struct SwitchRow final : adw::ActionRow, + helpers::gobj_mixin<SwitchRow, AdwSwitchRow> + { + struct Class : Glib::Class + { + using BaseClassParent = AdwActionRowClass; + using BaseClassType = struct AdwSwitchRowClass; + using BaseObjectType = AdwSwitchRow; + using CppClassParent = adw::ActionRow; + using CppObjectType = SwitchRow; + + auto init() -> Glib::Class const &; + auto static class_init_function(void * gclass, void * data) -> void; + auto static wrap_new(GObject * object) -> Glib::ObjectBase *; + }; + + using BaseObjectType = Class::BaseObjectType; + using BaseClassType = Class::BaseClassType; + using CppObjectType = Class::CppObjectType; + using CppClassType = Class; + + using helpers::gobj_mixin<CppObjectType, BaseObjectType>::gobj; + using helpers::gobj_mixin<CppObjectType, BaseObjectType>::gobj_copy; + + explicit SwitchRow(); + SwitchRow(SwitchRow const & other) = delete; + SwitchRow(SwitchRow && other) noexcept = default; + + auto operator=(SwitchRow const & other) noexcept -> SwitchRow & = delete; + auto operator=(SwitchRow && other) noexcept -> SwitchRow & = default; + + auto static get_type() -> GType; + auto static get_base_type() -> GType; + + auto get_active(this auto && self) noexcept; + + auto get_active(Gtk::Widget & widget) noexcept -> CppObjectType &; + + auto property_active(this auto && self); + + protected: + explicit SwitchRow(Glib::ConstructParams const & params); + explicit SwitchRow(BaseObjectType * gobj); + }; + + auto SwitchRow::get_active(this auto && self) noexcept + { + return self.property_active().value(); + } + + auto SwitchRow::property_active(this auto && self) + { + return helpers::make_property_proxy<bool>(self, "active"); + } + +} // namespace turns::adw + +namespace Glib +{ + auto wrap(AdwSwitchRow * object, bool copy = false) -> Glib::RefPtr<turns::adw::SwitchRow>; +} // namespace Glib + +#endif
\ No newline at end of file diff --git a/adw/src/switchrow.cpp b/adw/src/switchrow.cpp new file mode 100644 index 0000000..8e9508d --- /dev/null +++ b/adw/src/switchrow.cpp @@ -0,0 +1,72 @@ +#include "turns/adw/switchrow.hpp" + +#include "turns/adw/actionrow.hpp" + +#include <glibmm/class.h> +#include <glibmm/object.h> +#include <glibmm/objectbase.h> +#include <glibmm/refptr.h> +#include <glibmm/wrap.h> + +#include <adwaita.h> +#include <gio/gio.h> +#include <glib-object.h> + +namespace turns::adw +{ + namespace + { + auto constinit _class = SwitchRow::Class{}; + } // namespace + + auto SwitchRow::Class::init() -> Glib::Class const & + { + if (!gtype_) + { + gtype_ = adw_switch_row_get_type(); + } + return *this; + } + + auto SwitchRow::Class::wrap_new(GObject * object) -> Glib::ObjectBase * + { + return new SwitchRow(ADW_SWITCH_ROW(object)); + } + + SwitchRow::SwitchRow() + : Glib::ObjectBase{nullptr} + , adw::ActionRow{Glib::ConstructParams{_class.init()}} + { + } + + auto SwitchRow::get_type() -> GType + { + return _class.init().get_type(); + } + + auto SwitchRow::get_base_type() -> GType + { + return adw_switch_row_get_type(); + } + + SwitchRow::SwitchRow(Glib::ConstructParams const & params) + : adw::ActionRow{params} + { + } + + SwitchRow::SwitchRow(BaseObjectType * gobj) + : Glib::ObjectBase{nullptr} + , adw::ActionRow(ADW_ACTION_ROW(gobj)) + { + } + +} // namespace turns::adw + +namespace Glib +{ + auto wrap(AdwSwitchRow * object, bool copy) -> Glib::RefPtr<turns::adw::SwitchRow> + { + return Glib::make_refptr_for_instance<turns::adw::SwitchRow>( + dynamic_cast<turns::adw::SwitchRow *>(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 6998f90..f77dacd 100644 --- a/adw/src/wrap_init.cpp +++ b/adw/src/wrap_init.cpp @@ -6,6 +6,7 @@ #include "turns/adw/preferencesdialog.hpp" #include "turns/adw/preferencespage.hpp" #include "turns/adw/preferencesrow.hpp" +#include "turns/adw/switchrow.hpp" #include "turns/adw/toast.hpp" #include "turns/adw/toastoverlay.hpp" @@ -30,6 +31,7 @@ namespace turns::adw WRAP_CLASS(PreferencesDialog, preferences_dialog); WRAP_CLASS(PreferencesPage, preferences_page); WRAP_CLASS(PreferencesRow, preferences_row); + WRAP_CLASS(SwitchRow, switch_row); WRAP_CLASS(ToastOverlay, toast_overlay); ENSURE_TYPE(ActionRow); @@ -39,6 +41,7 @@ namespace turns::adw ENSURE_TYPE(PreferencesDialog); ENSURE_TYPE(PreferencesPage); ENSURE_TYPE(PreferencesRow); + ENSURE_TYPE(SwitchRow); ENSURE_TYPE(ToastOverlay); } } // namespace turns::adw
\ No newline at end of file |
