views/month: Display only weather icon under space contraint

If the horizontal space does not allow for an icon and
a temperature label, there'd still be enough space for
an icon only.

Visually, it makes sense to align that icon in icon-only
mode to the end.

Closes: #856

Signed-off-by: Markus Göllnitz <camelcasenick@bewares.it>
Co-authored-by: Georged Basile Stavracas Neto
<georges.stavracas@gmail.com>
This commit is contained in:
Markus Göllnitz
2025-01-22 16:45:31 -03:00
parent 87607efa90
commit 44894475d0
3 changed files with 44 additions and 4 deletions
+30 -2
View File
@@ -30,11 +30,13 @@
struct _GcalMonthCell
{
AdwBin parent;
AdwBreakpointBin parent;
GDateTime *date;
guint n_overflow;
AdwBreakpoint *breakpoint_narrow;
GtkLabel *day_label;
GtkWidget *header_box;
GtkLabel *month_name_label;
@@ -51,9 +53,11 @@ struct _GcalMonthCell
GcalContext *context;
GcalWeatherInfo *weather_info;
GBinding *icon_tooltip_binding;
};
G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, ADW_TYPE_BIN)
G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, ADW_TYPE_BREAKPOINT_BIN)
enum
{
@@ -303,6 +307,27 @@ on_weather_service_weather_changed_cb (GcalWeatherService *weather_service,
update_weather (self);
}
static void
on_breakpoint_changed_cb (GcalMonthCell *self,
GParamSpec *pspec)
{
AdwBreakpoint *current_breakpoint = adw_breakpoint_bin_get_current_breakpoint (ADW_BREAKPOINT_BIN (self));
if (current_breakpoint == self->breakpoint_narrow)
{
self->icon_tooltip_binding = g_object_bind_property (self->temp_label, "label",
self->weather_icon, "tooltip-text",
G_BINDING_SYNC_CREATE);
}
else
{
g_assert (G_IS_BINDING (self->icon_tooltip_binding));
g_clear_pointer (&self->icon_tooltip_binding, g_binding_unbind);
gtk_widget_set_tooltip_text (GTK_WIDGET (self->weather_icon), NULL);
}
}
/*
* GObject overrides
@@ -391,6 +416,7 @@ gcal_month_cell_class_init (GcalMonthCellClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/views/gcal-month-cell.ui");
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, breakpoint_narrow);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, day_label);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, header_box);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, month_name_label);
@@ -416,6 +442,8 @@ gcal_month_cell_init (GcalMonthCell *self)
g_signal_connect (drop_target, "accept", G_CALLBACK (on_drop_target_accept_cb), self);
g_signal_connect (drop_target, "drop", G_CALLBACK (on_drop_target_drop_cb), self);
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drop_target));
g_signal_connect(self, "notify::current-breakpoint", G_CALLBACK (on_breakpoint_changed_cb), 0);
}
GtkWidget*
+1 -1
View File
@@ -27,7 +27,7 @@ G_BEGIN_DECLS
#define GCAL_TYPE_MONTH_CELL (gcal_month_cell_get_type())
G_DECLARE_FINAL_TYPE (GcalMonthCell, gcal_month_cell, GCAL, MONTH_CELL, AdwBin)
G_DECLARE_FINAL_TYPE (GcalMonthCell, gcal_month_cell, GCAL, MONTH_CELL, AdwBreakpointBin)
GtkWidget* gcal_month_cell_new (void);
+13 -1
View File
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GcalMonthCell" parent="AdwBin">
<template class="GcalMonthCell" parent="AdwBreakpointBin">
<child>
<object class="AdwBreakpoint" id="breakpoint_narrow">
<condition>max-width: 120sp</condition>
<setter object="weather_icon" property="halign">end</setter>
<setter object="weather_icon" property="hexpand">True</setter>
<setter object="weather_icon" property="margin-start">6</setter>
<setter object="temp_label" property="visible">False</setter>
</object>
</child>
<property name="width-request">50</property>
<property name="height-request">50</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="focusable">True</property>