55
66public class ListsView : DemoPage {
77 construct {
8- title = " Lists" ;
8+ title = " Lists & Grids " ;
99
1010 var card_title = new Granite .HeaderLabel (" Gtk.ListBox" ) {
1111 secondary_text = " This ListBox has \" Granite.CssClass.CARD\" "
@@ -28,54 +28,116 @@ public class ListsView : DemoPage {
2828 );
2929 list_box. append (new Granite .ListItem () { child = separators_modelbutton });
3030
31- var scrolled_title = new Granite .HeaderLabel (" Gtk.ListView" ) {
31+ var list_title = new Granite .HeaderLabel (" Gtk.ListView" ) {
3232 secondary_text = " ScrolledWindow with \" has-frame = true\" has a view level background color"
3333 };
3434
35- var liststore = new GLib .ListStore (typeof (ListObject ));
36- liststore . append (new ListObject () {
35+ var list_store = new GLib .ListStore (typeof (ListObject ));
36+ list_store . append (new ListObject () {
3737 text = " Row 1"
3838 });
39- liststore . append (new ListObject () {
39+ list_store . append (new ListObject () {
4040 text = " Row 2"
4141 });
42- liststore . append (new ListObject () {
42+ list_store . append (new ListObject () {
4343 text = " Row 3"
4444 });
45- liststore . append (new ListObject () {
45+ list_store . append (new ListObject () {
4646 text = " Row 4"
4747 });
48- liststore . append (new ListObject () {
48+ list_store . append (new ListObject () {
4949 text = " Row 5"
5050 });
5151
52- var selection_model = new Gtk .SingleSelection (liststore );
52+ var list_selection = new Gtk .SingleSelection (list_store );
5353
54- var factory = new Gtk .SignalListItemFactory ();
55- factory . setup. connect ((obj) = > {
54+ var list_factory = new Gtk .SignalListItemFactory ();
55+ list_factory . setup. connect ((obj) = > {
5656 var list_item = (Gtk . ListItem ) obj;
5757 list_item. child = new Granite .ListItem ();
5858 });
5959
60- factory . bind. connect ((obj) = > {
60+ list_factory . bind. connect ((obj) = > {
6161 var list_item = (Gtk . ListItem ) obj;
6262 var list_object = (ListObject ) list_item. item;
6363
6464 var granite_list_item = ((Granite . ListItem ) list_item. child);
6565 granite_list_item. text = list_object. text;
6666 });
6767
68- var list_view = new Gtk .ListView (selection_model, factory ) {
68+ var list_view = new Gtk .ListView (list_selection, list_factory ) {
6969 show_separators = true
7070 };
7171
72- var scrolled_window = new Gtk .ScrolledWindow () {
72+ var list_scrolled = new Gtk .ScrolledWindow () {
7373 child = list_view,
7474 has_frame = true ,
7575 hscrollbar_policy = NEVER ,
7676 min_content_height = 128
7777 };
7878
79+ var grid_title = new Granite .HeaderLabel (" Gtk.GridView" );
80+
81+ var grid_store = new GLib .ListStore (typeof (GridObject ));
82+ grid_store. append (new GridObject () {
83+ icon_name = " folder-documents" ,
84+ text = " Documents"
85+ });
86+ grid_store. append (new GridObject () {
87+ icon_name = " folder-download" ,
88+ text = " Downloads"
89+ });
90+ grid_store. append (new GridObject () {
91+ icon_name = " folder-music" ,
92+ text = " Music"
93+ });
94+ grid_store. append (new GridObject () {
95+ icon_name = " folder-pictures" ,
96+ text = " Pictures"
97+ });
98+ grid_store. append (new GridObject () {
99+ icon_name = " folder-publicshare" ,
100+ text = " Public"
101+ });
102+ grid_store. append (new GridObject () {
103+ icon_name = " folder-templates" ,
104+ text = " Templates"
105+ });
106+ grid_store. append (new GridObject () {
107+ icon_name = " folder-videos" ,
108+ text = " Videos"
109+ });
110+
111+ var grid_selection = new Gtk .MultiSelection (grid_store);
112+
113+ var grid_factory = new Gtk .SignalListItemFactory ();
114+ grid_factory. setup. connect ((obj) = > {
115+ var list_item = (Gtk . ListItem ) obj;
116+ list_item. child = new GridItem ();
117+ });
118+
119+ grid_factory. bind. connect ((obj) = > {
120+ var list_item = (Gtk . ListItem ) obj;
121+ var grid_object = (GridObject ) list_item. item;
122+
123+ var grid_item = ((GridItem ) list_item. child);
124+ grid_item. text = grid_object. text;
125+ grid_item. icon_name = grid_object. icon_name;
126+ });
127+
128+ var grid_view = new Gtk .GridView (grid_selection, grid_factory) {
129+ max_columns = 4 ,
130+ enable_rubberband = true
131+ };
132+
133+ var grid_scrolled = new Gtk .ScrolledWindow () {
134+ child = grid_view,
135+ has_frame = true ,
136+ hscrollbar_policy = NEVER ,
137+ min_content_height = 128 ,
138+ propagate_natural_height = true
139+ };
140+
79141 var vbox = new Granite .Box (VERTICAL , HALF ) {
80142 margin_top = 12 ,
81143 margin_bottom = 12 ,
@@ -84,8 +146,10 @@ public class ListsView : DemoPage {
84146 };
85147 vbox. append (card_title);
86148 vbox. append (list_box);
87- vbox. append (scrolled_title);
88- vbox. append (scrolled_window);
149+ vbox. append (list_title);
150+ vbox. append (list_scrolled);
151+ vbox. append (grid_title);
152+ vbox. append (grid_scrolled);
89153
90154 child = vbox;
91155
@@ -95,4 +159,35 @@ public class ListsView : DemoPage {
95159 private class ListObject : Object {
96160 public string text { get ; set ; }
97161 }
162+
163+ private class GridObject : Object {
164+ public string text { get ; set ; }
165+ public string icon_name { get ; set ; }
166+ }
167+
168+ private class GridItem : Granite .Box {
169+ public string text { get ; set ; }
170+ public string icon_name { get ; set ; }
171+
172+ public GridItem () {
173+ Object (
174+ orientation: Gtk . Orientation . VERTICAL
175+ );
176+ }
177+
178+ construct {
179+ var image = new Gtk .Image .from_icon_name (icon_name) {
180+ pixel_size = 64
181+ };
182+
183+ var label = new Gtk .Label (text);
184+
185+ child_spacing = HALF ;
186+ append (image);
187+ append (label);
188+
189+ bind_property (" text" , label, " label" );
190+ bind_property (" icon-name" , image, " icon-name" );
191+ }
192+ }
98193}
0 commit comments