29#include <unordered_map>
32#include <sigc++/scoped_connection.h>
39using BoxChildren = std::unordered_map<Gtk::Widget *, sigc::scoped_connection>;
42static void set_expand(Gtk::Widget &widget, Gtk::Orientation
const orientation,
45 switch (orientation) {
46 case Gtk::Orientation::HORIZONTAL: widget.set_hexpand(expand);
break;
47 case Gtk::Orientation::VERTICAL : widget.set_vexpand(expand);
break;
48 default: std::abort();
52static void set_align(Gtk::Widget &widget, Gtk::Orientation
const orientation,
53 Gtk::Align
const align)
55 switch (orientation) {
56 case Gtk::Orientation::HORIZONTAL: widget.set_halign(align);
break;
57 case Gtk::Orientation::VERTICAL : widget.set_valign(align);
break;
58 default: std::abort();
67 default: std::abort();
71static void set_fill(Gtk::Widget &widget, Gtk::Orientation
const orientation,
72 bool const fill,
PackType const pack_type)
74 auto const align = fill ? Gtk::Align::FILL :
to_align(pack_type);
78static void set_padding(Gtk::Widget &widget, Gtk::Orientation
const orientation,
79 int const margin_start,
int const margin_end)
81 switch (orientation) {
82 case Gtk::Orientation::HORIZONTAL:
83 widget.set_margin_start(widget.get_margin_start() + margin_start);
84 widget.set_margin_end (widget.get_margin_end () + margin_end );
86 case Gtk::Orientation::VERTICAL:
87 widget.set_margin_top (widget.get_margin_top () + margin_start);
88 widget.set_margin_bottom(widget.get_margin_bottom() + margin_end );
90 default: std::abort();
98 auto &starts = it->second;
104 if (starts.empty()) {
107 auto const position = starts.size();
110 box.reorder_child_after(
child, previous);
116 auto const erase_child = [&]{ starts.erase(&
child); };
117 auto connection =
child.property_parent().signal_changed().connect(erase_child);
118 starts.emplace(&
child, std::move(connection));
122 Gtk::Box &box, Gtk::Widget &
child,
bool const expand,
bool const fill,
123 unsigned const padding)
125 auto const orientation = box.get_orientation();
134 unsigned const padding)
138 pack(pack_type, box,
child, expand, fill, padding);
142 unsigned const padding)
148 unsigned const padding)
153void pack_end(Gtk::Box &box, Gtk::Widget &
child,
bool const expand,
bool const fill,
154 unsigned const padding)
160 unsigned const padding)
static void set_fill(Gtk::Widget &widget, Gtk::Orientation const orientation, bool const fill, PackType const pack_type)
void pack_end(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the end of box.
static auto to_align(PackType const pack_type)
Gtk::Widget & get_nth_child(Gtk::Widget &widget, std::size_t const index)
Get the widgetʼs child at the given position. Throws std::out_of_range if the index is invalid.
static void set_expand(Gtk::Widget &widget, Gtk::Orientation const orientation, bool const expand)
PackOptions
Equivalent to GTK3ʼs Gtk::PackOptions.
static void set_align(Gtk::Widget &widget, Gtk::Orientation const orientation, Gtk::Align const align)
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
static void add(Gtk::Box &box, PackType const pack_type, Gtk::Widget &child)
static auto s_box_children
static void pack(PackType const pack_type, Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
std::unordered_map< Gtk::Widget *, sigc::scoped_connection > BoxChildren
static void set_padding(Gtk::Widget &widget, Gtk::Orientation const orientation, int const margin_start, int const margin_end)
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.