summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--test/test_button-native.rb39
-rw-r--r--test/test_button.rb40
-rw-r--r--test/test_genlist-native.rb75
-rw-r--r--test/test_genlist.rb68
-rw-r--r--test/test_list.rb60
5 files changed, 282 insertions, 0 deletions
diff --git a/test/test_button-native.rb b/test/test_button-native.rb
new file mode 100644
index 0000000..5a805b2
--- /dev/null
+++ b/test/test_button-native.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+require 'efl/native/elm/elm_win'
+require 'efl/native/elm/elm_bg'
+require 'efl/native/elm/elm_button'
+require 'efl/native/elm/elm_object'
+#
+include Efl::Native
+#
+elm_init 0, FFI::MemoryPointer::NULL
+#
+def on_click data, object, event
+ elm_exit
+end
+#
+win = elm_win_add(nil, "Greetings", 0)
+elm_win_title_set(win, "Hello, World!")
+elm_win_autodel_set(win, true)
+elm_policy_set(0, 1)
+evas_object_resize(win, 240, 60)
+evas_object_show(win)
+#
+bg = elm_bg_add(win)
+evas_object_size_hint_weight_set(bg, 1.0, 1.0)
+elm_win_resize_object_add(win, bg)
+evas_object_show(bg)
+#
+btn = elm_button_add(win)
+elm_object_part_text_set(btn, nil, "Good-Bye, World!")
+evas_object_smart_callback_add(btn, "clicked", method(:on_click), nil)
+evas_object_resize(btn, 120, 30)
+evas_object_move(btn, 60, 15)
+evas_object_show(btn)
+#
+elm_run
+elm_shutdown
+#
+# EOF
diff --git a/test/test_button.rb b/test/test_button.rb
new file mode 100644
index 0000000..93168d3
--- /dev/null
+++ b/test/test_button.rb
@@ -0,0 +1,40 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+require 'efl/elm/elm_win'
+require 'efl/elm/elm_bg'
+require 'efl/elm/elm_button'
+#
+include Efl
+#
+class MyWin < Elm::ElmWin
+ #
+ def initialize
+ super(nil, "Greetings") do
+ title_set "Hello, World!"
+ resize 240, 60
+ show
+ end
+ @bg = Elm::ElmBg.new(self) do
+ size_hint_weight_expand
+ show
+ end
+ resize_object_add @bg
+ @btn = Elm::ElmButton.new(self) do
+ part_text_set(nil, "Good-Bye, World!")
+ smart_callback_add("clicked", ->(*_) { Elm.exit }, nil)
+ resize 120, 30
+ move 60, 15
+ show
+ end
+ end
+end
+#
+Elm.init
+#
+MyWin.new
+#
+Elm.run
+Elm.shutdown
+#
+# EOF
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
diff --git a/test/test_list.rb b/test/test_list.rb
new file mode 100644
index 0000000..583a5bd
--- /dev/null
+++ b/test/test_list.rb
@@ -0,0 +1,60 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+require 'efl/elm/elm_win'
+require 'efl/elm/elm_bg'
+require 'efl/elm/elm_list'
+#
+include Efl
+#
+class MyWin < Elm::ElmWin
+ #
+ def initialize name, title, &block
+ super FFI::MemoryPointer::NULL, name, &block
+ title_set title
+ feed
+ smart_callback_add "delete,request", method(:on_delete), FFI::MemoryPointer.from_string("my data")
+ end
+ #
+ def feed
+ _self = self
+ @bg = Elm::ElmBg.new(self) do
+ size_hint_weight_expand
+ evas_object_color_set 150,180,100,180
+
+ show
+ end
+ resize_object_add @bg
+ @list = Elm::ElmList.new(self) do
+ Dir.entries(ENV["HOME"]).each do |entry|
+ next if entry[0] == '.'
+ item_append entry, nil, nil, _self.method(:on_select),
+ FFI::MemoryPointer.from_string(entry)
+ end
+ size_hint_weight_expand
+ show
+ end
+ resize_object_add @list
+ end
+ #
+ def on_select data, evas_object, event_info
+ p [:selected, data.read_string]
+ end
+ #
+ def on_delete data, evas_object, event_info
+ puts "EXIT #{data.read_string}"
+ Elm.exit
+ end
+end
+#
+Elm.init
+#
+win = MyWin.new "MyList", "List Example" do
+ alpha_set true
+ resize 300, 200
+ center_set 600, 300
+ show
+end
+#
+Elm.run
+Elm.shutdown