From fe21003777718efac8743bf99c5388b3d6477be2 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 4 Apr 2025 19:56:43 +0200 Subject: adw: implement basic StyleManager --- adw/src/enums.cpp | 49 ++++++++++++++++++++++ adw/src/stylemanager.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++ adw/src/wrap_init.cpp | 3 ++ 3 files changed, 158 insertions(+) create mode 100644 adw/src/enums.cpp create mode 100644 adw/src/stylemanager.cpp (limited to 'adw/src') diff --git a/adw/src/enums.cpp b/adw/src/enums.cpp new file mode 100644 index 0000000..02dd74a --- /dev/null +++ b/adw/src/enums.cpp @@ -0,0 +1,49 @@ +#include "adwaitamm/enums.hpp" + +#include + +#include + +#include + +namespace +{ + template + auto constexpr matches = + static_cast>(Wrapped) == static_cast>(Unwrapped); +} // namespace + +namespace Adwaita +{ + + static_assert(matches); + static_assert(matches); + static_assert(matches); + static_assert(matches); + static_assert(matches); + static_assert(matches); + static_assert(matches); + static_assert(matches); + static_assert(matches); + + static_assert(matches); + static_assert(matches); + static_assert(matches); + static_assert(matches); + static_assert(matches); + +} // namespace Adwaita + +namespace Glib +{ +#define VALUE_SPECIALIZATION(Enum, AdwEnumName) \ + auto Value::value_type() -> GType \ + { \ + return adw_##AdwEnumName##_get_type(); \ + } + + VALUE_SPECIALIZATION(AccentColor, accent_color) + VALUE_SPECIALIZATION(ColorScheme, color_scheme) + +#undef VALUE_SPECIALIZATION +} // namespace Glib \ No newline at end of file diff --git a/adw/src/stylemanager.cpp b/adw/src/stylemanager.cpp new file mode 100644 index 0000000..74fe40a --- /dev/null +++ b/adw/src/stylemanager.cpp @@ -0,0 +1,106 @@ +#include "adwaitamm/stylemanager.hpp" + +#include "adwaitamm/enums.hpp" + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +namespace Adwaita +{ + namespace + { + auto constinit _class = StyleManager::Class{}; + } // namespace + + auto StyleManager::Class::init() -> Glib::Class const & + { + if (!gtype_) + { + class_init_func_ = &StyleManager::Class::class_init_function; + register_derived_type(adw_style_manager_get_type()); + } + return *this; + } + + auto StyleManager::Class::class_init_function(void * gclass, void * data) -> void + { + auto const klass = static_cast(gclass); + Glib::Object_Class::class_init_function(klass, data); + } + + auto StyleManager::Class::wrap_new(GObject * object) -> Glib::ObjectBase * + { + return new StyleManager(ADW_STYLE_MANAGER(object)); + } + + auto StyleManager::get_default() -> StyleManager * + { + return Glib::wrap(adw_style_manager_get_default()); + } + + auto StyleManager::for_display(Gdk::Display & display) -> StyleManager * + { + return Glib::wrap(adw_style_manager_get_for_display(Glib::unwrap(&display))); + } + + auto StyleManager::get_type() -> GType + { + return _class.init().get_type(); + } + + auto StyleManager::get_base_type() -> GType + { + return adw_style_manager_get_type(); + } + + StyleManager::StyleManager(Glib::ConstructParams const & params) + : Glib::Object{params} + { + } + + StyleManager::StyleManager(BaseObjectType * gobj) + : Glib::Object(G_OBJECT(gobj)) + { + } + + StyleManager::StyleManager() + : Glib::ObjectBase{nullptr} + , Glib::Object{Glib::ConstructParams{_class.init()}} + { + adw_init(); + } + + auto StyleManager::get_accent_color() const -> AccentColor + { + return static_cast(adw_style_manager_get_accent_color(const_cast(unwrap(this)))); + } + + auto StyleManager::set_color_scheme(ColorScheme value) -> void + { + adw_style_manager_set_color_scheme(unwrap(this), static_cast(value)); + } + +} // namespace Adwaita + +namespace Glib +{ + auto wrap(AdwStyleManager * object) -> Adwaita::StyleManager * + { + return dynamic_cast(Glib::wrap_auto(G_OBJECT(object))); + } +} // namespace Glib \ No newline at end of file diff --git a/adw/src/wrap_init.cpp b/adw/src/wrap_init.cpp index 8cad77d..f048633 100644 --- a/adw/src/wrap_init.cpp +++ b/adw/src/wrap_init.cpp @@ -9,6 +9,7 @@ #include "adwaitamm/preferencesdialog.hpp" #include "adwaitamm/preferencespage.hpp" #include "adwaitamm/preferencesrow.hpp" +#include "adwaitamm/stylemanager.hpp" #include "adwaitamm/switchrow.hpp" #include "adwaitamm/toast.hpp" #include "adwaitamm/toastoverlay.hpp" @@ -34,6 +35,7 @@ namespace Adwaita WRAP_CLASS(PreferencesDialog, preferences_dialog); WRAP_CLASS(PreferencesPage, preferences_page); WRAP_CLASS(PreferencesRow, preferences_row); + WRAP_CLASS(StyleManager, style_manager); WRAP_CLASS(SwitchRow, switch_row); WRAP_CLASS(Toast, toast); WRAP_CLASS(ToastOverlay, toast_overlay); @@ -47,6 +49,7 @@ namespace Adwaita ENSURE_TYPE(PreferencesDialog); ENSURE_TYPE(PreferencesPage); ENSURE_TYPE(PreferencesRow); + ENSURE_TYPE(StyleManager); ENSURE_TYPE(SwitchRow); ENSURE_TYPE(Toast); ENSURE_TYPE(ToastOverlay); -- cgit v1.2.3