lib/fxruby-enhancement/enhancement.rb in fxruby-enhancement-0.1.0 vs lib/fxruby-enhancement/enhancement.rb in fxruby-enhancement-0.2.0
- old
+ new
@@ -1,30 +1,32 @@
-# coding: utf-8
module Fox
# Include this in your top class objects.
# If for a module, you want to extend, rather
# than include.
# FIXME: later we will clean this up.
module Enhancement
@stack = []
@base = nil
@components = {}
+ @kinder_parents = {}
SPECIAL = [:FXApp,
:FXColorItem,
:FXRegion,
:FXRectangle,
+ :FXPoint,
:FXGradient,
:FXEvent,
:FXDataTarget,
:FXFileStream,
:FXExtentd]
INITFORCE = { FXMenuBar: 1 }
# Module-level
class << self
attr_accessor :stack,
+ :kinder_parents, # this is to make 'as' delecrations work intuitively.
:base, # the very first component declared, usually the app.
:components,
:deferred_setups,
:ms_ingress_delay_min,
:ms_ingress_delay_max
@@ -95,10 +97,13 @@
if block_given?
block.(inst)
end
return inst
end
+
+ def rgb
+ end
# Find the referenced component's wrapper object
def refc sym, &block
raise "No reference component for #{sym} found" if Enhancement.components[sym].nil?
c = Enhancement.components[sym]
@@ -126,10 +131,35 @@
fox_component(name).inst
end
end
alias_method :fxi, :fox_instance
+ # To allow for adding new components at
+ # other places other than the immediate
+ # parental nesting.
+ def as tag, kpos: Enhancement.stack.last, &block
+ Enhancement.stack << (@os = os = refc(tag))
+
+ # We must add our actual parent to the kinder parent
+ # registry, and remove it before we're done here.
+ kstacklvl = Enhancement.stack.size + 1
+ Enhancement.kinder_parents[kstacklvl] = kpos
+
+ def instance a=nil, &block
+ @os.instance_name = a
+ @os.instance_block ||= []
+ @os.instance_block << [a, block]
+ end
+
+ self.instance_eval &block
+
+ Enhancement.kinder_parents.delete kstacklvl
+ Enhancement.stack.pop
+ @os = Enhancement.stack.last
+ return os
+ end
+
# Handles incomming external messages of type given
# block, written by user, is called with |type, message|.
# Zero or more symbols may be given,
# in which case the given block will
# be associated with all the given symbols.
@@ -146,9 +176,18 @@
# of this is held off until the last possible
# moment.
# TODO: Not sure we need this. This may go away.
def deferred_setup &block
Enhancement.deferred_setups << block
- end
+ end
+
+ # This simplifies creating the FXDCWindow object.
+ def fx_dc tag, event=nil, &block
+ unless event.nil?
+ FXDCWindow.new(ref(tag), event) { |dc| block.(dc) }
+ else
+ FXDCWindow.new(ref(tag)) { |dc| block.(dc) }
+ end
+ end
end
end
end