diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-04-28 11:22:20 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-04-28 11:22:20 +0200 |
| commit | 0b4f979c001835b20ff75a848eee83f59c1397c0 (patch) | |
| tree | b1fe6df13af1e873f8bff9b4f822d95d7b09a00f | |
| parent | 3fe6119b93141d74c9f34f69d2b3b6ae016c2abf (diff) | |
| download | turns-0b4f979c001835b20ff75a848eee83f59c1397c0.tar.xz turns-0b4f979c001835b20ff75a848eee83f59c1397c0.zip | |
adw: implement SpinRow
| -rw-r--r-- | adw/include/adwaitamm/private/spinrow_p.hpp | 35 | ||||
| -rw-r--r-- | adw/include/adwaitamm/spinrow.hpp | 117 | ||||
| -rw-r--r-- | adw/src/private/spinrow_p.cpp | 42 | ||||
| -rw-r--r-- | adw/src/spinrow.cpp | 383 | ||||
| -rw-r--r-- | adw/src/wrap_init.cpp | 4 |
5 files changed, 581 insertions, 0 deletions
diff --git a/adw/include/adwaitamm/private/spinrow_p.hpp b/adw/include/adwaitamm/private/spinrow_p.hpp new file mode 100644 index 0000000..f99c28d --- /dev/null +++ b/adw/include/adwaitamm/private/spinrow_p.hpp @@ -0,0 +1,35 @@ +/** + * @author Felix Morgner (felix.morgner@gmail.com) + * @copyright Copyright (c) 2025 + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifndef LIBADWAITAMM_PRIVATE_SPIN_ROW_P_HPP +#define LIBADWAITAMM_PRIVATE_SPIN_ROW_P_HPP + +#include "adwaitamm/private/actionrow_p.hpp" + +#include <glibmm/class.h> +#include <glibmm/objectbase.h> + +#define _ADWAITA_INSIDE +#include <adw-spin-row.h> +#undef _ADWAITA_INSIDE + +namespace Adwaita +{ + struct SpinRow_Class : Glib::Class + { + using BaseClassParent = AdwActionRowClass; + using BaseClassType = AdwSpinRowClass; + using BaseObjectType = AdwSpinRow; + using CppClassParent = ActionRow_Class; + using CppObjectType = struct SpinRow; + + auto init() -> Glib::Class const &; + auto static class_init_function(void * gclass, void * data) -> void; + auto static wrap_new(GObject * object) -> Glib::ObjectBase *; + }; +} // namespace Adwaita + +#endif
\ No newline at end of file diff --git a/adw/include/adwaitamm/spinrow.hpp b/adw/include/adwaitamm/spinrow.hpp new file mode 100644 index 0000000..f5e02b6 --- /dev/null +++ b/adw/include/adwaitamm/spinrow.hpp @@ -0,0 +1,117 @@ +/** + * @author Felix Morgner (felix.morgner@gmail.com) + * @copyright Copyright (c) 2025 + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifndef LIBADWAITAMM_SPIN_ROW_HPP +#define LIBADWAITAMM_SPIN_ROW_HPP + +#include "adwaitamm/actionrow.hpp" +#include "adwaitamm/helpers/gobj_mixin.hpp" + +#include <glibmm/object.h> +#include <glibmm/propertyproxy.h> +#include <glibmm/refptr.h> +#include <glibmm/signalproxy.h> + +#include <gtkmm/adjustment.h> +#include <gtkmm/spinbutton.h> + +#include <glib-object.h> + +#define _ADWAITA_INSIDE +#include <adw-spin-row.h> +#undef _ADWAITA_INSIDE + +using AdwSpinRow = struct _AdwSpinRow; + +namespace Adwaita +{ + struct SpinRow final : ActionRow, + helpers::gobj_mixin<SpinRow, AdwSpinRow> + { + using BaseObjectType = AdwSpinRow; + using BaseClassType = AdwSpinRowClass; + using CppObjectType = struct SpinRow; + using CppClassType = struct SpinRow_Class; + using helpers::gobj_mixin<CppObjectType, BaseObjectType>::gobj; + using helpers::gobj_mixin<CppObjectType, BaseObjectType>::gobj_copy; + +#pragma mark - Special Member Functions + SpinRow(Gtk::Adjustment & adjustment, double climb_rate, unsigned int digits); + SpinRow(double min, double max, double step); + SpinRow(SpinRow const & other) = delete; + SpinRow(SpinRow && other) noexcept = default; + + auto operator=(SpinRow const & other) noexcept -> SpinRow & = delete; + auto operator=(SpinRow && other) noexcept -> SpinRow & = default; + +#pragma mark - GObject Support + auto static get_type() -> GType; + auto static get_base_type() -> GType; + +#pragma mark - Functions + auto configure(Gtk::Adjustment & adjustment, double climb_rate, unsigned int digits) -> void; + auto update() -> void; + +#pragma mark - Getters + [[nodiscard]] auto get_adjustment() const -> Glib::RefPtr<Gtk::Adjustment>; + [[nodiscard]] auto get_climb_rate() const -> double; + [[nodiscard]] auto get_digits() const -> unsigned int; + [[nodiscard]] auto get_numeric() const -> bool; + [[nodiscard]] auto get_snap_to_ticks() const -> bool; + [[nodiscard]] auto get_update_policy() const -> Gtk::SpinButton::UpdatePolicy; + [[nodiscard]] auto get_value() const -> double; + [[nodiscard]] auto get_wrap() const -> bool; + +#pragma mark - Setters + auto set_adjustment(Gtk::Adjustment & value) -> void; + auto set_climb_rate(double value) -> void; + auto set_digits(unsigned int value) -> void; + auto set_numeric(bool value) -> void; + auto set_range(double min, double max) -> void; + auto set_snap_to_ticks(bool value) -> void; + auto set_update_policy(Gtk::SpinButton::UpdatePolicy value) -> void; + auto set_value(double value) -> void; + auto set_wrap(bool value) -> void; + +#pragma mark - Properties + [[nodiscard]] auto property_adjustment() -> Glib::PropertyProxy<Glib::RefPtr<Gtk::Adjustment>>; + [[nodiscard]] auto property_adjustment() const -> Glib::PropertyProxy_ReadOnly<Glib::RefPtr<Gtk::Adjustment>>; + [[nodiscard]] auto property_climb_rate() -> Glib::PropertyProxy<double>; + [[nodiscard]] auto property_climb_rate() const -> Glib::PropertyProxy_ReadOnly<double>; + [[nodiscard]] auto property_digits() -> Glib::PropertyProxy<unsigned int>; + [[nodiscard]] auto property_digits() const -> Glib::PropertyProxy_ReadOnly<unsigned int>; + [[nodiscard]] auto property_numeric() -> Glib::PropertyProxy<bool>; + [[nodiscard]] auto property_numeric() const -> Glib::PropertyProxy_ReadOnly<bool>; + [[nodiscard]] auto property_snap_to_ticks() -> Glib::PropertyProxy<bool>; + [[nodiscard]] auto property_snap_to_ticks() const -> Glib::PropertyProxy_ReadOnly<bool>; + [[nodiscard]] auto property_update_policy() -> Glib::PropertyProxy<Gtk::SpinButton::UpdatePolicy>; + [[nodiscard]] auto property_update_policy() const -> Glib::PropertyProxy_ReadOnly<Gtk::SpinButton::UpdatePolicy>; + [[nodiscard]] auto property_value() -> Glib::PropertyProxy<double>; + [[nodiscard]] auto property_value() const -> Glib::PropertyProxy_ReadOnly<double>; + [[nodiscard]] auto property_wrap() -> Glib::PropertyProxy<bool>; + [[nodiscard]] auto property_wrap() const -> Glib::PropertyProxy_ReadOnly<bool>; + +#pragma mark - Signals + auto signal_input() -> Glib::SignalProxy<int(double &)>; + auto signal_output() -> Glib::SignalProxy<bool()>; + auto signal_wrapped() -> Glib::SignalProxy<void()>; + + protected: + friend SpinRow_Class; + +#pragma mark - Internal Constructors + explicit SpinRow(Glib::ConstructParams const & params); + explicit SpinRow(BaseObjectType * gobj); + }; + +} // namespace Adwaita + +namespace Glib +{ + auto wrap(AdwSpinRow * object, bool copy = false) -> Adwaita::SpinRow *; +} // namespace Glib + +#endif
\ No newline at end of file diff --git a/adw/src/private/spinrow_p.cpp b/adw/src/private/spinrow_p.cpp new file mode 100644 index 0000000..1bd0085 --- /dev/null +++ b/adw/src/private/spinrow_p.cpp @@ -0,0 +1,42 @@ +/** + * @author Felix Morgner (felix.morgner@gmail.com) + * @copyright Copyright (c) 2025 + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "adwaitamm/private/spinrow_p.hpp" + +#include "adwaitamm/spinrow.hpp" + +#include <glibmm/class.h> +#include <glibmm/object.h> +#include <glibmm/objectbase.h> + +#include <gtkmm/object.h> + +#include <adwaita.h> + +namespace Adwaita +{ + auto SpinRow_Class::init() -> Glib::Class const & + { + if (!gtype_) + { + class_init_func_ = &class_init_function; + gtype_ = adw_spin_row_get_type(); + } + return *this; + } + + auto SpinRow_Class::class_init_function(void * gclass, void * data) -> void + { + auto const klass = static_cast<BaseClassType *>(gclass); + CppClassParent::class_init_function(klass, data); + + } + + auto SpinRow_Class::wrap_new(GObject * object) -> Glib::ObjectBase * + { + return Gtk::manage(new SpinRow(ADW_SPIN_ROW(object))); + } +} // namespace Adwaita
\ No newline at end of file diff --git a/adw/src/spinrow.cpp b/adw/src/spinrow.cpp new file mode 100644 index 0000000..0f86ca0 --- /dev/null +++ b/adw/src/spinrow.cpp @@ -0,0 +1,383 @@ +/** + * @author Felix Morgner (felix.morgner@gmail.com) + * @copyright Copyright (c) 2025 + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "adwaitamm/spinrow.hpp" + +#include "adwaitamm/actionrow.hpp" +#include "adwaitamm/private/spinrow_p.hpp" + +#include <sigc++/functors/slot.h> + +#include <glibmm/exceptionhandler.h> +#include <glibmm/object.h> +#include <glibmm/objectbase.h> +#include <glibmm/propertyproxy.h> +#include <glibmm/refptr.h> +#include <glibmm/signalproxy.h> +#include <glibmm/wrap.h> + +#include <gtkmm/adjustment.h> +#include <gtkmm/spinbutton.h> + +#include <glib-object.h> +#include <glib.h> +#include <gtk/gtk.h> + +namespace Adwaita +{ + namespace + { + auto constinit _class = SpinRow_Class{}; + + namespace property_name + { + auto constexpr adjustment = "adjustment"; + auto constexpr climb_rate = "climb-rate"; + auto constexpr digits = "digits"; + auto constexpr numeric = "numeric"; + auto constexpr snap_to_ticks = "snap-to-ticks"; + auto constexpr update_policy = "update-policy"; + auto constexpr value = "value"; + auto constexpr wrap = "wrap"; + } // namespace property_name + + namespace signal_handler + { + auto input(AdwSpinRow * self, double * new_value, void * user_data) -> int + try + { + auto object = Glib::wrap(self); + if (object) + { + auto slot = Glib::SignalProxyNormal::data_to_slot(user_data); + if (slot) + { + return (*static_cast<sigc::slot<int(double &)> *>(slot))(*new_value); + } + } + return {}; + } + catch (...) + { + Glib::exception_handlers_invoke(); + return {}; + } + + auto input_notify(AdwSpinRow * self, double * new_value, void * user_data) -> gboolean + try + { + auto object = Glib::wrap(self); + if (object) + { + auto slot = Glib::SignalProxyNormal::data_to_slot(user_data); + if (slot) + { + (*static_cast<sigc::slot<int(double &)> *>(slot))(*new_value); + } + } + return {}; + } + catch (...) + { + Glib::exception_handlers_invoke(); + return {}; + } + + auto output(AdwSpinRow * self, void * user_data) -> gboolean + try + { + auto object = Glib::wrap(self); + if (object) + { + auto slot = Glib::SignalProxyNormal::data_to_slot(user_data); + if (slot) + { + return static_cast<gboolean>((*static_cast<sigc::slot<bool()> *>(slot))()); + } + } + return {}; + } + catch (...) + { + Glib::exception_handlers_invoke(); + return {}; + } + + auto output_notify(AdwSpinRow * self, void * user_data) -> gboolean + try + { + auto object = Glib::wrap(self); + if (object) + { + auto slot = Glib::SignalProxyNormal::data_to_slot(user_data); + if (slot) + { + (*static_cast<sigc::slot<bool()> *>(slot))(); + } + } + return {}; + } + catch (...) + { + Glib::exception_handlers_invoke(); + return {}; + } + } // namespace signal_handler + + namespace signal_info + { + auto const input = Glib::SignalProxyInfo{ + "input", + reinterpret_cast<GCallback>(&signal_handler::input), + reinterpret_cast<GCallback>(&signal_handler::input_notify), + }; + + auto const output = Glib::SignalProxyInfo{ + "output", + reinterpret_cast<GCallback>(&signal_handler::output), + reinterpret_cast<GCallback>(&signal_handler::output_notify), + }; + + auto const wrapped = Glib::SignalProxyInfo{ + "wrapped", + reinterpret_cast<GCallback>(&Glib::SignalProxyNormal::slot0_void_callback), + reinterpret_cast<GCallback>(&Glib::SignalProxyNormal::slot0_void_callback), + }; + } // namespace signal_info + } // namespace + + SpinRow::SpinRow(Gtk::Adjustment & adjustment, double climb_rate, unsigned int digits) + : Glib::ObjectBase{nullptr} + , ActionRow{Glib::ConstructParams{_class.init(), "adjustment", unwrap(&adjustment), "climb-rate", climb_rate, "digits", digits, nullptr}} + { + } + + SpinRow::SpinRow(double min, double max, double step) + : Glib::ObjectBase{nullptr} + , ActionRow{ADW_ACTION_ROW(adw_spin_row_new_with_range(min, max, step))} + { + } + + auto SpinRow::get_type() -> GType + { + return _class.init().get_type(); + } + + auto SpinRow::get_base_type() -> GType + { + return adw_spin_row_get_type(); + } + + auto SpinRow::configure(Gtk::Adjustment & adjustment, double climb_rate, unsigned int digits) -> void + { + return adw_spin_row_configure(unwrap(this), unwrap(&adjustment), climb_rate, digits); + } + + auto SpinRow::update() -> void + { + return adw_spin_row_update(unwrap(this)); + } + + auto SpinRow::get_adjustment() const -> Glib::RefPtr<Gtk::Adjustment> + { + // Take a copy, since SpinRow owns the adjustment + return Glib::wrap(adw_spin_row_get_adjustment(const_cast<BaseObjectType *>(unwrap(this))), true); + } + + auto SpinRow::get_climb_rate() const -> double + { + return adw_spin_row_get_climb_rate(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::get_digits() const -> unsigned int + { + return adw_spin_row_get_digits(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::get_numeric() const -> bool + { + return adw_spin_row_get_numeric(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::get_snap_to_ticks() const -> bool + { + return adw_spin_row_get_snap_to_ticks(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::get_update_policy() const -> Gtk::SpinButton::UpdatePolicy + { + return static_cast<Gtk::SpinButton::UpdatePolicy>(adw_spin_row_get_update_policy(const_cast<BaseObjectType *>(unwrap(this)))); + } + + auto SpinRow::get_value() const -> double + { + return adw_spin_row_get_value(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::get_wrap() const -> bool + { + return adw_spin_row_get_wrap(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::set_adjustment(Gtk::Adjustment & value) -> void + { + return adw_spin_row_set_adjustment(unwrap(this), unwrap(&value)); + } + + auto SpinRow::set_climb_rate(double value) -> void + { + return adw_spin_row_set_climb_rate(unwrap(this), value); + } + + auto SpinRow::set_digits(unsigned int value) -> void + { + return adw_spin_row_set_digits(unwrap(this), value); + } + + auto SpinRow::set_numeric(bool value) -> void + { + return adw_spin_row_set_numeric(unwrap(this), value); + } + + auto SpinRow::set_range(double min, double max) -> void + { + return adw_spin_row_set_range(unwrap(this), min, max); + } + + auto SpinRow::set_snap_to_ticks(bool value) -> void + { + return adw_spin_row_set_snap_to_ticks(unwrap(this), value); + } + + auto SpinRow::set_update_policy(Gtk::SpinButton::UpdatePolicy value) -> void + { + return adw_spin_row_set_update_policy(unwrap(this), static_cast<GtkSpinButtonUpdatePolicy>(value)); + } + + auto SpinRow::set_value(double value) -> void + { + return adw_spin_row_set_value(unwrap(this), value); + } + + auto SpinRow::set_wrap(bool value) -> void + { + return adw_spin_row_set_wrap(unwrap(this), value); + } + + [[nodiscard]] auto SpinRow::property_adjustment() -> Glib::PropertyProxy<Glib::RefPtr<Gtk::Adjustment>> + { + return {this, property_name::adjustment}; + } + + [[nodiscard]] auto SpinRow::property_adjustment() const -> Glib::PropertyProxy_ReadOnly<Glib::RefPtr<Gtk::Adjustment>> + { + return {this, property_name::adjustment}; + } + + [[nodiscard]] auto SpinRow::property_climb_rate() -> Glib::PropertyProxy<double> + { + return {this, property_name::climb_rate}; + } + + [[nodiscard]] auto SpinRow::property_climb_rate() const -> Glib::PropertyProxy_ReadOnly<double> + { + return {this, property_name::climb_rate}; + } + + [[nodiscard]] auto SpinRow::property_digits() -> Glib::PropertyProxy<unsigned int> + { + return {this, property_name::digits}; + } + + [[nodiscard]] auto SpinRow::property_digits() const -> Glib::PropertyProxy_ReadOnly<unsigned int> + { + return {this, property_name::digits}; + } + + [[nodiscard]] auto SpinRow::property_numeric() -> Glib::PropertyProxy<bool> + { + return {this, property_name::numeric}; + } + + [[nodiscard]] auto SpinRow::property_numeric() const -> Glib::PropertyProxy_ReadOnly<bool> + { + return {this, property_name::numeric}; + } + + [[nodiscard]] auto SpinRow::property_snap_to_ticks() -> Glib::PropertyProxy<bool> + { + return {this, property_name::snap_to_ticks}; + } + + [[nodiscard]] auto SpinRow::property_snap_to_ticks() const -> Glib::PropertyProxy_ReadOnly<bool> + { + return {this, property_name::snap_to_ticks}; + } + + [[nodiscard]] auto SpinRow::property_update_policy() -> Glib::PropertyProxy<Gtk::SpinButton::UpdatePolicy> + { + return {this, property_name::update_policy}; + } + + [[nodiscard]] auto SpinRow::property_update_policy() const -> Glib::PropertyProxy_ReadOnly<Gtk::SpinButton::UpdatePolicy> + { + return {this, property_name::update_policy}; + } + + [[nodiscard]] auto SpinRow::property_value() -> Glib::PropertyProxy<double> + { + return {this, property_name::value}; + } + + [[nodiscard]] auto SpinRow::property_value() const -> Glib::PropertyProxy_ReadOnly<double> + { + return {this, property_name::value}; + } + + [[nodiscard]] auto SpinRow::property_wrap() -> Glib::PropertyProxy<bool> + { + return {this, property_name::wrap}; + } + + [[nodiscard]] auto SpinRow::property_wrap() const -> Glib::PropertyProxy_ReadOnly<bool> + { + return {this, property_name::wrap}; + } + + auto SpinRow::signal_input() -> Glib::SignalProxy<int(double &)> + { + return {this, &signal_info::input}; + } + + auto SpinRow::signal_output() -> Glib::SignalProxy<bool()> + { + return {this, &signal_info::output}; + } + + auto SpinRow::signal_wrapped() -> Glib::SignalProxy<void()> + { + return {this, &signal_info::wrapped}; + } + + SpinRow::SpinRow(Glib::ConstructParams const & params) + : ActionRow{params} + { + } + + SpinRow::SpinRow(BaseObjectType * gobj) + : ActionRow(ADW_ACTION_ROW(gobj)) + { + } + +} // namespace Adwaita + +namespace Glib +{ + auto wrap(AdwSpinRow * object, bool copy) -> Adwaita::SpinRow * + { + return dynamic_cast<Adwaita::SpinRow *>(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 d7dece1..ae68fd9 100644 --- a/adw/src/wrap_init.cpp +++ b/adw/src/wrap_init.cpp @@ -26,11 +26,13 @@ #include "adwaitamm/private/preferencesdialog_p.hpp" // IWYU pragma: keep - required for gobj class definition. #include "adwaitamm/private/preferencespage_p.hpp" // IWYU pragma: keep - required for gobj class definition. #include "adwaitamm/private/preferencesrow_p.hpp" // IWYU pragma: keep - required for gobj class definition. +#include "adwaitamm/private/spinrow_p.hpp" #include "adwaitamm/private/stylemanager_p.hpp" #include "adwaitamm/private/switchrow_p.hpp" #include "adwaitamm/private/toast_p.hpp" #include "adwaitamm/private/toastoverlay_p.hpp" #include "adwaitamm/private/windowtitle_p.hpp" +#include "adwaitamm/spinrow.hpp" #include "adwaitamm/stylemanager.hpp" #include "adwaitamm/switchrow.hpp" #include "adwaitamm/toast.hpp" @@ -59,6 +61,7 @@ namespace Adwaita WRAP_CLASS(PreferencesDialog, preferences_dialog); WRAP_CLASS(PreferencesPage, preferences_page); WRAP_CLASS(PreferencesRow, preferences_row); + WRAP_CLASS(SpinRow, spin_row); WRAP_CLASS(StyleManager, style_manager); WRAP_CLASS(SwitchRow, switch_row); WRAP_CLASS(Toast, toast); @@ -75,6 +78,7 @@ namespace Adwaita ENSURE_TYPE(PreferencesDialog); ENSURE_TYPE(PreferencesPage); ENSURE_TYPE(PreferencesRow); + ENSURE_TYPE(SpinRow); ENSURE_TYPE(StyleManager); ENSURE_TYPE(SwitchRow); ENSURE_TYPE(Toast); |
