summaryrefslogtreecommitdiffstats
path: root/test/test_genlist.rb
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-02-19 00:33:42 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-02-19 00:33:42 +0100
commit745d270cc955b01264e9f11297ec6bd3ab2fb47d (patch)
tree14f78b460fde86fda3ef68623c63d8908e9fbcf4 /test/test_genlist.rb
parentf72de68ba9365398cf17c07594ce0ef666ab5992 (diff)
parent554927f7bad42cd1e5c25c4877646b284c736edd (diff)
downloadffi-efl-745d270cc955b01264e9f11297ec6bd3ab2fb47d.zip
ffi-efl-745d270cc955b01264e9f11297ec6bd3ab2fb47d.tar.gz
Merge pull request #4 from mhanne/examples
Examples for ElmButton, ElmList, ElmGenList
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