From a0ebdf466949c9e60a68f9ebbd7ab373018c07d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 21 Apr 2011 14:57:25 +0200 Subject: use inherited to give subclassess access to @func_prefixes, ElmWin uses Efl::Helper --- lib/efl/elementary.rb | 19 +++++++------------ lib/efl/ffi.rb | 1 + 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/efl/elementary.rb b/lib/efl/elementary.rb index ba263a8..cf06717 100644 --- a/lib/efl/elementary.rb +++ b/lib/efl/elementary.rb @@ -19,26 +19,21 @@ module Efl end end # - class ElmWin < Efl::Evas::EvasObject - attr_reader :evas_object + class ElmWin + include Efl::Helper + @func_prefixes = [ 'elm_win_', 'elm_' ].freeze def initialize parent, title, type=:elm_win_basic @evas_object = Evas::EvasObject.new Efl::API.elm_win_add parent, title, type - yield self if block_given? + @ptr = @evas_object.ptr + yield self,@evas_object if block_given? end def add e - eo = Evas::EvasObject.new Efl::API.send "elm_#{e}_add", @evas_object.ptr + eo = Evas::EvasObject.new Efl::API.send "elm_#{e}_add", @ptr yield eo if block_given? eo end def smart_callback_add event_str, cb, data=FFI::MemoryPointer::NULL - Efl::API.evas_object_smart_callback_add @evas_object.ptr, event_str, cb, data - end - def method_missing m, *args, &block - [ 'elm_win_', 'elm_' ].each do |s| - sym = s+m.to_s - return Efl::API.send( sym, @evas_object.ptr, *args, &block ) if Efl::API.respond_to? sym - end - Efl::API.send m + Efl::API.evas_object_smart_callback_add @ptr, event_str, cb, data end end # diff --git a/lib/efl/ffi.rb b/lib/efl/ffi.rb index 38bf16b..9425fd3 100644 --- a/lib/efl/ffi.rb +++ b/lib/efl/ffi.rb @@ -41,6 +41,7 @@ module Efl def self.included m m.class_eval "def ptr; @ptr; end" m.class_eval "def self.func_prefixes; @func_prefixes; end" + m.class_eval "def self.inherited sub; sub.class_eval 'def self.func_prefixes; superclass.func_prefixes; end'; end" end def method_missing m, *args, &block self.class.func_prefixes.each do |p| -- cgit v1.1-2-g2b99