Module: Rabbit::Element::ContainerElement

Constant Summary

Constants included from GetText

GetText::DOMAIN

Instance Attribute Summary collapse

Attributes included from Base

#base_h, #base_w, #base_x, #base_y, #default_margin_bottom, #default_margin_left, #default_margin_right, #default_margin_top, #default_padding_bottom, #default_padding_left, #default_padding_right, #default_padding_top, #default_visible, #h, #horizontal_centering, #margin_bottom, #margin_left, #margin_right, #margin_top, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #ph, #pw, #px, #py, #real_simulation, #user_property, #vertical_centering, #w, #x, #y

Instance Method Summary collapse

Methods included from Base

#add_default_prop, #adjust_x_centering, #adjust_y_margin, #adjust_y_padding, #available_w, #centering_adjusted_height, #centering_adjusted_width, #clear_margin, #clear_padding, #clone, #compile_element, #compile_for_horizontal_centering, #default_prop, #dirty!, #do_horizontal_centering, #do_horizontal_centering?, #do_vertical_centering?, #draw, #font, #hide, #if_dirty, #init_default_margin, #init_default_padding, #init_default_visible, #inline_element?, #margin_set, #margin_with, #match?, #next_element, #padding_set, #padding_with, #previous_element, #prop_value, #reset_horizontal_centering, #restore_x_margin, #restore_x_padding, #setup_margin, #setup_padding, #show, #slide, #substitute_newline, #text_renderer?, #visible?, #wait

Methods included from Base::DrawHook

#clear_draw_procs, def_draw_hook, def_draw_hooks

Methods included from Utils

arg_list, collect_classes_under_module, collect_modules_under_module, collect_under_module, combination, compute_bottom_y, compute_left_x, compute_right_x, compute_top_y, corresponding_class_under_module, corresponding_module_under_module, corresponding_objects, drawable_to_pixbuf, ensure_time, events_pending_available?, extract_four_way, find_path_in_load_path, init_by_constants_as_default_value, move_to, move_to_bottom_left, move_to_bottom_right, move_to_top_left, move_to_top_right, parse_four_way, process_pending_events, process_pending_events_proc, quartz?, require_files_under_directory_in_load_path, require_safe, split_number_to_minute_and_second, stringify_hash_key, support_console_input?, support_console_output?, syntax_highlighting_debug?, time, to_class_name, unescape_title, windows?

Methods included from GetText

included

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



13
14
15
# File 'lib/rabbit/element/container-element.rb', line 13

def elements
  @elements
end

Instance Method Details

#<<(element) ⇒ Object Also known as: add_element



27
28
29
30
31
# File 'lib/rabbit/element/container-element.rb', line 27

def <<(element)
  @elements << element
  element.parent = self
  dirty!
end

#[](name_or_index) ⇒ Object



248
249
250
251
252
253
254
# File 'lib/rabbit/element/container-element.rb', line 248

def [](name_or_index)
  if name_or_index.is_a?(Integer)
    @elements[name_or_index]
  else
    super
  end
end

#[]=(name_or_index, value) ⇒ Object



256
257
258
259
260
261
262
# File 'lib/rabbit/element/container-element.rb', line 256

def []=(name_or_index, value)
  if name_or_index.is_a?(Integer)
    @elements[name_or_index] = value
  else
    super
  end
end

#_widthObject

SLOW!!



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/rabbit/element/container-element.rb', line 178

def _width
  block_widths = []
  block_widths << @elements.inject(0) do |result, elem|
    if elem.width
      if elem.inline_element?
        result + elem.width
      else
        block_widths << elem.width
        elem.width
      end
    else
      result
    end
  end
  block_widths.max.to_i
end

#clear_themeObject Also known as: container_clear_theme



216
217
218
219
220
221
# File 'lib/rabbit/element/container-element.rb', line 216

def clear_theme
  @elements.each do |element|
    element.clear_theme
  end
  super
end

#compile(canvas, x, y, w, h) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/rabbit/element/container-element.rb', line 109

def compile(canvas, x, y, w, h)
  super
  if_dirty do
    x, y, w, h = setup_padding(@x, @y, @w, @h)
    compile_elements(canvas, x, y, w, h)
    x, w = restore_x_padding(x, w)
    x, w = adjust_x_centering(x, w)
    y, h = adjust_y_padding(y, h)
  end
end

#compile_elements(canvas, x, y, w, h) ⇒ Object



120
121
122
123
124
125
126
127
# File 'lib/rabbit/element/container-element.rb', line 120

def compile_elements(canvas, x, y, w, h)
  prev_is_inline = false
  @elements.each do |element|
    element.compile(canvas, x, y, w, h)
    compile_horizontal_element(element, canvas, x, y, w, h)
    x, y, w, h = element.draw(true)
  end
end

#compile_horizontal(canvas, x, y, w, h) ⇒ Object



129
130
131
132
133
# File 'lib/rabbit/element/container-element.rb', line 129

def compile_horizontal(canvas, x, y, w, h)
  @elements.each do |element|
    compile_horizontal_element(element, canvas, x, y, w, h)
  end
end

#compile_horizontal_element(element, canvas, x, y, w, h) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/rabbit/element/container-element.rb', line 135

def compile_horizontal_element(element, canvas, x, y, w, h)
  if do_horizontal_centering? or element.do_horizontal_centering?
    element.do_horizontal_centering(canvas, x, y, w, h)
  else
    element.reset_horizontal_centering(canvas, x, y, w, h)
  end
end

#delete(element) ⇒ Object



40
41
42
43
44
45
# File 'lib/rabbit/element/container-element.rb', line 40

def delete(element)
  return if @elements.delete(element).nil?
  element.parent = nil
  dirty!
  element
end

#dirty?Boolean

Returns:

  • (Boolean)


224
225
226
# File 'lib/rabbit/element/container-element.rb', line 224

def dirty?
  super or @elements.any?{|x| x.dirty?}
end

#draw_element(canvas, x, y, w, h, simulation) ⇒ Object



75
76
77
# File 'lib/rabbit/element/container-element.rb', line 75

def draw_element(canvas, x, y, w, h, simulation)
  draw_elements(canvas, x, y, w, h, simulation)
end

#draw_elements(canvas, x, y, w, h, simulation) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rabbit/element/container-element.rb', line 79

def draw_elements(canvas, x, y, w, h, simulation)
  @centering_adjusted_height = 0

  args = [x, y, w, h]
  if do_vertical_centering?
    adjust_height = ((h - height - @padding_bottom) / 2.0).ceil
    if y + adjust_height > 0
      args = [x, y + adjust_height, w, h - adjust_height]
    else
      adjust_height = 0
    end
    @centering_adjusted_height = adjust_height
    compile_elements(canvas, *args)
  end

  base_x, base_w = x, w
  @elements.each do |element|
    x, y, w, h = element.draw(simulation)
  end
  last_element = @elements.last
  if last_element and last_element.inline_element?
    container_height = height
    x = base_x
    y += container_height
    w = base_w
    h -= container_height
  end
  [x, y, w, h]
end

#have_tag?(name) ⇒ Boolean

Returns:

  • (Boolean)


240
241
242
# File 'lib/rabbit/element/container-element.rb', line 240

def have_tag?(name)
  @elements.any? {|element| element.have_tag?(name)}
end

#have_wait_tag?Boolean

Returns:

  • (Boolean)


244
245
246
# File 'lib/rabbit/element/container-element.rb', line 244

def have_wait_tag?
  @elements.any? {|element| element.have_wait_tag?}
end

#heightObject

perhaps SLOW!!



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/rabbit/element/container-element.rb', line 196

def height
  inline_heights = []
  @elements.inject(0) do |result, elem|
    elem_height = elem.height
    if elem_height
      if elem.inline_element?
        inline_heights << elem_height
        result
      else
        prev_inlines_max_height = inline_heights.max.to_i
        inline_heights.clear
        h = elem_height + elem.margin_top + elem.margin_bottom
        result + h + prev_inlines_max_height
      end
    else
      result
    end
  end + inline_heights.max.to_i + @padding_top + @padding_bottom
end

#initialize(elems = []) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/rabbit/element/container-element.rb', line 18

def initialize(elems=[])
  @elements = []
  elems = [elems] unless elems.is_a?(Array)
  elems.each do |elem|
    add_element(elem)
  end
  super()
end

#inspect(verbose = false) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
# File 'lib/rabbit/element/container-element.rb', line 228

def inspect(verbose=false)
  elem_info = @elements.collect do |x|
    _indent(x.inspect(verbose))
  end.join("\n")
  if verbose
    self_info = super(verbose)
  else
    self_info = "<#{self.class.name}>"
  end
  self_info + (elem_info.empty? ? "" : "\n") + elem_info
end

#prop_delete(name) ⇒ Object



161
162
163
164
165
# File 'lib/rabbit/element/container-element.rb', line 161

def prop_delete(name)
  collect do |elem|
    elem.prop_delete(name)
  end
end

#prop_get(name) ⇒ Object



155
156
157
158
159
# File 'lib/rabbit/element/container-element.rb', line 155

def prop_get(name)
  collect do |elem|
    elem.prop_get(name)
  end
end

#prop_set(*args) ⇒ Object



149
150
151
152
153
# File 'lib/rabbit/element/container-element.rb', line 149

def prop_set(*args)
  each do |elem|
    elem.prop_set(*args)
  end
end

#replace_element(child, *targets) ⇒ Object



70
71
72
73
# File 'lib/rabbit/element/container-element.rb', line 70

def replace_element(child, *targets)
  index = @elements.index(child)
  @elements[index, 1] = targets
end

#substitute_text(&block) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/rabbit/element/container-element.rb', line 59

def substitute_text(&block)
  substituted = false
  e = @elements.dup
  e.each_with_index do |element, i|
    element_substituted = element.substitute_text(&block)
    substituted ||= element_substituted
  end
  dirty! if substituted
  substituted
end

#textObject



47
48
49
50
51
# File 'lib/rabbit/element/container-element.rb', line 47

def text
  @elements.collect do |element|
    element.text
  end.join("\n")
end

#to_html(generator) ⇒ Object



143
144
145
146
147
# File 'lib/rabbit/element/container-element.rb', line 143

def to_html(generator)
  collect do |element|
    element.to_html(generator)
  end.join("\n")
end

#to_rdObject



53
54
55
56
57
# File 'lib/rabbit/element/container-element.rb', line 53

def to_rd
  @elements.collect do |element|
    element.to_rd
  end.join("\n")
end

#unshift(element) ⇒ Object



34
35
36
37
38
# File 'lib/rabbit/element/container-element.rb', line 34

def unshift(element)
  @elements.unshift(element)
  element.parent = self
  dirty!
end

#widthObject



167
168
169
170
171
172
173
174
175
# File 'lib/rabbit/element/container-element.rb', line 167

def width
  @elements.collect do |elem|
    w = elem.w
    if w
      w += elem.margin_left + elem.margin_right
    end
    w
  end.compact.max.to_i + @padding_left + @padding_right
end