[libshumate] demos: Create scale in UI file



commit 65b57cdb4e9889f30fee0f248d264eefb462d667
Author: James Westman <james jwestman net>
Date:   Wed Mar 10 11:15:41 2021 -0600

    demos: Create scale in UI file
    
    Now that ShumateScale supports setting the viewport after construction,
    create it in the UI file.

 demos/shumate-demo-window.c  | 12 ++++--------
 demos/shumate-demo-window.ui |  6 ++++++
 2 files changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/demos/shumate-demo-window.c b/demos/shumate-demo-window.c
index d34a686..0129bb7 100644
--- a/demos/shumate-demo-window.c
+++ b/demos/shumate-demo-window.c
@@ -26,6 +26,7 @@ struct _ShumateDemoWindow
 
   ShumateView *view;
   GtkOverlay *overlay;
+  ShumateScale *scale;
   ShumateLicense *license;
   GtkDropDown *layers_dropdown;
 
@@ -127,6 +128,7 @@ shumate_demo_window_class_init (ShumateDemoWindowClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Shumate/Demo/ui/shumate-demo-window.ui");
   gtk_widget_class_bind_template_child (widget_class, ShumateDemoWindow, view);
   gtk_widget_class_bind_template_child (widget_class, ShumateDemoWindow, overlay);
+  gtk_widget_class_bind_template_child (widget_class, ShumateDemoWindow, scale);
   gtk_widget_class_bind_template_child (widget_class, ShumateDemoWindow, license);
   gtk_widget_class_bind_template_child (widget_class, ShumateDemoWindow, layers_dropdown);
   gtk_widget_class_bind_template_callback (widget_class, on_layers_dropdown_notify_selected);
@@ -136,23 +138,17 @@ shumate_demo_window_class_init (ShumateDemoWindowClass *klass)
 static void
 shumate_demo_window_init (ShumateDemoWindow *self)
 {
-  ShumateScale *scale;
   ShumateViewport *viewport;
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
   viewport = shumate_view_get_viewport (self->view);
 
-  scale = shumate_scale_new (viewport);
-  g_object_set (scale,
-                "halign", GTK_ALIGN_START,
-                "valign", GTK_ALIGN_END,
-                NULL);
-  gtk_overlay_add_overlay (self->overlay, GTK_WIDGET (scale));
-
   /* Set the map source */
   on_layers_dropdown_notify_selected (self, NULL, self->layers_dropdown);
 
+  shumate_scale_set_viewport (self->scale, viewport);
+
   /* Add the marker layers */
   self->marker_layer = shumate_marker_layer_new (viewport);
   shumate_view_add_layer (self->view, SHUMATE_LAYER (self->marker_layer));
diff --git a/demos/shumate-demo-window.ui b/demos/shumate-demo-window.ui
index 6bb2a59..2fabff7 100644
--- a/demos/shumate-demo-window.ui
+++ b/demos/shumate-demo-window.ui
@@ -23,6 +23,12 @@
           <object class="ShumateView" id="view">
           </object>
         </child>
+        <child type="overlay">
+          <object class="ShumateScale" id="scale">
+            <property name="halign">start</property>
+            <property name="valign">end</property>
+          </object>
+        </child>
         <child type="overlay">
           <object class="ShumateLicense" id="license">
             <property name="halign">end</property>


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