views/month-cell: Add AdwBin as parent to methods retrieving height of widget

This is future-proofing the uncertain decision of removing
GtkWidget's `margin-*` properties in the future, which is what
we're currently using to retrieve the height of certain widgets.

Whenever the intention is to get the entire size of a particular
widget, including properties that contribute to layout such as
margins, the `get_width()`/`get_height()` methods don't include
these properties during calculations. However, getting the size
of the parent widget will include them in its entirety.

As such, the safest path is to use AdwBin as the parent to the
respective widgets, and using it to retrieve the height.

See: <https://gitlab.gnome.org/GNOME/gtk/-/issues/6556#note_2056432>
Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/739>
This commit is contained in:
Hari Rana
2026-04-03 16:37:14 -04:00
parent a578d93ce3
commit 92b74849bf
2 changed files with 65 additions and 52 deletions
+52 -48
View File
@@ -29,66 +29,70 @@ template $GcalMonthCell: Widget {
child: Overlay overlay {
[overlay]
Box header_box {
Adw.Bin {
valign: start;
spacing: 6;
margin-top: 6;
margin-bottom: 6;
margin-start: 6;
margin-end: 6;
Label day_label {
styles [
"day-label",
"numeric",
]
}
child: Box header_box {
spacing: 6;
margin-top: 6;
margin-bottom: 6;
margin-start: 6;
margin-end: 6;
Image weather_icon {
pixel-size: 16;
margin-start: 12;
accessible-role: presentation;
Label day_label {
styles [
"day-label",
"numeric",
]
}
styles [
"dimmed",
]
}
Image weather_icon {
pixel-size: 16;
margin-start: 12;
accessible-role: presentation;
Label temp_label {
styles [
"dimmed",
"temp-label",
]
}
styles [
"dimmed",
]
}
Label temp_label {
styles [
"dimmed",
"temp-label",
]
}
};
}
[overlay]
Button overflow_button {
accessible-role: toggle_button;
Adw.Bin {
valign: end;
sensitive: false;
clicked => $overflow_button_clicked_cb(template) not-swapped;
tooltip-text: _("All Events");
margin-top: 1;
margin-start: 1;
margin-bottom: 2;
margin-end: 2;
accessibility {
has-popup: true;
labelled-by: overflow_inscription;
}
child: Button overflow_button {
accessible-role: toggle_button;
sensitive: false;
clicked => $overflow_button_clicked_cb(template) not-swapped;
tooltip-text: _("All Events");
margin-top: 1;
margin-start: 1;
margin-bottom: 2;
margin-end: 2;
styles [
"flat",
"overflow",
]
Box {
Inscription overflow_inscription {
text-overflow: ellipsize_end;
accessibility {
has-popup: true;
labelled-by: overflow_inscription;
}
}
styles [
"flat",
"overflow",
]
child: Inscription overflow_inscription {
text-overflow: ellipsize_end;
};
};
}
};
}
+13 -4
View File
@@ -70,6 +70,17 @@ static guint signals[N_SIGNALS] = { 0, };
* Auxiliary methods
*/
static inline gint
get_parent_bin_height (GtkWidget *widget)
{
GtkWidget *parent;
parent = gtk_widget_get_parent (widget);
g_assert (ADW_IS_BIN (parent));
return gtk_widget_get_height (parent);
}
static void
update_style_flags (GcalMonthCell *self)
{
@@ -568,9 +579,7 @@ gcal_month_cell_get_header_height (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), -1);
return gtk_widget_get_height (self->header_box) +
gtk_widget_get_margin_top (self->header_box) +
gtk_widget_get_margin_bottom (self->header_box);
return get_parent_bin_height (self->header_box);
}
gint
@@ -578,7 +587,7 @@ gcal_month_cell_get_overflow_height (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), -1);
return gtk_widget_get_height (self->overflow_button);
return get_parent_bin_height (self->overflow_button);
}
gboolean