[egg-list-box] Initial version of test with scrolledwindow



commit 2e300a837a0bd4b4d1e38f06f9125a78518a1751
Author: Alexander Larsson <alexl redhat com>
Date:   Wed May 16 14:05:18 2012 +0200

    Initial version of test with scrolledwindow

 Makefile.am        |    8 ++++-
 test-scrolled.vala |   97 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index d98958a..f2770ef 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,7 +9,7 @@ AM_VALAFLAGS = \
 	@LISTBOX_PACKAGES@ \
 	$(NULL)
 
-noinst_PROGRAMS = test-list
+noinst_PROGRAMS = test-list test-scrolled
 
 test_list_SOURCES = \
 	egg-list-box.vala \
@@ -17,6 +17,12 @@ test_list_SOURCES = \
 	$(NULL)
 test_list_LDADD = $(LISTBOX_LIBS)
 
+test_scrolled_SOURCES = \
+	egg-list-box.vala \
+	test-scrolled.vala \
+	$(NULL)
+test_scrolled_LDADD = $(LISTBOX_LIBS)
+
 CLEANFILES = \
 	$(test_list_SOURCES:.vala=.c) \
 	*.vapi *.stamp
diff --git a/test-scrolled.vala b/test-scrolled.vala
new file mode 100644
index 0000000..8ab2de2
--- /dev/null
+++ b/test-scrolled.vala
@@ -0,0 +1,97 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
+/*
+ * Copyright (C) 2011 Alexander Larsson <alexl redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+using Egg;
+
+class Row : Grid {
+  public int32 value;
+  public Row () {
+	value = Random.int_range (0, 10000);
+	var l = new Label ("Value %u".printf (value));
+	this.add (l);
+	l.show ();
+  }
+
+	
+}
+public static int
+compare (Widget a, Widget b) {
+  return (int32)(b as Row).value - (int32)(a as Row).value;
+}
+
+public static bool
+filter (Widget widget) {
+  return (widget as Row).value % 2 == 0;
+}
+
+public static int
+main (string[] args) {
+  int num_rows = 0;
+
+  Gtk.init (ref args);
+
+  if (args.length > 1)
+	num_rows = int.parse (args[1]);
+
+  if (num_rows == 0)
+	num_rows = 1000;
+  
+  var w = new Window ();
+  var hbox = new Box(Orientation.HORIZONTAL, 0);
+  w.add (hbox);
+
+  var scrolled = new ScrolledWindow (null, null);
+  scrolled.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
+  hbox.add (scrolled);
+  
+  var list = new ListBox();
+  scrolled.add_with_viewport (list);
+
+  for (int i = 0; i < num_rows; i++) {
+	var row = new Row ();
+	list.add (row);
+  }
+  var vbox = new Box(Orientation.VERTICAL, 0);
+  hbox.add (vbox);
+
+  var b = new Button.with_label ("sort");
+  vbox.add (b);
+  b.clicked.connect ( () => {
+		  list.set_sort_func (compare);
+	  });
+
+  b = new Button.with_label ("filter");
+  vbox.add (b);
+  b.clicked.connect ( () => {
+		  list.set_filter_func (filter);
+	  });
+
+  b = new Button.with_label ("unfilter");
+  vbox.add (b);
+  b.clicked.connect ( () => {
+		  list.set_filter_func (null);
+	  });
+
+  w.show_all ();
+
+
+  Gtk.main ();
+
+  return 0;
+}



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