From 92b74849bfcf7f206145d0fbc502b7466e45e355 Mon Sep 17 00:00:00 2001 From: Hari Rana Date: Thu, 2 Apr 2026 22:29:09 -0400 Subject: [PATCH] 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: Part-of: --- src/gui/views/gcal-month-cell.blp | 100 ++++++++++++++++-------------- src/gui/views/gcal-month-cell.c | 17 +++-- 2 files changed, 65 insertions(+), 52 deletions(-) diff --git a/src/gui/views/gcal-month-cell.blp b/src/gui/views/gcal-month-cell.blp index 5ccc4c94..8b05541c 100644 --- a/src/gui/views/gcal-month-cell.blp +++ b/src/gui/views/gcal-month-cell.blp @@ -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; + }; + }; } }; } diff --git a/src/gui/views/gcal-month-cell.c b/src/gui/views/gcal-month-cell.c index 3588589b..0771740c 100644 --- a/src/gui/views/gcal-month-cell.c +++ b/src/gui/views/gcal-month-cell.c @@ -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