[gnome-games/wip/exalm/list-rows: 1/3] developer-list-item: Extend ListBoxRow instead of Label



commit 456f75df9be586a746757b7df998649755641322
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Sep 30 18:25:24 2018 +0500

    developer-list-item: Extend ListBoxRow instead of Label
    
    Pack label into it instead. This is cleaner and allows to be more
    flexible with layout.

 data/ui/developer-list-item.ui  | 16 ++++++++++------
 src/ui/developer-list-item.vala |  7 +++++--
 src/ui/developers-view.vala     | 13 ++++++-------
 3 files changed, 21 insertions(+), 15 deletions(-)
---
diff --git a/data/ui/developer-list-item.ui b/data/ui/developer-list-item.ui
index b80940bb..74b94a79 100644
--- a/data/ui/developer-list-item.ui
+++ b/data/ui/developer-list-item.ui
@@ -1,10 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="GamesDeveloperListItem" parent="GtkLabel">
+  <template class="GamesDeveloperListItem" parent="GtkListBoxRow">
     <property name="visible">true</property>
-    <property name="vexpand">true</property>
-    <property name="margin">6</property>
-    <property name="wrap">true</property>
-    <property name="xalign">0</property>
+    <child>
+      <object class="GtkLabel" id="label">
+        <property name="visible">true</property>
+        <property name="margin">6</property>
+        <property name="wrap">true</property>
+        <property name="xalign">0</property>
+      </object>
+    </child>
   </template>
-</interface>
\ No newline at end of file
+</interface>
diff --git a/src/ui/developer-list-item.vala b/src/ui/developer-list-item.vala
index e5a20c4d..23871e8b 100644
--- a/src/ui/developer-list-item.vala
+++ b/src/ui/developer-list-item.vala
@@ -1,5 +1,8 @@
 [GtkTemplate (ui = "/org/gnome/Games/ui/developer-list-item.ui")]
-private class Games.DeveloperListItem: Gtk.Label {
+private class Games.DeveloperListItem: Gtk.ListBoxRow {
+       [GtkChild]
+       private Gtk.Label label;
+
        private Developer _developer;
        public Developer developer {
                get { return _developer; }
@@ -16,7 +19,7 @@ private class Games.DeveloperListItem: Gtk.Label {
 
        private void update_label () {
                var val = developer.get_developer ();
-               label = val == "" ? _("Unknown") : val;
+               label.label = val == "" ? _("Unknown") : val;
        }
 
        public static int compare (DeveloperListItem a, DeveloperListItem b) {
diff --git a/src/ui/developers-view.vala b/src/ui/developers-view.vala
index d7250761..0cce1477 100644
--- a/src/ui/developers-view.vala
+++ b/src/ui/developers-view.vala
@@ -36,9 +36,8 @@ private class Games.DevelopersView : SidebarView {
        private void hide_developer (Developer developer) {
                Gtk.ListBoxRow? first_occurence = null;
 
-               foreach (var item in list_box.get_children ()) {
-                       var row = item as Gtk.ListBoxRow;
-                       var list_item = row.get_child () as DeveloperListItem;
+               foreach (var row in list_box.get_children ()) {
+                       var list_item = row as DeveloperListItem;
 
                        if (Developer.equal (list_item.developer, developer)) {
                                if (first_occurence != null) {
@@ -50,7 +49,7 @@ private class Games.DevelopersView : SidebarView {
                                        break;
                                }
                                else {
-                                       first_occurence = row;
+                                       first_occurence = list_item;
                                        first_occurence.changed ();
                                }
                        }
@@ -68,14 +67,14 @@ private class Games.DevelopersView : SidebarView {
        }
 
        protected override void invalidate (Gtk.ListBoxRow row_item) {
-               var row = row_item.get_child () as DeveloperListItem;
+               var row = row_item as DeveloperListItem;
                var developer = row.developer;
                collection_view.filtering_developer = developer;
        }
 
        protected override int sort_rows (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) {
-               var item1 = row1.get_child () as DeveloperListItem;
-               var item2 = row2.get_child () as DeveloperListItem;
+               var item1 = row1 as DeveloperListItem;
+               var item2 = row2 as DeveloperListItem;
 
                return DeveloperListItem.compare (item1, item2);
        }


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