summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-12-01 10:03:40 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-12-01 10:03:40 +0100
commita9849b967d92b18b1960c00cc6e7be0d6c2eb49a (patch)
tree391e2de1d4ccd72ddfcdbe4afa8f35e683fab9ae
parent63951e9d43b56080c118a517f002fc00243ff0ba (diff)
test_genlist: use defined callback types to avoid building FFI::Function by handHEADmaster
-rw-r--r--test/test_genlist.rb75
1 files changed, 47 insertions, 28 deletions
diff --git a/test/test_genlist.rb b/test/test_genlist.rb
index 76303c5..86f7c51 100644
--- a/test/test_genlist.rb
+++ b/test/test_genlist.rb
@@ -3,17 +3,29 @@
3# 3#
4require 'efl/elementary_all' 4require 'efl/elementary_all'
5# 5#
6class ElmGenItemClass < FFI::Struct 6# require 'efl/native/elm/elm_gen'
7 layout :version, :int, 7module Efl::Native
8 :refcount, :uint, 8 class ElmGenItemClass < FFI::Struct
9 :delete_me, :pointer, 9 layout :version, :int,
10 :item_style, :pointer, 10 :refcount, :uint,
11 :decorate_item_style, :pointer, 11 :delete_me, :pointer,
12 :decorate_all_item_style, :pointer, 12 :item_style, :pointer,
13 :text_get, :pointer, 13 :decorate_item_style, :pointer,
14 :content_get, :pointer, 14 :decorate_all_item_style, :pointer,
15 :state_get, :pointer, 15 # :text_get, :elm_gen_item_text_get_cb,
16 :del, :pointer 16 :text_get, :elm_gen_item_content_get_cb,
17 :content_get, :elm_gen_item_content_get_cb,
18 :state_get, :elm_gen_item_state_get_cb,
19 :del, :elm_gen_item_del_cb
20
21 def self.create style, text_get_fct, content_get_fct
22 i = ElmGenItemClass.new(Native.elm_genlist_item_class_new)
23 i[:item_style] = FFI::MemoryPointer.from_string(style)
24 i[:text_get] = text_get_fct
25 i[:content_get] = content_get_fct
26 i
27 end
28 end
17end 29end
18# 30#
19include Efl 31include Efl
@@ -31,33 +43,40 @@ class Window < Elm::ElmWin
31 show 43 show
32 end 44 end
33 resize_object_add(@bg) 45 resize_object_add(@bg)
34 @itc = ElmGenItemClass.new(Native.elm_genlist_item_class_new) 46
35 @itc[:item_style] = FFI::MemoryPointer.from_string("default")
36 @itc[:text_get] = FFI::Function.new(:pointer, [:pointer, :pointer, :string]) do |data, *_|
37 ptr = FFI::MemoryPointer.from_string("Item # #{data.read_string}")
38 ptr.autorelease = false
39 ptr
40 end
41 @itc[:content_get] = FFI::Function.new(:pointer, [:pointer, :pointer, :string]) do |data, obj, part|
42 Elm::ElmIcon.new(self) do
43 standard_set(part == "elm.swallow.icon" ? "home" : "clock")
44 size_hint_aspect_set 0, 1, 1
45 end.to_ptr
46 end
47 @list = Elm::ElmGenList.new(self) do 47 @list = Elm::ElmGenList.new(self) do
48 size_hint_weight_expand 48 size_hint_weight_expand
49 show 49 show
50 end 50 end
51 resize_object_add(@list)
52
53 @itc = Efl::Native::ElmGenItemClass.create('default', method(:item_text_get), method(:item_content_get))
51 30.times do |i| 54 30.times do |i|
52 @list.item_append(@itc, i.to_s, nil, :elm_genlist_item_none, 55 @list.item_append(@itc, i.to_s, nil, :elm_genlist_item_none, method(:evt_callback), i.to_s)
53 FFI::Function.new(:pointer, [:pointer, :pointer, :pointer]) {|data, obj, evt|
54 p [:selected, data.read_string] }, i.to_s)
55 end 56 end
56 resize_object_add(@list) 57
57 smart_callback_add "delete,request", ->(*_) { Elm.exit }, nil 58 smart_callback_add "delete,request", ->(*_) { Elm.exit }, nil
58 resize 200, 300 59 resize 200, 300
59 show 60 show
60 end 61 end
62
63 def evt_callback data, obj, evt
64 p [:selected, data.read_string]
65 end
66
67 def item_text_get data, obj, part
68 ptr = FFI::MemoryPointer.from_string("Item # #{data.read_string}")
69 ptr.autorelease = false
70 ptr
71 end
72
73 def item_content_get data, obj, part
74 Elm::ElmIcon.new(self) do
75 standard_set(part == "elm.swallow.icon" ? "home" : "clock")
76 size_hint_aspect_set 0, 1, 1
77 end.to_ptr
78 end
79
61end 80end
62# 81#
63Window.new 82Window.new