summaryrefslogtreecommitdiffstats
path: root/test/test_genlist.rb
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-02-19 00:45:15 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-02-19 00:45:15 +0100
commit90ae47e71fb3d7179a703bcc344c284e468f59da (patch)
tree6e006829cd89edd17b929e43e8f4ae5d69390262 /test/test_genlist.rb
parentb1c747d11c0e51e28cc3db53cae780654b88c1e5 (diff)
parent745d270cc955b01264e9f11297ec6bd3ab2fb47d (diff)
downloadffi-efl-90ae47e71fb3d7179a703bcc344c284e468f59da.zip
ffi-efl-90ae47e71fb3d7179a703bcc344c284e468f59da.tar.gz
Merge branch 'master' of github.com:jeremyz/ffi-efl
Diffstat (limited to 'test/test_genlist.rb')
-rw-r--r--test/test_genlist.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/test_genlist.rb b/test/test_genlist.rb
new file mode 100644
index 0000000..76303c5
--- /dev/null
+++ b/test/test_genlist.rb
@@ -0,0 +1,68 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+require 'efl/elementary_all'
+#
+class ElmGenItemClass < FFI::Struct
+ layout :version, :int,
+ :refcount, :uint,
+ :delete_me, :pointer,
+ :item_style, :pointer,
+ :decorate_item_style, :pointer,
+ :decorate_all_item_style, :pointer,
+ :text_get, :pointer,
+ :content_get, :pointer,
+ :state_get, :pointer,
+ :del, :pointer
+end
+#
+include Efl
+#
+Elm.init
+#
+class Window < Elm::ElmWin
+ #
+ def initialize
+ super nil, "genlist"
+ title_set("Genlist")
+ @bg = Elm::ElmBg.new(self) do
+ color_set 255, 255, 255
+ size_hint_weight_expand
+ show
+ end
+ resize_object_add(@bg)
+ @itc = ElmGenItemClass.new(Native.elm_genlist_item_class_new)
+ @itc[:item_style] = FFI::MemoryPointer.from_string("default")
+ @itc[:text_get] = FFI::Function.new(:pointer, [:pointer, :pointer, :string]) do |data, *_|
+ ptr = FFI::MemoryPointer.from_string("Item # #{data.read_string}")
+ ptr.autorelease = false
+ ptr
+ end
+ @itc[:content_get] = FFI::Function.new(:pointer, [:pointer, :pointer, :string]) do |data, obj, part|
+ Elm::ElmIcon.new(self) do
+ standard_set(part == "elm.swallow.icon" ? "home" : "clock")
+ size_hint_aspect_set 0, 1, 1
+ end.to_ptr
+ end
+ @list = Elm::ElmGenList.new(self) do
+ size_hint_weight_expand
+ show
+ end
+ 30.times do |i|
+ @list.item_append(@itc, i.to_s, nil, :elm_genlist_item_none,
+ FFI::Function.new(:pointer, [:pointer, :pointer, :pointer]) {|data, obj, evt|
+ p [:selected, data.read_string] }, i.to_s)
+ end
+ resize_object_add(@list)
+ smart_callback_add "delete,request", ->(*_) { Elm.exit }, nil
+ resize 200, 300
+ show
+ end
+end
+#
+Window.new
+#
+Elm.run
+Elm.shutdown
+#
+# EOF