views/week: Move expand header button to week view

This commit is contained in:
Georges Basile Stavracas Neto
2025-04-04 21:00:30 -03:00
parent c0dfe588ae
commit 9048fe939f
3 changed files with 79 additions and 93 deletions
+5 -30
View File
@@ -74,8 +74,6 @@ struct _GcalWeekHeader
GtkGrid *grid;
GtkWidget *scrolledwindow;
GtkButton *expand_button;
GtkWidget *expand_button_box;
GtkEventController *motion_controller;
GtkBox *weekdays_box;
GtkWidget *main_box;
@@ -512,8 +510,6 @@ update_overflow (GcalWeekHeader *self)
}
}
gtk_widget_set_visible (GTK_WIDGET (self->expand_button), show_expand);
if (self->can_expand != show_expand)
{
self->can_expand = show_expand;
@@ -1051,7 +1047,6 @@ header_collapse (GcalWeekHeader *self)
GTK_POLICY_NEVER,
GTK_POLICY_NEVER);
gtk_scrolled_window_set_max_content_height (GTK_SCROLLED_WINDOW (self->scrolledwindow), -1);
gtk_button_set_icon_name (self->expand_button, "go-down-symbolic");
layout_manager = gtk_widget_get_layout_manager (GTK_WIDGET (self->grid));
@@ -1094,8 +1089,6 @@ header_expand (GcalWeekHeader *self)
gtk_scrolled_window_set_max_content_height (GTK_SCROLLED_WINDOW (self->scrolledwindow),
gtk_widget_get_height (week_view) / 2);
gtk_button_set_icon_name (self->expand_button, "go-up-symbolic");
child = gtk_widget_get_first_child (GTK_WIDGET (self->grid));
while (child)
{
@@ -1343,19 +1336,13 @@ gcal_week_header_size_allocate (GtkWidget *widget,
GcalWeekHeader *self = (GcalWeekHeader *) widget;
gboolean ltr;
gdouble cell_width;
gint start_x;
g_assert (GCAL_IS_WEEK_HEADER (self));
gtk_widget_allocate (self->main_box, width, height, baseline, NULL);
ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
start_x = ltr ? gtk_widget_get_width (self->expand_button_box) : 0;
if (!ltr)
width -= gtk_widget_get_width (self->expand_button_box);
cell_width = (width - start_x) / 7.0;
cell_width = width / 7.0;
if (gtk_widget_should_layout (self->selection.widget))
{
@@ -1382,7 +1369,7 @@ gcal_week_header_size_allocate (GtkWidget *widget,
gtk_widget_size_allocate (self->selection.widget,
&(GtkAllocation) {
.x = ALIGNED (start_x + selection_x),
.x = ALIGNED (selection_x),
.y = -6,
.width = ALIGNED (selection_width + 1),
.height = height + 6,
@@ -1394,7 +1381,7 @@ gcal_week_header_size_allocate (GtkWidget *widget,
{
gtk_widget_size_allocate (self->dnd.widget,
&(GtkAllocation) {
.x = start_x + self->dnd.cell * cell_width,
.x = self->dnd.cell * cell_width,
.y = -6,
.width = cell_width,
.height = height + 6,
@@ -1409,10 +1396,8 @@ gcal_week_header_snapshot (GtkWidget *widget,
{
g_autoptr (GDateTime) week_start = NULL;
GcalWeekHeader *self;
int alloc_width;
gboolean ltr;
gint current_cell;
gint start_x;
gint height;
gint width;
gint x;
@@ -1420,21 +1405,13 @@ gcal_week_header_snapshot (GtkWidget *widget,
/* Fonts and colour selection */
self = GCAL_WEEK_HEADER (widget);
ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
start_x = ltr ? gtk_widget_get_width (self->expand_button_box) : 0;
alloc_width = gtk_widget_get_width (widget);
if (!ltr)
alloc_width -= gtk_widget_get_width (self->expand_button_box);
week_start = gcal_date_time_get_start_of_week (self->active_date);
current_cell = g_date_time_get_day_of_week (self->active_date) - 1;
current_cell = (7 + current_cell - self->first_weekday) % 7;
x = ALIGNED (ltr ? start_x : alloc_width - start_x);
width = gtk_widget_get_width (widget) - start_x;
width = gtk_widget_get_width (widget);
height = gtk_widget_get_height (widget);
x = ALIGNED (ltr ? 0 : width);
gtk_snapshot_save (snapshot);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, 0));
@@ -1561,8 +1538,6 @@ gcal_week_header_class_init (GcalWeekHeaderClass *kclass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/views/gcal-week-header.ui");
gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, expand_button);
gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, expand_button_box);
gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, grid);
gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, main_box);
gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, motion_controller);
+34 -61
View File
@@ -9,80 +9,56 @@
<style>
<class name="week-header" />
</style>
<child>
<object class="GtkBox">
<property name="orientation">horizontal</property>
<property name="orientation">vertical</property>
<!-- Gestures -->
<child>
<object class="GtkBox" id="expand_button_box">
<property name="hexpand">False</property>
<child>
<object class="GtkButton" id="expand_button">
<property name="visible">False</property>
<property name="hexpand">True</property>
<property name="halign">center</property>
<property name="valign">end</property>
<property name="margin-bottom">6</property>
<property name="icon_name">go-down-symbolic</property>
<signal name="clicked" handler="on_expand_action_activated" object="GcalWeekHeader" swapped="yes"/>
<style>
<class name="flat" />
<class name="circular" />
</style>
</object>
</child>
<object class="GtkGestureClick">
<property name="button">1</property>
<signal name="pressed" handler="on_button_pressed" object="GcalWeekHeader" swapped="no" />
<signal name="released" handler="on_button_released" object="GcalWeekHeader" swapped="no" />
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<object class="GtkEventControllerMotion" id="motion_controller">
<property name="propagation-phase">none</property>
<signal name="motion" handler="on_motion_notify" object="GcalWeekHeader" swapped="no" />
</object>
</child>
<!-- Gestures -->
<child>
<object class="GtkGestureClick">
<property name="button">1</property>
<signal name="pressed" handler="on_button_pressed" object="GcalWeekHeader" swapped="no" />
<signal name="released" handler="on_button_released" object="GcalWeekHeader" swapped="no" />
</object>
</child>
<child>
<object class="GtkEventControllerMotion" id="motion_controller">
<property name="propagation-phase">none</property>
<signal name="motion" handler="on_motion_notify" object="GcalWeekHeader" swapped="no" />
</object>
</child>
<child>
<object class="GtkBox" id="weekdays_box">
<property name="homogeneous">True</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow">
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">never</property>
<property name="propagate-natural-height">True</property>
<property name="margin-bottom">2</property>
<child>
<object class="GtkBox" id="weekdays_box">
<property name="homogeneous">True</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow">
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">never</property>
<property name="propagate-natural-height">True</property>
<property name="margin-bottom">2</property>
<object class="GtkViewport">
<child>
<object class="GtkViewport">
<child>
<object class="GtkGrid" id="grid">
<property name="column-homogeneous">True</property>
<property name="hexpand">True</property>
<property name="column-spacing">6</property>
<property name="row-spacing">2</property>
<property name="margin-start">6</property>
</object>
</child>
<object class="GtkGrid" id="grid">
<property name="column-homogeneous">True</property>
<property name="hexpand">True</property>
<property name="column-spacing">6</property>
<property name="row-spacing">2</property>
<property name="margin-start">6</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
@@ -91,8 +67,5 @@
</template>
<object class="GtkSizeGroup" id="sizegroup">
<property name="mode">horizontal</property>
<widgets>
<widget name="expand_button_box"/>
</widgets>
</object>
</object>
</interface>
+40 -2
View File
@@ -47,8 +47,38 @@
</child>
<child>
<object class="GcalWeekHeader" id="header">
<signal name="event-activated" handler="on_event_activated" object="GcalWeekView" swapped="yes" />
<object class="GtkBox">
<property name="orientation">horizontal</property>
<!-- Expand / Collapse button -->
<child>
<object class="GtkBox" id="expand_button_box">
<property name="hexpand">False</property>
<child>
<object class="GtkToggleButton">
<property name="visible" bind-source="header" bind-property="can-expand" bind-flags="sync-create" />
<property name="active" bind-source="header" bind-property="expanded" bind-flags="sync-create|bidirectional" />
<property name="hexpand">True</property>
<property name="halign">center</property>
<property name="valign">end</property>
<property name="margin-bottom">6</property>
<property name="icon_name">go-down-symbolic</property>
<style>
<class name="flat" />
<class name="circular" />
</style>
</object>
</child>
</object>
</child>
<child>
<object class="GcalWeekHeader" id="header">
<property name="hexpand">True</property>
<signal name="event-activated" handler="on_event_activated" object="GcalWeekView" swapped="yes" />
</object>
</child>
</object>
</child>
@@ -113,4 +143,12 @@
</object>
</child>
</template>
<object class="GtkSizeGroup" id="sizegroup">
<property name="mode">horizontal</property>
<widgets>
<widget name="expand_button_box" />
<widget name="hours_bar" />
</widgets>
</object>
</interface>