[libshumate] demo: Add "Go To" menu for testing animations



commit b77d2a7a7927d4f30121702704c8ace558f1df93
Author: James Westman <james jwestman net>
Date:   Sat Apr 23 19:52:44 2022 -0500

    demo: Add "Go To" menu for testing animations

 demos/shumate-demo-window.c  | 37 +++++++++++++++++++++++++++++++++++++
 demos/shumate-demo-window.ui | 24 ++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
---
diff --git a/demos/shumate-demo-window.c b/demos/shumate-demo-window.c
index 1327408..f986292 100644
--- a/demos/shumate-demo-window.c
+++ b/demos/shumate-demo-window.c
@@ -89,17 +89,54 @@ get_map_source_name (ShumateMapSource *map_source)
   return g_strdup (shumate_map_source_get_name (map_source));
 }
 
+static void
+activate_goto_europe (GSimpleAction *simple,
+                      GVariant      *parameter,
+                      gpointer       user_data)
+{
+  shumate_map_go_to (SHUMATE_MAP (user_data), 49.531565, 17.532806);
+}
+
+static void
+activate_goto_nyc (GSimpleAction *simple,
+                   GVariant      *parameter,
+                   gpointer       user_data)
+{
+  shumate_map_go_to (SHUMATE_MAP (user_data), 40.718820, -74.001605);
+}
+
+static void
+activate_goto_eiffel_tower (GSimpleAction *simple,
+                            GVariant      *parameter,
+                            gpointer       user_data)
+{
+  shumate_map_go_to (SHUMATE_MAP (user_data), 48.858279, 2.294486);
+}
+
 static void
 shumate_demo_window_init (ShumateDemoWindow *self)
 {
   ShumateViewport *viewport;
   GtkExpression *expression;
   g_autoptr(GBytes) bytes = NULL;
+  g_autoptr(GSimpleActionGroup) action_map = NULL;
   const char *style_json;
   GError *error = NULL;
+  const GActionEntry action_entries[] = {
+    { "goto-europe", activate_goto_europe },
+    { "goto-nyc", activate_goto_nyc },
+    { "goto-eiffel-tower", activate_goto_eiffel_tower },
+  };
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  action_map = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (action_map),
+                                   action_entries,
+                                   G_N_ELEMENTS (action_entries),
+                                   shumate_simple_map_get_map (self->map));
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "win", G_ACTION_GROUP (action_map));
+
   self->registry = shumate_map_source_registry_new_with_defaults ();
   shumate_map_source_registry_add (self->registry, SHUMATE_MAP_SOURCE (shumate_test_tile_source_new ()));
   expression = gtk_cclosure_expression_new (G_TYPE_STRING, NULL, 0, NULL,
diff --git a/demos/shumate-demo-window.ui b/demos/shumate-demo-window.ui
index f07ddad..f5b7173 100644
--- a/demos/shumate-demo-window.ui
+++ b/demos/shumate-demo-window.ui
@@ -12,6 +12,16 @@
           <object class="GtkDropDown" id="layers_dropdown">
           </object>
         </child>
+        <child type="end">
+          <object class="GtkMenuButton">
+            <property name="label" translatable="true">Go To</property>
+            <property name="popover">
+              <object class="GtkPopoverMenu">
+                <property name="menu-model">goto_menu</property>
+              </object>
+            </property>
+          </object>
+        </child>
       </object>
     </child>
     <child>
@@ -20,4 +30,18 @@
       </object>
     </child>
   </template>
+  <menu id="goto_menu">
+    <item>
+      <attribute name="label" translatable="true">Europe</attribute>
+      <attribute name="action">win.goto-europe</attribute>
+    </item>
+    <item>
+      <attribute name="label" translatable="true">New York City</attribute>
+      <attribute name="action">win.goto-nyc</attribute>
+    </item>
+    <item>
+      <attribute name="label" translatable="true">Eiffel Tower</attribute>
+      <attribute name="action">win.goto-eiffel-tower</attribute>
+    </item>
+  </menu>
 </interface>


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