[gnome-calendar/wip/cdavis/use-leaflet: 25/28] window: Move action widgets at small widths




commit 78d9dd1e8e18dc1f16a1a14cf5b9e8a9a96748dc
Author: Christopher Davis <christopherdavis gnome org>
Date:   Thu Jul 7 11:42:45 2022 -0400

    window: Move action widgets at small widths
    
    Moves the action widgets (Today, New Event, Search) to an
    action bar when the window shrinks.

 src/gui/gcal-window.c  | 35 +++++++++++++++++++++++++++++++++++
 src/gui/gcal-window.ui |  6 ++++++
 2 files changed, 41 insertions(+)
---
diff --git a/src/gui/gcal-window.c b/src/gui/gcal-window.c
index 9024be1e..82e72750 100644
--- a/src/gui/gcal-window.c
+++ b/src/gui/gcal-window.c
@@ -104,10 +104,12 @@ struct _GcalWindow
   GtkWidget          *month_view;
   GtkWidget          *agenda_view;
   GtkWidget          *date_chooser;
+  GtkWidget          *action_bar;
 
   /* header_bar widets */
   GtkWidget          *calendars_button;
   GtkWidget          *menu_button;
+  GtkWidget          *new_event_button;
   GtkWidget          *today_button;
   GtkWidget          *views_switcher;
 
@@ -651,6 +653,34 @@ event_activated (GcalView        *view,
   gcal_event_widget_show_preview (event_widget, event_preview_cb, user_data);
 }
 
+static void
+on_folded_notify_cb (AdwLeaflet *leaflet,
+                     GParamSpec *pspec,
+                     GcalWindow *self)
+{
+  if (adw_leaflet_get_folded (leaflet))
+    {
+      gtk_header_bar_remove (GTK_HEADER_BAR (self->header_bar), self->today_button);
+      gtk_header_bar_remove (GTK_HEADER_BAR (self->header_bar), self->new_event_button);
+      gtk_header_bar_remove (GTK_HEADER_BAR (self->header_bar), GTK_WIDGET (self->search_button));
+
+      gtk_action_bar_pack_start (GTK_ACTION_BAR (self->action_bar), self->today_button);
+      gtk_action_bar_pack_end (GTK_ACTION_BAR (self->action_bar), self->new_event_button);
+      gtk_action_bar_pack_end (GTK_ACTION_BAR (self->action_bar), GTK_WIDGET (self->search_button));
+    }
+  else
+    {
+      gtk_action_bar_remove (GTK_ACTION_BAR (self->action_bar), self->today_button);
+      gtk_action_bar_remove (GTK_ACTION_BAR (self->action_bar), self->new_event_button);
+      gtk_action_bar_remove (GTK_ACTION_BAR (self->action_bar), GTK_WIDGET (self->search_button));
+
+      gtk_header_bar_pack_start (GTK_HEADER_BAR (self->header_bar), self->today_button);
+      gtk_header_bar_pack_end (GTK_HEADER_BAR (self->header_bar), self->new_event_button);
+      gtk_header_bar_pack_end (GTK_HEADER_BAR (self->header_bar), GTK_WIDGET (self->search_button));
+    }
+}
+
+
 static void
 on_toast_dismissed_cb (AdwToast   *toast,
                        GcalWindow *self)
@@ -1026,9 +1056,11 @@ gcal_window_class_init (GcalWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, main_box);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, menu_button);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, month_view);
+  gtk_widget_class_bind_template_child (widget_class, GcalWindow, action_bar);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, quick_add_popover);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, search_button);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, calendar_management_dialog);
+  gtk_widget_class_bind_template_child (widget_class, GcalWindow, new_event_button);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, today_button);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, overlay);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, views_stack);
@@ -1038,6 +1070,9 @@ gcal_window_class_init (GcalWindowClass *klass)
 
   gtk_widget_class_bind_template_callback (widget_class, view_changed);
 
+  /* Layout related */
+  gtk_widget_class_bind_template_callback (widget_class, on_folded_notify_cb);
+
   /* Event creation related */
   gtk_widget_class_bind_template_callback (widget_class, edit_event);
   gtk_widget_class_bind_template_callback (widget_class, create_event_detailed_cb);
diff --git a/src/gui/gcal-window.ui b/src/gui/gcal-window.ui
index 18b9100c..14b21c62 100644
--- a/src/gui/gcal-window.ui
+++ b/src/gui/gcal-window.ui
@@ -100,6 +100,7 @@
         <child>
           <object class="AdwLeaflet" id="leaflet">
             <property name="homogeneous">False</property>
+            <signal name="notify::folded" handler="on_folded_notify_cb" object="GcalWindow" swapped="no"/>
             <child>
               <object class="GtkBox">
                 <property name="hexpand">False</property>
@@ -143,6 +144,11 @@
                     </style>
                   </object>
                 </child>
+                <child>
+                  <object class="GtkActionBar" id="action_bar">
+                    <property name="revealed" bind-source="leaflet" bind-property="folded" 
bind-flags="sync-create"/>
+                  </object>
+                </child>
               </object>
             </child>
             <child>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]