diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-03-27 12:05:53 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-03-27 12:05:53 +0100 |
| commit | 0d9e3328a2e1b017b712c30ccb144d5ea0b45f33 (patch) | |
| tree | dedd27c90feb763ec07435c98c897c3c6943f530 | |
| parent | 5467a7c2b1fb1831ca726d1ecb6b46010d146ebc (diff) | |
| download | turns-0d9e3328a2e1b017b712c30ccb144d5ea0b45f33.tar.xz turns-0d9e3328a2e1b017b712c30ccb144d5ea0b45f33.zip | |
adw: extend dialog
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | adw/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | adw/include/turns/adw/breakpoint.hpp | 112 | ||||
| -rw-r--r-- | adw/include/turns/adw/dialog.hpp | 5 | ||||
| -rw-r--r-- | adw/src/breakpoint.cpp | 160 | ||||
| -rw-r--r-- | adw/src/dialog.cpp | 21 | ||||
| -rw-r--r-- | adw/src/wrap_init.cpp | 3 | ||||
| -rw-r--r-- | ui/include/turns/ui/windows/participant_editor.hpp | 3 | ||||
| -rw-r--r-- | ui/src/windows/participant_editor.cpp | 10 |
9 files changed, 305 insertions, 13 deletions
@@ -2,4 +2,5 @@ /build /ch.arknet.Turns /coverage -/coverage.info
\ No newline at end of file +/coverage.info +/leaks.log
\ No newline at end of file diff --git a/adw/CMakeLists.txt b/adw/CMakeLists.txt index 49ac424..28b3ae1 100644 --- a/adw/CMakeLists.txt +++ b/adw/CMakeLists.txt @@ -2,6 +2,7 @@ add_library("adw" "src/actionrow.cpp" "src/application.cpp" "src/applicationwindow.cpp" + "src/breakpoint.cpp" "src/dialog.cpp" "src/preferencesdialog.cpp" "src/preferencespage.cpp" diff --git a/adw/include/turns/adw/breakpoint.hpp b/adw/include/turns/adw/breakpoint.hpp new file mode 100644 index 0000000..b274bbb --- /dev/null +++ b/adw/include/turns/adw/breakpoint.hpp @@ -0,0 +1,112 @@ +#ifndef TURNS_ADW_BREAKPOINT_HPP +#define TURNS_ADW_BREAKPOINT_HPP + +#include "turns/adw/helpers/gobj_mixin.hpp" + +#include <glibmm/object.h> +#include <glibmm/objectbase.h> +#include <glibmm/propertyproxy.h> +#include <glibmm/refptr.h> +#include <glibmm/ustring.h> + +#include <gtkmm/buildable.h> + +#include <glib-object.h> + +#include <optional> + +#define _ADWAITA_INSIDE +#include <adw-breakpoint.h> +#undef _ADWAITA_INSIDE + +namespace turns::adw +{ + struct BreakpointCondition + { + enum struct LengthType : int + { + min_width, + max_width, + min_height, + max_height, + }; + + enum struct RatioType : int + { + min_aspect_ratio, + max_aspect_ratio + }; + + BreakpointCondition(BreakpointCondition const & other); + BreakpointCondition(BreakpointCondition && other); + BreakpointCondition(LengthType type, double value, int unit); // FIXME: replace unit type with actual enum. + BreakpointCondition(RatioType type, int width, int height); + + ~BreakpointCondition() noexcept; + + auto operator&&(BreakpointCondition & rhs) & -> BreakpointCondition; + auto operator||(BreakpointCondition & lhs) & -> BreakpointCondition; + + explicit operator Glib::ustring() const; + + auto static parse(Glib::ustring str) -> std::optional<BreakpointCondition>; + + private: + friend struct Breakpoint; + + explicit BreakpointCondition(AdwBreakpointCondition * object); + + AdwBreakpointCondition * m_object{nullptr}; + }; + + struct Breakpoint final : Glib::Object, + Gtk::Buildable, + helpers::gobj_mixin<Breakpoint, AdwBreakpoint> + { + struct Class : Glib::Class + { + using BaseClassParent = GObjectClass; + using BaseClassType = AdwBreakpointClass; + using BaseObjectType = AdwBreakpoint; + using CppClassParent = struct Glib::Object_Class; + using CppObjectType = Breakpoint; + + 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 Breakpoint(BreakpointCondition & condition); + Breakpoint(Breakpoint const & other) = delete; + Breakpoint(Breakpoint && other) noexcept = default; + + auto operator=(Breakpoint const & other) noexcept -> Breakpoint & = delete; + auto operator=(Breakpoint && other) noexcept -> Breakpoint & = default; + + auto static get_type() -> GType; + auto static get_base_type() -> GType; + + auto property_condition() -> Glib::PropertyProxy<BreakpointCondition *>; + + protected: + explicit Breakpoint(Glib::ConstructParams const & params); + explicit Breakpoint(BaseObjectType * gobj); + }; + +} // namespace turns::adw + +namespace Glib +{ + auto wrap(AdwBreakpoint * object, bool copy = false) -> Glib::RefPtr<turns::adw::Breakpoint>; +} // namespace Glib + + +#endif
\ No newline at end of file diff --git a/adw/include/turns/adw/dialog.hpp b/adw/include/turns/adw/dialog.hpp index 75a095c..316a218 100644 --- a/adw/include/turns/adw/dialog.hpp +++ b/adw/include/turns/adw/dialog.hpp @@ -2,11 +2,13 @@ #define TURNS_ADW_DIALOG_HPP #include "helpers/gobj_mixin.hpp" +#include "turns/adw/breakpoint.hpp" #include <glibmm/class.h> #include <glibmm/object.h> #include <glibmm/objectbase.h> #include <glibmm/refptr.h> +#include <glibmm/ustring.h> #include <gtkmm/widget.h> @@ -53,7 +55,10 @@ namespace turns::adw auto static get_type() -> GType; auto static get_base_type() -> GType; + auto add_breakpoint(adw::Breakpoint && breakpoint) -> void; + auto close() -> void; auto present(Gtk::Widget * parent) -> void; + auto set_title(Glib::ustring const & str) -> void; protected: explicit Dialog(Glib::ConstructParams const & params); diff --git a/adw/src/breakpoint.cpp b/adw/src/breakpoint.cpp new file mode 100644 index 0000000..eb857ad --- /dev/null +++ b/adw/src/breakpoint.cpp @@ -0,0 +1,160 @@ +#include "turns/adw/breakpoint.hpp" + +#include "turns/adw/helpers/properties.hpp" + +#include <glibmm/class.h> +#include <glibmm/object.h> +#include <glibmm/objectbase.h> +#include <glibmm/private/object_p.h> +#include <glibmm/propertyproxy.h> +#include <glibmm/refptr.h> +#include <glibmm/ustring.h> +#include <glibmm/wrap.h> + +#include <glib-object.h> + +#include <optional> +#include <utility> + +namespace turns::adw +{ + + static_assert(static_cast<int>(BreakpointCondition::LengthType::min_width) == ADW_BREAKPOINT_CONDITION_MIN_WIDTH); + static_assert(static_cast<int>(BreakpointCondition::LengthType::max_width) == ADW_BREAKPOINT_CONDITION_MAX_WIDTH); + static_assert(static_cast<int>(BreakpointCondition::LengthType::min_height) == ADW_BREAKPOINT_CONDITION_MIN_HEIGHT); + static_assert(static_cast<int>(BreakpointCondition::LengthType::max_height) == ADW_BREAKPOINT_CONDITION_MAX_HEIGHT); + + static_assert(static_cast<int>(BreakpointCondition::RatioType::min_aspect_ratio) == ADW_BREAKPOINT_CONDITION_MIN_ASPECT_RATIO); + static_assert(static_cast<int>(BreakpointCondition::RatioType::max_aspect_ratio) == ADW_BREAKPOINT_CONDITION_MAX_ASPECT_RATIO); + + BreakpointCondition::BreakpointCondition(BreakpointCondition const & other) + : BreakpointCondition{adw_breakpoint_condition_copy(other.m_object)} + { + } + + BreakpointCondition::BreakpointCondition(BreakpointCondition && other) + : BreakpointCondition{std::exchange(other.m_object, nullptr)} + { + } + + BreakpointCondition::BreakpointCondition(LengthType type, double value, int unit) + : BreakpointCondition{adw_breakpoint_condition_new_length(static_cast<AdwBreakpointConditionLengthType>(static_cast<int>(type)), + value, + static_cast<AdwLengthUnit>(unit))} + { + } + + BreakpointCondition::BreakpointCondition(RatioType type, int width, int height) + : BreakpointCondition{ + adw_breakpoint_condition_new_ratio(static_cast<AdwBreakpointConditionRatioType>(static_cast<int>(type)), width, height)} + { + } + + BreakpointCondition::BreakpointCondition(AdwBreakpointCondition * object) + : m_object{object} + { + } + + BreakpointCondition::~BreakpointCondition() noexcept + { + if (m_object) + { + adw_breakpoint_condition_free(m_object); + m_object = nullptr; + } + } + + auto BreakpointCondition::operator&&(BreakpointCondition & rhs) & -> BreakpointCondition + { + return BreakpointCondition{adw_breakpoint_condition_new_and(m_object, rhs.m_object)}; + } + + auto BreakpointCondition::operator||(BreakpointCondition & rhs) & -> BreakpointCondition + { + return BreakpointCondition{adw_breakpoint_condition_new_or(m_object, rhs.m_object)}; + } + + BreakpointCondition::operator Glib::ustring() const + { + return adw_breakpoint_condition_to_string(const_cast<AdwBreakpointCondition *>(m_object)); + } + + auto BreakpointCondition::parse(Glib::ustring str) -> std::optional<BreakpointCondition> + { + if (auto object = adw_breakpoint_condition_parse(str.c_str())) + { + return BreakpointCondition{object}; + } + return std::nullopt; + } + +} // namespace turns::adw + +namespace turns::adw +{ + namespace + { + auto constinit _class = Breakpoint::Class{}; + } // namespace + + auto Breakpoint::Class::init() -> Glib::Class const & + { + if (!gtype_) + { + class_init_func_ = &class_init_function; + gtype_ = adw_breakpoint_get_type(); + } + return *this; + } + + auto Breakpoint::Class::class_init_function(void * gclass, void * data) -> void + { + auto const klass = static_cast<BaseClassType *>(gclass); + CppClassParent::class_init_function(klass, data); + } + + auto Breakpoint::Class::wrap_new(GObject * object) -> Glib::ObjectBase * + { + return new Breakpoint{ADW_BREAKPOINT(object)}; + } + + Breakpoint::Breakpoint(BreakpointCondition & condition) + : Glib::ObjectBase{nullptr} + , Glib::Object{Glib::ConstructParams{_class.init(), "condition", condition.m_object, nullptr}} + { + } + + Breakpoint::Breakpoint(Glib::ConstructParams const & params) + : Glib::Object{params} + { + } + + Breakpoint::Breakpoint(BaseObjectType * gobj) + : Glib::Object{G_OBJECT(gobj)} + { + } + + auto Breakpoint::get_type() -> GType + { + return _class.init().get_type(); + } + + auto Breakpoint::get_base_type() -> GType + { + return adw_breakpoint_get_type(); + } + + auto Breakpoint::property_condition() -> Glib::PropertyProxy<BreakpointCondition *> + { + return helpers::make_property_proxy<BreakpointCondition *>(*this, "condition"); + } + +} // namespace turns::adw + +namespace Glib +{ + auto wrap(AdwBreakpoint * object, bool copy) -> Glib::RefPtr<turns::adw::Breakpoint> + { + return Glib::make_refptr_for_instance(dynamic_cast<turns::adw::Breakpoint *>(Glib::wrap_auto(G_OBJECT(object), copy))); + } +} // namespace Glib diff --git a/adw/src/dialog.cpp b/adw/src/dialog.cpp index c6d5e2b..8047d65 100644 --- a/adw/src/dialog.cpp +++ b/adw/src/dialog.cpp @@ -1,10 +1,13 @@ #include "turns/adw/dialog.hpp" +#include "turns/adw/breakpoint.hpp" + #include <glibmm/class.h> #include <glibmm/object.h> #include <glibmm/objectbase.h> #include <glibmm/refptr.h> #include <glibmm/ustring.h> +#include <glibmm/utility.h> #include <glibmm/wrap.h> #include <gtkmm/init.h> @@ -71,9 +74,25 @@ namespace turns::adw { } + auto Dialog::add_breakpoint(adw::Breakpoint && breakpoint) -> void + { + breakpoint.reference(); + adw_dialog_add_breakpoint(Glib::unwrap(this), Glib::unwrap(&breakpoint)); + } + + auto Dialog::close() -> void + { + adw_dialog_close(Glib::unwrap(this)); + } + auto Dialog::present(Gtk::Widget * parent) -> void { - adw_dialog_present(gobj(), Glib::unwrap(parent)); + adw_dialog_present(Glib::unwrap(this), Glib::unwrap(parent)); + } + + auto Dialog::set_title(Glib::ustring const & str) -> void + { + adw_dialog_set_title(Glib::unwrap(this), Glib::c_str_or_nullptr(str)); } } // namespace turns::adw diff --git a/adw/src/wrap_init.cpp b/adw/src/wrap_init.cpp index 16f87c3..df553da 100644 --- a/adw/src/wrap_init.cpp +++ b/adw/src/wrap_init.cpp @@ -3,6 +3,7 @@ #include "turns/adw/actionrow.hpp" #include "turns/adw/application.hpp" #include "turns/adw/applicationwindow.hpp" +#include "turns/adw/breakpoint.hpp" #include "turns/adw/dialog.hpp" #include "turns/adw/preferencesdialog.hpp" #include "turns/adw/preferencespage.hpp" @@ -28,6 +29,7 @@ namespace turns::adw WRAP_CLASS(ActionRow, action_row); WRAP_CLASS(Application, application); WRAP_CLASS(ApplicationWindow, application_window); + WRAP_CLASS(Breakpoint, breakpoint); WRAP_CLASS(Dialog, dialog); WRAP_CLASS(Toast, toast); WRAP_CLASS(PreferencesDialog, preferences_dialog); @@ -39,6 +41,7 @@ namespace turns::adw ENSURE_TYPE(ActionRow); ENSURE_TYPE(Application); ENSURE_TYPE(ApplicationWindow); + ENSURE_TYPE(Breakpoint); ENSURE_TYPE(Dialog); ENSURE_TYPE(Toast); ENSURE_TYPE(PreferencesDialog); diff --git a/ui/include/turns/ui/windows/participant_editor.hpp b/ui/include/turns/ui/windows/participant_editor.hpp index 6c7829f..508038a 100644 --- a/ui/include/turns/ui/windows/participant_editor.hpp +++ b/ui/include/turns/ui/windows/participant_editor.hpp @@ -27,8 +27,6 @@ namespace turns::ui::windows participant_editor(BaseObjectType * base, Glib::RefPtr<Gtk::Builder> const builder, Glib::RefPtr<core::participant> obj = {}); - auto present(Gtk::Widget * parent) -> void; - auto signal_finished() -> signal_finished_type; private: @@ -36,7 +34,6 @@ namespace turns::ui::windows auto handle_item_bind(Glib::RefPtr<Gtk::ListItem> item) -> void; auto handle_item_setup(Glib::RefPtr<Gtk::ListItem> item) -> void; - AdwDialog * m_adw; AdwComboRow * m_disposition; Gtk::Button * m_finish; AdwEntryRow * m_name; diff --git a/ui/src/windows/participant_editor.cpp b/ui/src/windows/participant_editor.cpp index 719bb1c..ddae0b2 100644 --- a/ui/src/windows/participant_editor.cpp +++ b/ui/src/windows/participant_editor.cpp @@ -36,7 +36,6 @@ namespace turns::ui::windows participant_editor::participant_editor(BaseObjectType * base, Glib::RefPtr<Gtk::Builder> const builder, Glib::RefPtr<core::participant> obj) : adw::Dialog{base} - , m_adw{ADW_DIALOG(Glib::unwrap(this))} , m_disposition{ADW_COMBO_ROW(Glib::unwrap(builder->get_widget<Gtk::ListBoxRow>("disposition")))} , m_finish{builder->get_widget<Gtk::Button>("finish")} , m_name{ADW_ENTRY_ROW(Glib::unwrap(builder->get_widget<Gtk::ListBoxRow>("name")))} @@ -46,7 +45,7 @@ namespace turns::ui::windows , m_participant{obj} { - adw_dialog_set_title(m_adw, _(obj ? lang::edit_participant : lang::add_participant)); + set_title(_(obj ? lang::edit_participant : lang::add_participant)); m_finish->signal_clicked().connect(sigc::mem_fun(*this, &participant_editor::handle_finish_clicked)); for (auto n : std::views::iota(std::uint8_t{}, static_cast<std::uint8_t>(core::disposition::END))) @@ -68,11 +67,6 @@ namespace turns::ui::windows } } - auto participant_editor::present(Gtk::Widget * parent) -> void - { - adw_dialog_present(m_adw, Glib::unwrap(parent)); - } - auto participant_editor::signal_finished() -> signal_finished_type { return m_signal_finished; @@ -92,7 +86,7 @@ namespace turns::ui::windows } m_signal_finished.emit(name, priority, disposition); - adw_dialog_close(m_adw); + close(); } auto participant_editor::handle_item_bind(Glib::RefPtr<Gtk::ListItem> item) -> void |
