module Rabbit::Element::Base
Attributes
Public Class Methods
Source
# File lib/rabbit/element/base.rb, line 56 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
Source
# File lib/rabbit/element/base.rb, line 484 def []=(name, value) @user_property[name] = value end
Source
# File lib/rabbit/element/base.rb, line 229 def add_default_prop(name, value) name = normalize_property_name(name) @default_prop[name] = make_prop_value(name, value) end
Source
# File lib/rabbit/element/base.rb, line 324 def adjust_y_margin(y, h) y += @margin_bottom h -= @margin_bottom [y, h] end
Source
# File lib/rabbit/element/base.rb, line 310 def adjust_y_padding(y, h) y -= @padding_top h += @padding_top + @padding_bottom [y, h] end
Source
# File lib/rabbit/element/base.rb, line 405 def available_w @w - @padding_left - @padding_right end
Source
# File lib/rabbit/element/base.rb, line 421 def centering_adjusted_height @centering_adjusted_height || 0 end
Source
# File lib/rabbit/element/base.rb, line 417 def centering_adjusted_width @centering_adjusted_width || 0 end
Source
# File lib/rabbit/element/base.rb, line 355 def clear_margin @margin_left = @default_margin_left @margin_right = @default_margin_right @margin_top = @default_margin_top @margin_bottom = @default_margin_bottom end
Source
# File lib/rabbit/element/base.rb, line 348 def clear_padding @padding_left = @default_padding_left @padding_right = @default_padding_right @padding_top = @default_padding_top @padding_bottom = @default_padding_bottom end
Source
# File lib/rabbit/element/base.rb, line 263 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
Source
# File lib/rabbit/element/base.rb, line 433 def clone obj = super obj.user_property = @user_property.clone obj.prop = @prop.clone obj end
Calls superclass method
Source
# File lib/rabbit/element/base.rb, line 120 def compile(canvas, x, y, w, h) compile_element(canvas, x, y, w, h) end
Source
# File lib/rabbit/element/base.rb, line 124 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
Source
# File lib/rabbit/element/base.rb, line 134 def compile_for_horizontal_centering(canvas, x, y, w, h) compile(canvas, x, y, w, h) end
Source
# File lib/rabbit/element/base.rb, line 138 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
Source
# File lib/rabbit/element/base.rb, line 440 def default_prop @default_prop.dup end
Source
# File lib/rabbit/element/base.rb, line 391 def do_horizontal_centering(canvas, x, y, w, h) end
Source
# File lib/rabbit/element/base.rb, line 369 def do_horizontal_centering? @horizontal_centering or (parent and parent.do_horizontal_centering?) end
Source
# File lib/rabbit/element/base.rb, line 374 def do_vertical_centering? @vertical_centering or (parent and parent.do_horizontal_centering?) end
Source
# File lib/rabbit/element/base.rb, line 89 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 = restore_x_centering(x, w) y, h = adjust_y_padding(y, h) y, h = adjust_y_margin(y, h) [x, y, w, h] end
Source
# File lib/rabbit/element/base.rb, line 234 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
Source
# File lib/rabbit/element/base.rb, line 413 def height @height + @padding_top + @padding_bottom end
Source
# File lib/rabbit/element/base.rb, line 476 def hide(&block) change_visible(false, &block) end
Source
# File lib/rabbit/element/base.rb, line 379 def horizontal_centering=(new_value) if @horizontal_centering != new_value dirty! end @horizontal_centering = new_value end
Source
# File lib/rabbit/element/base.rb, line 362 def if_dirty if dirty? yield @dirty = false end end
Source
# File lib/rabbit/element/base.rb, line 337 def init_default_margin @default_margin_left = 0 @default_margin_right = 0 @default_margin_top = 0 @default_margin_bottom = 0 end
Source
# File lib/rabbit/element/base.rb, line 330 def init_default_padding @default_padding_left = 0 @default_padding_right = 0 @default_padding_top = 0 @default_padding_bottom = 0 end
Source
# File lib/rabbit/element/base.rb, line 344 def init_default_visible @default_visible = !have_wait_tag? end
Source
# File lib/rabbit/element/base.rb, line 425 def inspect(verbose=false) if verbose super() else "<#{self.class.name}>" end end
Calls superclass method
Source
# File lib/rabbit/element/base.rb, line 448 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
Source
# File lib/rabbit/element/base.rb, line 456 def margin_with(params) margin_set(params) end
Source
# File lib/rabbit/element/base.rb, line 444 def match?(pattern) pattern === text end
Source
# File lib/rabbit/element/base.rb, line 401 def next_element sibling_element(1) end
Source
# File lib/rabbit/element/base.rb, line 460 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
Source
# File lib/rabbit/element/base.rb, line 468 def padding_with(params) padding_set(params) end
Source
# File lib/rabbit/element/base.rb, line 67 def parent=(parent) @slide = nil @parent = parent end
Source
# File lib/rabbit/element/base.rb, line 397 def previous_element sibling_element(-1) end
Source
# File lib/rabbit/element/base.rb, line 222 def prop_delete(name) name = normalize_property_name(name) @prop.delete(name) dirty! end
Also aliased as: __prop_delete__
Source
# File lib/rabbit/element/base.rb, line 209 def prop_get(name) name = normalize_property_name(name) @prop[name] end
Also aliased as: __prop_get__
Source
# File lib/rabbit/element/base.rb, line 202 def prop_set(name, *values) name = normalize_property_name(name) @prop[name] = make_prop_value(name, *values) dirty! end
Also aliased as: __prop_set__
Source
# File lib/rabbit/element/base.rb, line 215 def prop_value(name) name = normalize_property_name(name) value = @prop[name] value = value.value if value.respond_to?(:value) value end
Source
# File lib/rabbit/element/base.rb, line 394 def reset_horizontal_centering(canvas, x, y, w, h) end
Source
# File lib/rabbit/element/base.rb, line 304 def restore_x_centering(x, w) x -= centering_adjusted_width w += centering_adjusted_width [x, w] end
Source
# File lib/rabbit/element/base.rb, line 292 def restore_x_margin(x, w) x -= @margin_left w += @margin_left + @margin_right [x, w] end
Source
# File lib/rabbit/element/base.rb, line 286 def restore_x_padding(x, w) x -= @padding_left w += @padding_left + @padding_right [x, w] end
Source
# File lib/rabbit/element/base.rb, line 178 def scene_snapshot(widget, snapshot, canvas, width, height) return unless scene_visible? x, y, w, h = widget.x, widget.y, width, height # Dirty... We need to reconsider when we compute horizontal # centering after we remove DrawingArea based rendering # engine. original_x = @x @x = widget.x - @padding_left # pre_draw_proc may be deleted while calling. For example, the # image-timer theme's init proc is deleted when it's called. @pre_draw_procs.dup.each do |proc, _name| x, y, w, h = proc.call(canvas, x, y, w, h, false) end # DrawingArea based renderer set padding after pre_draw_procs. x, y, w, h = setup_padding(x, y, w, h) x, y, w, h = scene_snapshot_element(widget, snapshot, canvas, x, y, w, h) # post_draw_proc may be deleted while calling. @post_draw_procs.dup.each do |proc, _name| x, y, w, h = proc.call(canvas, x, y, w, h, false) end @x = original_x end
Source
# File lib/rabbit/element/base.rb, line 76 def scene_visible? if @parent return false unless @parent.scene_visible? end return true if @visible return true if slide&.visible_waited_target?(self) false end
Source
# File lib/rabbit/element/base.rb, line 316 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
Source
# File lib/rabbit/element/base.rb, line 278 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
Source
# File lib/rabbit/element/base.rb, line 146 def setup_scene(canvas, scene_widget, x, y, w, h) compile(canvas, x, y, w, h) x, y, w, h = setup_margin(x, y, w, h) x, w = setup_x_centering(x, w) x, y, w, h = setup_padding(x, y, w, h) @pre_draw_procs.each do |proc, _name| x, y, w, h = proc.call(canvas, x, y, w, h, true) end x, y, w, h = setup_scene_element(canvas, scene_widget, x, y, w, h) @post_draw_procs.each do |proc, _name| x, y, w, h = proc.call(canvas, x, y, w, h, true) end x, w = restore_x_padding(x, w) x, w = restore_x_margin(x, w) x, w = restore_x_centering(x, w) y, h = adjust_y_padding(y, h) y, h = adjust_y_margin(y, h) [x, y, w, h] end
Source
# File lib/rabbit/element/base.rb, line 172 def setup_scene_element(canvas, scene_widget, x, y, w, h) widget = Renderer::SceneNodeWidget.new(canvas, self, x, y, w, h) scene_widget.put(widget, x, y, w, h) [x, y, w, h] end
Source
# File lib/rabbit/element/base.rb, line 298 def setup_x_centering(x, w) x += centering_adjusted_width w -= centering_adjusted_width [x, w] end
Source
# File lib/rabbit/element/base.rb, line 472 def show(&block) change_visible(true, &block) end
Source
# File lib/rabbit/element/base.rb, line 257 def substitute_newline substitute_text do |text| text.gsub(/(\\)?\\n/) {$1 ? "\\n" : "\n"} end end
Source
# File lib/rabbit/element/base.rb, line 386 def vertical_centering=(new_value) dirty! if @vertical_centering != new_value @vertical_centering = new_value end
Source
# File lib/rabbit/element/base.rb, line 108 def wait(*args, &block) slide.register_wait_proc(self, *args, &block) if slide end
Source
# File lib/rabbit/element/base.rb, line 409 def width @width + @padding_left + @padding_right end
Protected Instance Methods
Source
# File lib/rabbit/element/base.rb, line 489 def user_property=(prop) @user_property = prop end
Private Instance Methods
Source
# File lib/rabbit/element/base.rb, line 575 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
Source
# File lib/rabbit/element/base.rb, line 581 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
Source
# File lib/rabbit/element/base.rb, line 605 def _indent(str, width=" ") result = "" str.each_line do |line| result << width + line end result end
Source
# File lib/rabbit/element/base.rb, line 498 def _slide if @parent @parent.slide else nil end end
Source
# File lib/rabbit/element/base.rb, line 506 def change_visible(value) visible = @visible @visible = value if block_given? begin yield ensure @visible = visible end end end
Source
# File lib/rabbit/element/base.rb, line 518 def make_prop_value(name, *values) formatter_name = to_class_name(name) unless Format.const_defined?(formatter_name) raise UnknownPropertyError.new(name) end Format.const_get(formatter_name).new(*values) end
Source
# File lib/rabbit/element/base.rb, line 544 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
Source
# File lib/rabbit/element/base.rb, line 539 def normalize_property_name(name) name = name.to_s if name.is_a?(Symbol) name.gsub(/_/, "-") end
Source
# File lib/rabbit/element/base.rb, line 526 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