module Rabbit::Element::Base
Attributes
base_h[R]
base_w[R]
base_x[R]
base_y[R]
default_margin_bottom[RW]
default_margin_left[RW]
default_margin_right[RW]
default_margin_top[RW]
default_padding_bottom[RW]
default_padding_left[RW]
default_padding_right[RW]
default_padding_top[RW]
default_visible[RW]
h[R]
horizontal_centering[R]
margin_bottom[RW]
margin_left[RW]
margin_right[RW]
margin_top[RW]
padding_bottom[RW]
padding_left[RW]
padding_right[RW]
padding_top[RW]
parent[R]
ph[R]
pw[R]
px[R]
py[R]
real_simulation[R]
user_property[R]
vertical_centering[R]
w[R]
x[R]
y[R]
Public Class Methods
new()
click to toggle source
# File lib/rabbit/element/base.rb, line 40 def initialize @x = @y = @w = @h = nil @parent = nil @user_property = {} @default_prop = {} init_default_padding init_default_margin init_default_visible clear_theme end
Public Instance Methods
[](name)
click to toggle source
# File lib/rabbit/element/base.rb, line 393 def [](name) @user_property[name] end
[]=(name, value)
click to toggle source
# File lib/rabbit/element/base.rb, line 397 def []=(name, value) @user_property[name] = value end
add_default_prop(name, value)
click to toggle source
# File lib/rabbit/element/base.rb, line 148 def add_default_prop(name, value) name = normalize_property_name(name) @default_prop[name] = make_prop_value(name, value) end
adjust_x_centering(x, w)
click to toggle source
# File lib/rabbit/element/base.rb, line 217 def adjust_x_centering(x, w) x -= centering_adjusted_width w += centering_adjusted_width [x, w] end
adjust_y_margin(y, h)
click to toggle source
# File lib/rabbit/element/base.rb, line 237 def adjust_y_margin(y, h) y += @margin_bottom h -= @margin_bottom [y, h] end
adjust_y_padding(y, h)
click to toggle source
# File lib/rabbit/element/base.rb, line 223 def adjust_y_padding(y, h) y -= @padding_top h += @padding_top + @padding_bottom [y, h] end
available_w()
click to toggle source
# File lib/rabbit/element/base.rb, line 318 def available_w @w - @padding_left - @padding_right end
centering_adjusted_height()
click to toggle source
# File lib/rabbit/element/base.rb, line 334 def centering_adjusted_height @centering_adjusted_height || 0 end
centering_adjusted_width()
click to toggle source
# File lib/rabbit/element/base.rb, line 330 def centering_adjusted_width @centering_adjusted_width || 0 end
clear_margin()
click to toggle source
# File lib/rabbit/element/base.rb, line 268 def clear_margin @margin_left = @default_margin_left @margin_right = @default_margin_right @margin_top = @default_margin_top @margin_bottom = @default_margin_bottom end
clear_padding()
click to toggle source
# File lib/rabbit/element/base.rb, line 261 def clear_padding @padding_left = @default_padding_left @padding_right = @default_padding_right @padding_top = @default_padding_top @padding_bottom = @default_padding_bottom end
clear_theme()
click to toggle source
# File lib/rabbit/element/base.rb, line 182 def clear_theme @slide = nil @visible = @default_visible @real_simulation = true @width = @height = nil @centering_adjusted_width = nil @centering_adjusted_height = nil @horizontal_centering = @vertical_centering = false @prop = default_prop clear_margin clear_padding clear_draw_procs dirty! end
clone()
click to toggle source
Calls superclass method
# File lib/rabbit/element/base.rb, line 346 def clone obj = super obj.user_property = @user_property.clone obj.prop = @prop.clone obj end
compile(canvas, x, y, w, h)
click to toggle source
# File lib/rabbit/element/base.rb, line 95 def compile(canvas, x, y, w, h) compile_element(canvas, x, y, w, h) end
compile_element(canvas, x, y, w, h)
click to toggle source
# File lib/rabbit/element/base.rb, line 99 def compile_element(canvas, x, y, w, h) @base_x, @base_y, @base_w, @base_h = x, y, w, h @px, @py, @pw, @ph = @x, @y, @w, @h x, y, w, h = setup_margin(x, y, w, h) @canvas, @x, @y, @w, @h = canvas, x, y, w, h if [@px, @py, @pw, @ph] != [@x, @y, @w, @h] dirty! end end
compile_for_horizontal_centering(canvas, x, y, w, h)
click to toggle source
# File lib/rabbit/element/base.rb, line 109 def compile_for_horizontal_centering(canvas, x, y, w, h) compile(canvas, x, y, w, h) end
compile_horizontal(canvas, x, y, w, h)
click to toggle source
# File lib/rabbit/element/base.rb, line 113 def compile_horizontal(canvas, x, y, w, h) if do_horizontal_centering? do_horizontal_centering(canvas, x, y, w, h) else reset_horizontal_centering(canvas, x, y, w, h) end end
default_prop()
click to toggle source
# File lib/rabbit/element/base.rb, line 353 def default_prop @default_prop.dup end
dirty!()
click to toggle source
# File lib/rabbit/element/base.rb, line 75 def dirty! @dirty = true end
dirty?()
click to toggle source
# File lib/rabbit/element/base.rb, line 79 def dirty? @dirty end
do_horizontal_centering(canvas, x, y, w, h)
click to toggle source
# File lib/rabbit/element/base.rb, line 304 def do_horizontal_centering(canvas, x, y, w, h) end
do_horizontal_centering?()
click to toggle source
# File lib/rabbit/element/base.rb, line 282 def do_horizontal_centering? @horizontal_centering or (parent and parent.do_horizontal_centering?) end
do_vertical_centering?()
click to toggle source
# File lib/rabbit/element/base.rb, line 287 def do_vertical_centering? @vertical_centering or (parent and parent.do_horizontal_centering?) end
draw(simulation=false)
click to toggle source
# File lib/rabbit/element/base.rb, line 64 def draw(simulation=false) x, y, w, h = setup_padding(@x, @y, @w, @h) x, y, w, h = _draw(@canvas, x, y, w, h, simulation) x, w = restore_x_padding(x, w) x, w = restore_x_margin(x, w) x, w = adjust_x_centering(x, w) y, h = adjust_y_padding(y, h) y, h = adjust_y_margin(y, h) [x, y, w, h] end
font(props)
click to toggle source
# File lib/rabbit/element/base.rb, line 153 def font(props) props.each do |key, value| key, value = normalize_font_property(key, value) if value prop_set(key, value) else prop_delete(key) end end end
have_tag?(name)
click to toggle source
# File lib/rabbit/element/base.rb, line 87 def have_tag?(name) false end
have_wait_tag?()
click to toggle source
# File lib/rabbit/element/base.rb, line 91 def have_wait_tag? false end
height()
click to toggle source
# File lib/rabbit/element/base.rb, line 326 def height @height + @padding_top + @padding_bottom end
hide(&block)
click to toggle source
# File lib/rabbit/element/base.rb, line 389 def hide(&block) change_visible(false, &block) end
horizontal_centering=(new_value)
click to toggle source
# File lib/rabbit/element/base.rb, line 292 def horizontal_centering=(new_value) if @horizontal_centering != new_value dirty! end @horizontal_centering = new_value end
if_dirty() { || ... }
click to toggle source
# File lib/rabbit/element/base.rb, line 275 def if_dirty if dirty? yield @dirty = false end end
init_default_margin()
click to toggle source
# File lib/rabbit/element/base.rb, line 250 def init_default_margin @default_margin_left = 0 @default_margin_right = 0 @default_margin_top = 0 @default_margin_bottom = 0 end
init_default_padding()
click to toggle source
# File lib/rabbit/element/base.rb, line 243 def init_default_padding @default_padding_left = 0 @default_padding_right = 0 @default_padding_top = 0 @default_padding_bottom = 0 end
init_default_visible()
click to toggle source
# File lib/rabbit/element/base.rb, line 257 def init_default_visible @default_visible = !have_wait_tag? end
inline_element?()
click to toggle source
# File lib/rabbit/element/base.rb, line 164 def inline_element? true end
inspect(verbose=false)
click to toggle source
Calls superclass method
# File lib/rabbit/element/base.rb, line 338 def inspect(verbose=false) if verbose super() else "<#{self.class.name}>" end end
margin_set(*values)
click to toggle source
# File lib/rabbit/element/base.rb, line 361 def margin_set(*values) top, right, bottom, left = parse_four_way(*values) @margin_top = top if top @margin_right = right if right @margin_bottom = bottom if bottom @margin_left = left if left end
margin_with(params)
click to toggle source
# File lib/rabbit/element/base.rb, line 369 def margin_with(params) margin_set(params) end
match?(pattern)
click to toggle source
# File lib/rabbit/element/base.rb, line 357 def match?(pattern) pattern === text end
next_element()
click to toggle source
# File lib/rabbit/element/base.rb, line 314 def next_element sibling_element(1) end
padding_set(*values)
click to toggle source
# File lib/rabbit/element/base.rb, line 373 def padding_set(*values) top, right, bottom, left = parse_four_way(*values) @padding_top = top if top @padding_right = right if right @padding_bottom = bottom if bottom @padding_left = left if left end
padding_with(params)
click to toggle source
# File lib/rabbit/element/base.rb, line 381 def padding_with(params) padding_set(params) end
parent=(parent)
click to toggle source
# File lib/rabbit/element/base.rb, line 51 def parent=(parent) @slide = nil @parent = parent end
previous_element()
click to toggle source
# File lib/rabbit/element/base.rb, line 310 def previous_element sibling_element(-1) end
prop_delete(name)
click to toggle source
# File lib/rabbit/element/base.rb, line 141 def prop_delete(name) name = normalize_property_name(name) @prop.delete(name) dirty! end
Also aliased as: __prop_delete__
prop_get(name)
click to toggle source
# File lib/rabbit/element/base.rb, line 128 def prop_get(name) name = normalize_property_name(name) @prop[name] end
Also aliased as: __prop_get__
prop_set(name, *values)
click to toggle source
# File lib/rabbit/element/base.rb, line 121 def prop_set(name, *values) name = normalize_property_name(name) @prop[name] = make_prop_value(name, *values) dirty! end
Also aliased as: __prop_set__
prop_value(name)
click to toggle source
# File lib/rabbit/element/base.rb, line 134 def prop_value(name) name = normalize_property_name(name) value = @prop[name] value = value.value if value.respond_to?(:value) value end
reset_horizontal_centering(canvas, x, y, w, h)
click to toggle source
# File lib/rabbit/element/base.rb, line 307 def reset_horizontal_centering(canvas, x, y, w, h) end
restore_x_margin(x, w)
click to toggle source
# File lib/rabbit/element/base.rb, line 211 def restore_x_margin(x, w) x -= @margin_left w += @margin_left + @margin_right [x, w] end
restore_x_padding(x, w)
click to toggle source
# File lib/rabbit/element/base.rb, line 205 def restore_x_padding(x, w) x -= @padding_left w += @padding_left + @padding_right [x, w] end
setup_margin(x, y, w, h)
click to toggle source
# File lib/rabbit/element/base.rb, line 229 def setup_margin(x, y, w, h) x += @margin_left y += @margin_top w -= @margin_left + @margin_right h -= @margin_top + @margin_bottom [x, y, w, h] end
setup_padding(x, y, w, h)
click to toggle source
# File lib/rabbit/element/base.rb, line 197 def setup_padding(x, y, w, h) x += @padding_left y += @padding_top w -= @padding_left + @padding_right h -= @padding_top + @padding_bottom [x, y, w, h] end
show(&block)
click to toggle source
# File lib/rabbit/element/base.rb, line 385 def show(&block) change_visible(true, &block) end
slide()
click to toggle source
# File lib/rabbit/element/base.rb, line 60 def slide @slide ||= _slide end
substitute_newline()
click to toggle source
# File lib/rabbit/element/base.rb, line 176 def substitute_newline substitute_text do |text| text.gsub(/(\\)?\\n/) {$1 ? "\\n" : "\n"} end end
substitute_text()
click to toggle source
# File lib/rabbit/element/base.rb, line 172 def substitute_text false end
text_renderer?()
click to toggle source
# File lib/rabbit/element/base.rb, line 168 def text_renderer? false end
vertical_centering=(new_value)
click to toggle source
# File lib/rabbit/element/base.rb, line 299 def vertical_centering=(new_value) dirty! if @vertical_centering != new_value @vertical_centering = new_value end
visible?()
click to toggle source
# File lib/rabbit/element/base.rb, line 56 def visible? @visible end
wait(*args, &block)
click to toggle source
# File lib/rabbit/element/base.rb, line 83 def wait(*args, &block) slide.register_wait_proc(self, *args, &block) if slide end
width()
click to toggle source
# File lib/rabbit/element/base.rb, line 322 def width @width + @padding_left + @padding_right end
Protected Instance Methods
prop=(prop)
click to toggle source
# File lib/rabbit/element/base.rb, line 406 def prop=(prop) @prop = prop end
user_property=(prop)
click to toggle source
# File lib/rabbit/element/base.rb, line 402 def user_property=(prop) @user_property = prop end
Private Instance Methods
_draw(canvas, x, y, w, h, simulation)
click to toggle source
# File lib/rabbit/element/base.rb, line 492 def _draw(canvas, x, y, w, h, simulation) around_draw_procs = @around_draw_procs.dup around_draw_procs.concat(slide.waited_draw_procs(self)) if slide _draw_rec(canvas, x, y, w, h, simulation, around_draw_procs) end
_draw_rec(canvas, x, y, w, h, simulation, around_draw_procs)
click to toggle source
# File lib/rabbit/element/base.rb, line 498 def _draw_rec(canvas, x, y, w, h, simulation, around_draw_procs) if around_draw_procs.empty? (@pre_draw_procs + [method(:draw_element)] + @post_draw_procs.reverse).each do |pro,| @real_simulation = simulation _simulation = simulation _simulation = true unless visible? x, y, w, h = pro.call(canvas, x, y, w, h, _simulation) end [x, y, w, h] else @real_simulation = simulation _simulation = simulation _simulation = true unless visible? pro, = around_draw_procs.pop next_proc = Proc.new do |*args| args << around_draw_procs _draw_rec(*args) end pro.call(canvas, x, y, w, h, _simulation, next_proc) end end
_indent(str, width=" ")
click to toggle source
# File lib/rabbit/element/base.rb, line 522 def _indent(str, width=" ") result = "" str.each_line do |line| result << width + line end result end
_slide()
click to toggle source
# File lib/rabbit/element/base.rb, line 411 def _slide if @parent @parent.slide else nil end end
change_visible(value) { || ... }
click to toggle source
# File lib/rabbit/element/base.rb, line 419 def change_visible(value) visible = @visible @visible = value if block_given? begin yield ensure @visible = visible end end end
make_prop_value(name, *values)
click to toggle source
# File lib/rabbit/element/base.rb, line 431 def make_prop_value(name, *values) formatter_name = to_class_name(name) begin unless Format.const_defined?(formatter_name) raise NameError end rescue NameError raise UnknownPropertyError.new(name) end Format.const_get(formatter_name).new(*values) end
normalize_font_property(key, value)
click to toggle source
# File lib/rabbit/element/base.rb, line 461 def normalize_font_property(key, value) key = key.to_s case key when /\A(family)\z/ ["font_#{$1}", value] when /\A(desc)(?:ription)?\z/ ["font_#{$1}", value] when /\A(?:foreground|color|fg_color|fg)\z/ ["foreground", value] when /\A(?:background|bg_color|bg)\z/ ["background", value] when /\A(?:underline|ul)\z/ ["underline", value] when /\A(?:underline|ul)_color\z/ ["underline_color", value] when /\A(rise|superscript|subscript)\z/ value = -value if $1 == "subscript" ["rise", value] when /\A(?:strike[_]?through)\z/ value = value ? "true" : "false" unless value.is_a?(String) ["strikethrough", value] when /\A(?:strike[_]?through_color)\z/ ["strikethrough_color", value] when /\A(?:fallback)\z/ value = value ? "true" : "false" unless value.is_a?(String) ["fallback", value] else [key, value] end end
normalize_property_name(name)
click to toggle source
# File lib/rabbit/element/base.rb, line 456 def normalize_property_name(name) name = name.to_s if name.is_a?(Symbol) name.gsub(/_/, "-") end
sibling_element(relative_index)
click to toggle source
# File lib/rabbit/element/base.rb, line 443 def sibling_element(relative_index) if @parent ind = @parent.elements.index(self) if ind @parent.elements[ind + relative_index] else nil end else nil end end