summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_genlist-native.rb75
-rw-r--r--test/test_genlist.rb68
2 files changed, 143 insertions, 0 deletions
diff --git a/test/test_genlist-native.rb b/test/test_genlist-native.rb
new file mode 100644
index 0000000..19f8712
--- /dev/null
+++ b/test/test_genlist-native.rb
@@ -0,0 +1,75 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+require 'efl/native/elm/elm_win'
+require 'efl/native/elm/elm_bg'
+require 'efl/native/elm/elm_label'
+require 'efl/native/elm/elm_genlist'
+#
+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::Native
+#
+elm_init 0, FFI::MemoryPointer::NULL
+#
+win = elm_win_add(nil, "genlist", 0)
+elm_win_title_set(win, "Genlist")
+elm_policy_set(0, 1)
+elm_win_autodel_set(win, true)
+#
+bg = elm_bg_add(win)
+elm_bg_color_set(bg, 255, 255, 255)
+evas_object_size_hint_weight_set(bg, 1.0, 1.0)
+elm_win_resize_object_add(win, bg)
+evas_object_show(bg)
+#
+if !@itc
+ itc_ptr = elm_genlist_item_class_new
+ @itc = ElmGenItemClass.new(itc_ptr)
+ @itc[:item_style] = FFI::MemoryPointer.from_string("default")
+ @itc[:text_get] = FFI::Function.new(:pointer, [:pointer, :pointer, :string]) {|data, *_|
+ ptr = FFI::MemoryPointer.from_string("Item # #{data.read_string}")
+ ptr.autorelease = false
+ ptr
+ }
+ @itc[:content_get] = FFI::Function.new(:pointer, [:pointer, :pointer, :string]) do
+ |data, obj, part|
+ ic = elm_icon_add(obj)
+ elm_icon_standard_set(ic, "clock") if part == "elm.swallow.icon"
+ evas_object_size_hint_aspect_set(ic, 0, 1, 1)
+ ic
+ end
+ @itc[:state_get] = nil
+ @itc[:del] = nil
+end
+#
+list = elm_genlist_add(win)
+#
+30.times do |i|
+ elm_genlist_item_append(list, @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
+#
+evas_object_size_hint_weight_set(list, 1.0, 1.0)
+elm_win_resize_object_add(win, list)
+evas_object_show(list)
+#
+evas_object_resize(win, 200, 300)
+evas_object_show(win)
+#
+elm_run
+elm_shutdown
+#
+# EOF
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