Class: EideticRML::Widgets::Widget

Inherits:
Object
  • Object
show all
Includes:
Support
Defined in:
lib/erml_widgets.rb

Direct Known Subclasses

Arc, Container, Image, Line, PreformattedText, Span, Star

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support

#from_units, parse_measurement, parse_measurement_pts, #to_units

Constructor Details

#initialize(parent, attrs = {}) ⇒ Widget

Returns a new instance of Widget.



27
28
29
30
31
32
33
# File 'lib/erml_widgets.rb', line 27

def initialize(parent, attrs={})
  @parent = parent
  @display = parent.display
  parent.children << self if parent.respond_to?(:children)
  attributes(attrs)
  @visible = true
end

Instance Attribute Details

#disabledObject

Returns the value of attribute disabled.



24
25
26
# File 'lib/erml_widgets.rb', line 24

def disabled
  @disabled
end

#height_pctObject (readonly)

Returns the value of attribute height_pct.



23
24
25
# File 'lib/erml_widgets.rb', line 23

def height_pct
  @height_pct
end

#max_height_pctObject (readonly)

Returns the value of attribute max_height_pct.



23
24
25
# File 'lib/erml_widgets.rb', line 23

def max_height_pct
  @max_height_pct
end

#max_width_pctObject (readonly)

Returns the value of attribute max_width_pct.



23
24
25
# File 'lib/erml_widgets.rb', line 23

def max_width_pct
  @max_width_pct
end

#parentObject

Returns the value of attribute parent.



24
25
26
# File 'lib/erml_widgets.rb', line 24

def parent
  @parent
end

#printedObject



468
469
470
# File 'lib/erml_widgets.rb', line 468

def printed
  @printed or @disabled
end

#visible(bounds = nil) ⇒ Object



543
544
545
546
547
# File 'lib/erml_widgets.rb', line 543

def visible(bounds=nil)
  return @visible if bounds.nil?
  return 0 if left.nil? or top.nil? or right.nil? or bottom.nil?
  (left >= bounds.left and top >= bounds.top and right <= bounds.right and bottom <= bounds.bottom) ? 1 : 0
end

#width_pctObject (readonly)

Returns the value of attribute width_pct.



23
24
25
# File 'lib/erml_widgets.rb', line 23

def width_pct
  @width_pct
end

Instance Method Details

#after_layoutObject



271
272
273
# File 'lib/erml_widgets.rb', line 271

def after_layout
  # override this method
end

#align(value = nil) ⇒ Object



52
53
54
55
# File 'lib/erml_widgets.rb', line 52

def align(value=nil)
  return @align if value.nil?
  @align = value.to_sym if [:top, :right, :bottom, :left].include?(value.to_sym)
end

#attributes(attrs) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/erml_widgets.rb', line 43

def attributes(attrs)
  attrs = attrs.inject({}) { |m, kv| m[kv.first.to_s.sub(/^class$/,'klass')] = kv.last; m } # stringify keys
  pre_keys, post_keys = attributes_first & attrs.keys, attributes_last & attrs.keys # keys are sorted same as attributes_first
  keys = attrs.keys - pre_keys - post_keys
  pre_keys.each { |key| attribute(key, attrs[key]) }
  keys.each { |key| attribute(key, attrs[key]) }
  post_keys.each { |key| attribute(key, attrs[key]) }
end

#before_layoutObject



263
264
265
# File 'lib/erml_widgets.rb', line 263

def before_layout
  @orig_width, @orig_height = @width, @height
end

#border(value = nil) ⇒ Object



281
282
283
284
285
# File 'lib/erml_widgets.rb', line 281

def border(value=nil)
  return @border if value.nil?
  @border = pen_style_for(value)
  @border_top = @border_right = @border_bottom = @border_left = nil
end

#border_bottom(value = nil) ⇒ Object



297
298
299
300
# File 'lib/erml_widgets.rb', line 297

def border_bottom(value=nil)
  return @border_bottom || @border if value.nil?
  @border_bottom = pen_style_for(value)
end

#border_left(value = nil) ⇒ Object



302
303
304
305
# File 'lib/erml_widgets.rb', line 302

def border_left(value=nil)
  return @border_left || @border if value.nil?
  @border_left = pen_style_for(value)
end

#border_right(value = nil) ⇒ Object



292
293
294
295
# File 'lib/erml_widgets.rb', line 292

def border_right(value=nil)
  return @border_right || @border if value.nil?
  @border_right = pen_style_for(value)
end

#border_top(value = nil) ⇒ Object



287
288
289
290
# File 'lib/erml_widgets.rb', line 287

def border_top(value=nil)
  return @border_top || @border if value.nil?
  @border_top = pen_style_for(value)
end

#bottom(value = nil, units = nil) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/erml_widgets.rb', line 123

def bottom(value=nil, units=nil)
  return rel_y(shifted_y(@bottom || ((@top.nil? or height.nil?) ? nil : @top + height))) if value.nil?
  return to_units(value, bottom) if value.is_a?(Symbol)
  @position = :relative if position == :static and value.respond_to?(:to_str)
  @bottom = parse_measurement_pts(value, units || self.units)
  @bottom = parent.height + @bottom if @bottom <= 0
  @height = @bottom - @top unless @top.nil?
end

#cloneObject



35
36
37
# File 'lib/erml_widgets.rb', line 35

def clone
  @clone ||= super
end

#colspan(value = nil) ⇒ Object



497
498
499
500
# File 'lib/erml_widgets.rb', line 497

def colspan(value=nil)
  return @colspan || 1 if value.nil?
  @colspan = value.to_i if value.to_i >= 1
end

#content_bottom(units = :pt) ⇒ Object



239
240
241
# File 'lib/erml_widgets.rb', line 239

def content_bottom(units=:pt)
  to_units(units, bottom - margin_bottom - padding_bottom)
end

#content_height(units = :pt) ⇒ Object



247
248
249
# File 'lib/erml_widgets.rb', line 247

def content_height(units=:pt)
  to_units(units, (height || 0) - non_content_height)
end

#content_left(units = :pt) ⇒ Object



243
244
245
# File 'lib/erml_widgets.rb', line 243

def content_left(units=:pt)
  to_units(units, left + margin_left + padding_left)
end

#content_right(units = :pt) ⇒ Object



235
236
237
# File 'lib/erml_widgets.rb', line 235

def content_right(units=:pt)
  to_units(units, right - margin_right - padding_right)
end

#content_top(units = :pt) ⇒ Object



231
232
233
# File 'lib/erml_widgets.rb', line 231

def content_top(units=:pt)
  to_units(units, top + margin_top + padding_top)
end

#content_width(units = :pt) ⇒ Object



251
252
253
# File 'lib/erml_widgets.rb', line 251

def content_width(units=:pt)
  to_units(units, (width || 0) - non_content_width)
end

#default_padding_bottomObject



363
364
365
# File 'lib/erml_widgets.rb', line 363

def default_padding_bottom
  0
end

#default_padding_leftObject



367
368
369
# File 'lib/erml_widgets.rb', line 367

def default_padding_left
  0
end

#default_padding_rightObject



359
360
361
# File 'lib/erml_widgets.rb', line 359

def default_padding_right
  0
end

#default_padding_topObject



355
356
357
# File 'lib/erml_widgets.rb', line 355

def default_padding_top
  0
end

#display(value = nil) ⇒ Object



480
481
482
483
# File 'lib/erml_widgets.rb', line 480

def display(value=nil)
  return @display || :once if value.nil?
  @display = value.to_sym if [:once, :always, :first, :succeeding, :even, :odd].include?(value.to_sym)
end

#display_for_page(document_page_no, section_page_no) ⇒ Object



485
486
487
488
489
490
491
492
493
494
495
# File 'lib/erml_widgets.rb', line 485

def display_for_page(document_page_no, section_page_no)
  # puts "display_for_page: #{display.inspect}"
  case display
  when :always then true
  when :first then section_page_no == 1
  when :succeeding then section_page_no > 1
  when :even then document_page_no.even?
  when :odd then document_page_no.odd?
  else false
  end
end

#fill(value = nil) ⇒ Object



307
308
309
310
# File 'lib/erml_widgets.rb', line 307

def fill(value=nil)
  return @fill if value.nil?
  @fill = brush_style_for(value)
end

#font(value = nil) ⇒ Object



414
415
416
417
418
419
# File 'lib/erml_widgets.rb', line 414

def font(value=nil)
  # inherited
  return @font || parent.font if value.nil?
  return @font = font.clone if value == :copy
  @font = font_style_for(value)
end

#font_color(value = nil) ⇒ Object



421
422
423
424
# File 'lib/erml_widgets.rb', line 421

def font_color(value=nil)
  return font.color if value.nil?
  font(:copy).color(value)
end

#font_size(value = nil) ⇒ Object



426
427
428
429
# File 'lib/erml_widgets.rb', line 426

def font_size(value=nil)
  return font.size if value.nil?
  font(:copy).size(value)
end

#font_style(value = nil) ⇒ Object



431
432
433
434
435
# File 'lib/erml_widgets.rb', line 431

def font_style(value=nil)
  return font.style if value.nil?
  @font = font.clone
  @font.style(value)
end

#font_weight(value = nil) ⇒ Object



437
438
439
440
441
# File 'lib/erml_widgets.rb', line 437

def font_weight(value=nil)
  return font.weight if value.nil?
  @font = font.clone
  @font.weight(value)
end

#has_height?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/erml_widgets.rb', line 142

def has_height?
  @height and !@height_pct
end

#has_width?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/erml_widgets.rb', line 146

def has_width?
  @width and !@width_pct
end

#height(value = nil, units = nil) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/erml_widgets.rb', line 176

def height(value=nil, units=nil)
  return @height_pct ? @height_pct * parent.content_height : @height if value.nil?
  return to_units(value, height) if value.is_a?(Symbol)
  if value =~ /(\d+(\.\d+)?)%/
    @height_pct = $1.to_f.quo(100)
    @height = @height_pct * parent.content_height
  elsif value.to_s =~ /^[+-]/
    @height = parent.content_height + parse_measurement_pts(value, units || self.units)
    @height_pct = nil
  else
    @height = parse_measurement_pts(value, units || self.units)
    @height_pct = nil
  end
  @bottom = nil unless @top.nil?
  height_set
end

#id(value = nil) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/erml_widgets.rb', line 68

def id(value=nil)
  return @id if value.nil?
  if value.to_s =~ /^(\w+)$/
    @id = $1.freeze
    root.widgets[@id] = self
  end
  @path = nil
end

#initialize_copy(other) ⇒ Object



39
40
41
# File 'lib/erml_widgets.rb', line 39

def initialize_copy(other)
  @is_clone = true
end

#klass(value = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/erml_widgets.rb', line 77

def klass(value=nil)
  return @klass if value.nil?
  @klass = $1.freeze if value.to_s =~ /^\s*(\w+(\s+\w+)*)\s*$/
  @path = nil
  return if parent.nil?
  attributes(root.rules.matching(path).inject({}) { |attrs, rule| attrs.update(rule.attrs) })
end

#layout_widget(writer) ⇒ Object



267
268
269
# File 'lib/erml_widgets.rb', line 267

def layout_widget(writer)
  # override this method
end

#leaf?Boolean

def postpone

@visible = false
@postponed ||= 0
@postponed += 1
@disabled = true if @postponed > 1

end

Returns:

  • (Boolean)


556
557
558
# File 'lib/erml_widgets.rb', line 556

def leaf?
  true
end

#leavesObject



560
561
562
# File 'lib/erml_widgets.rb', line 560

def leaves
  leaf? ? 1 : 0
end

#left(value = nil, units = nil) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/erml_widgets.rb', line 96

def left(value=nil, units=nil)
  return rel_x(shifted_x(@left || ((@right.nil? or width.nil?) ? nil : @right - width))) if value.nil?
  return to_units(value, left) if value.is_a?(Symbol)
  @position = :relative if position == :static and value.respond_to?(:to_str)
  @left = parse_measurement_pts(value, units || self.units)
  @left = parent.width + @left if @left < 0
  @width = @right - @left unless @right.nil?
end

#margin(value = nil) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/erml_widgets.rb', line 336

def margin(value=nil)
  return [margin_top, margin_right, margin_bottom, margin_left] if value.nil?
  return [margin_top(value), margin_right(value), margin_bottom(value), margin_left(value)] if value.is_a?(Symbol)
  if value.respond_to?(:to_str)
    value = value.split(',').map do |n|
      parse_measurement_pts(n, units)
    end
  else
    value = Array(value).map { |m| from_units(units, m) }
  end
  m = case value.size
    when 4 then value
    when 2 then value * 2
    when 1 then value * 4
  else nil
  end
  @margin_top, @margin_right, @margin_bottom, @margin_left = m unless m.nil?
end

#margin_bottom(value = nil) ⇒ Object



324
325
326
327
328
# File 'lib/erml_widgets.rb', line 324

def margin_bottom(value=nil)
  return @margin_bottom || 0 if value.nil?
  return to_units(value, margin_bottom) if value.is_a?(Symbol)
  @margin_bottom = parse_measurement_pts(value, units)
end

#margin_left(value = nil) ⇒ Object



330
331
332
333
334
# File 'lib/erml_widgets.rb', line 330

def margin_left(value=nil)
  return @margin_left || 0 if value.nil?
  return to_units(value, margin_left) if value.is_a?(Symbol)
  @margin_left = parse_measurement_pts(value, units)
end

#margin_right(value = nil) ⇒ Object



318
319
320
321
322
# File 'lib/erml_widgets.rb', line 318

def margin_right(value=nil)
  return @margin_right || 0 if value.nil?
  return to_units(value, margin_right) if value.is_a?(Symbol)
  @margin_right = parse_measurement_pts(value, units)
end

#margin_top(value = nil) ⇒ Object



312
313
314
315
316
# File 'lib/erml_widgets.rb', line 312

def margin_top(value=nil)
  return @margin_top || 0 if value.nil?
  return to_units(value, margin_top) if value.is_a?(Symbol)
  @margin_top = parse_measurement_pts(value, units)
end

#max_content_heightObject



223
224
225
# File 'lib/erml_widgets.rb', line 223

def max_content_height
  max_height_avail - non_content_height
end

#max_height(value = nil, units = nil) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/erml_widgets.rb', line 208

def max_height(value=nil, units=nil)
  return @max_height_pct ? @max_height_pct * parent.content_height : @max_height if value.nil?
  return to_units(value, max_height) if value.is_a?(Symbol)
  if value =~ /(\d+(\.\d+)?)%/
    @max_height_pct = $1.to_f.quo(100)
    @max_height = @max_height_pct * parent.content_height
  elsif value.to_s =~ /^[+-]/
    @max_height = parent.content_height + parse_measurement_pts(value, units || self.units)
    @max_height_pct = nil
  else
    @max_height = parse_measurement_pts(value, units || self.units)
    @hmax_height_pct = nil
  end
end

#max_height_availObject



227
228
229
# File 'lib/erml_widgets.rb', line 227

def max_height_avail
  height || parent.max_content_height - ((top || parent.content_top) - parent.content_top)
end

#max_width(value = nil, units = nil) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/erml_widgets.rb', line 193

def max_width(value=nil, units=nil)
  return @max_width_pct ? @max_width_pct * parent.content_width : @max_width if value.nil?
  return to_units(value, max_width) if value.is_a?(Symbol)
  if value =~ /(\d+(\.\d+)?)%/
    @max_width_pct = $1.to_f.quo(100)
    @max_width = @max_width_pct * parent.content_width
  elsif value.to_s =~ /^[+-]/
    @max_width = parent.content_width + parse_measurement_pts(value, units || self.units)
    @max_width_pct = nil
  else
    @max_width = parse_measurement_pts(value, units || self.units)
    @max_width_pct = nil
  end
end

#non_content_heightObject



255
256
257
# File 'lib/erml_widgets.rb', line 255

def non_content_height
  margin_top + padding_top + padding_bottom + margin_bottom
end

#non_content_widthObject



259
260
261
# File 'lib/erml_widgets.rb', line 259

def non_content_width
  margin_left + padding_left + padding_right + margin_right
end

#origin_x(value = nil) ⇒ Object



507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/erml_widgets.rb', line 507

def origin_x(value=nil)
  if value.nil?
    case @origin_x
    when 'left'   then left
    when 'center' then (left + right).quo(2)
    when 'right'  then right
    else left
    end
  else
    @origin_x = value.strip
  end
end

#origin_y(value = nil) ⇒ Object



520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/erml_widgets.rb', line 520

def origin_y(value=nil)
  if value.nil?
    case @origin_y
    when 'top'    then top
    when 'middle' then (top + bottom).quo(2)
    when 'bottom' then bottom
    else top
    end
  else
    @origin_y = value.strip
  end
end

#padding(value = nil) ⇒ Object



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/erml_widgets.rb', line 395

def padding(value=nil)
  return [padding_top, padding_right, padding_bottom, padding_left] if value.nil?
  return [padding_top(value), padding_right(value), padding_bottom(value), padding_left(value)] if value.is_a?(Symbol)
  if value.respond_to?(:to_str)
    value = value.split(',').map do |n|
      parse_measurement_pts(n, units)
    end
  else
    value = Array(value).map { |p| from_units(units, p) }
  end
  p = case value.size
    when 4 then value
    when 2 then value * 2
    when 1 then value * 4
  else nil
  end
  @padding_top, @padding_right, @padding_bottom, @padding_left = p unless p.nil?
end

#padding_bottom(value = nil) ⇒ Object



383
384
385
386
387
# File 'lib/erml_widgets.rb', line 383

def padding_bottom(value=nil)
  return @padding_bottom || default_padding_bottom if value.nil?
  return to_units(value, padding_bottom) if value.is_a?(Symbol)
  @padding_bottom = parse_measurement_pts(value, units)
end

#padding_left(value = nil) ⇒ Object



389
390
391
392
393
# File 'lib/erml_widgets.rb', line 389

def padding_left(value=nil)
  return @padding_left || default_padding_left if value.nil?
  return to_units(value, padding_left) if value.is_a?(Symbol)
  @padding_left = parse_measurement_pts(value, units)
end

#padding_right(value = nil) ⇒ Object



377
378
379
380
381
# File 'lib/erml_widgets.rb', line 377

def padding_right(value=nil)
  return @padding_right || default_padding_right if value.nil?
  return to_units(value, padding_right) if value.is_a?(Symbol)
  @padding_right = parse_measurement_pts(value, units)
end

#padding_top(value = nil) ⇒ Object



371
372
373
374
375
# File 'lib/erml_widgets.rb', line 371

def padding_top(value=nil)
  return @padding_top || default_padding_top if value.nil?
  return to_units(value, padding_top) if value.is_a?(Symbol)
  @padding_top = parse_measurement_pts(value, units)
end

#pathObject



92
93
94
# File 'lib/erml_widgets.rb', line 92

def path
  @path ||= (parent.nil? ? selector_tag : parent.path.dup << '/' << selector_tag).freeze
end

#position(value = nil) ⇒ Object



57
58
59
60
# File 'lib/erml_widgets.rb', line 57

def position(value=nil)
  return @position || :static if value.nil?
  @position = value.to_sym if [:static, :relative, :absolute].include?(value.to_sym)
end

#preferred_height(writer, units = :pt) ⇒ Object



154
155
156
# File 'lib/erml_widgets.rb', line 154

def preferred_height(writer, units=:pt)
  @height ? to_units(units, @height) : nil
end

#preferred_width(writer, units = :pt) ⇒ Object



150
151
152
# File 'lib/erml_widgets.rb', line 150

def preferred_width(writer, units=:pt)
  @width ? to_units(units, @width) : nil
end


443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/erml_widgets.rb', line 443

def print(writer)
  # $stderr.puts "<<<try printing #{object_id} (#{tag}) visible: #{visible}"
  return if visible == false
  return if disabled
  # $stderr.puts "print #{tag} { left = #{left}, top = #{top}}"
  before_print(writer)
  if @rotate.nil?
    paint_background(writer)
    draw_content(writer)
    draw_border(writer)
  else
    writer.rotate(rotate, origin_x, origin_y) do
      paint_background(writer)
      draw_content(writer)
      draw_border(writer)
    end
  end
  @printed = true
  # $stderr.puts ">>>printed #{object_id} (#{tag})"
  @width = @orig_width if @orig_width
  @height = @orig_height if @orig_height
rescue Exception => e
  raise RuntimeError, e.message + "\nError printing #{path}.", e.backtrace
end

#right(value = nil, units = nil) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/erml_widgets.rb', line 114

def right(value=nil, units=nil)
  return rel_y(shifted_x(@right || ((@left.nil? or width.nil?) ? nil : @left + width))) if value.nil?
  return to_units(value, right) if value.is_a?(Symbol)
  @position = :relative if position == :static and value.respond_to?(:to_str)
  @right = parse_measurement_pts(value, units || self.units)
  @right = parent.width + @right if @right <= 0
  @width = @right - @left unless @left.nil?
end

#rootObject



472
473
474
# File 'lib/erml_widgets.rb', line 472

def root
  parent.nil? ? self : parent.root
end

#root_pageObject



476
477
478
# File 'lib/erml_widgets.rb', line 476

def root_page
  parent.root_page
end

#rotate(value = nil) ⇒ Object



533
534
535
536
# File 'lib/erml_widgets.rb', line 533

def rotate(value=nil)
  return @rotate if value.nil?
  @rotate = value.to_f
end

#rowspan(value = nil) ⇒ Object



502
503
504
505
# File 'lib/erml_widgets.rb', line 502

def rowspan(value=nil)
  return @rowspan || 1 if value.nil?
  @rowspan = value.to_i if value.to_i >= 1
end

#selector_tagObject



85
86
87
88
89
90
# File 'lib/erml_widgets.rb', line 85

def selector_tag
  value = (tag || '').dup
  value << '#' << id unless id.nil?
  value << '.' << klass.split(/\s/).join('.') unless klass.nil?
  value
end

#shift(value = nil, units = nil) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/erml_widgets.rb', line 132

def shift(value=nil, units=nil)
  return [shift_x(units || :pt), shift_y(units || :pt)] if value.nil?
  if value.respond_to?(:to_str)
    x, y = value.to_s.split(',', 2)
  else
    x, y = Array(value)
  end
  @shift_x, @shift_y = parse_measurement_pts(x, units || self.units), parse_measurement_pts(y, units || self.units)
end

#tag(value = nil) ⇒ Object



62
63
64
65
66
# File 'lib/erml_widgets.rb', line 62

def tag(value=nil)
  return @tag if value.nil?
  @tag = $1.freeze if value.to_s =~ /^(\w+)$/
  @path = nil
end

#top(value = nil, units = nil) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/erml_widgets.rb', line 105

def top(value=nil, units=nil)
  return rel_y(shifted_y(@top || ((@bottom.nil? or height.nil?) ? nil : @bottom - height))) if value.nil?
  return to_units(value, top) if value.is_a?(Symbol)
  @position = :relative if position == :static and value.respond_to?(:to_str)
  @top = parse_measurement_pts(value, units || self.units)
  @top = parent.height + @top if @top < 0
  @height = @bottom - @top unless @bottom.nil?
end

#units(value = nil) ⇒ Object



275
276
277
278
279
# File 'lib/erml_widgets.rb', line 275

def units(value=nil)
  # inherited
  return @units || parent.units if value.nil?
  @units = value.to_sym if EideticPDF::UNIT_CONVERSION[value.to_sym]
end

#width(value = nil, units = nil) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/erml_widgets.rb', line 158

def width(value=nil, units=nil)
  return @width_pct ? @width_pct * parent.content_width : @width if value.nil?
  return to_units(value, width) if value.is_a?(Symbol)
  if value =~ /(\d+(\.\d+)?)%/
    @width_pct = $1.to_f.quo(100)
    # @width = @width_pct * parent.content_width
    @width = nil
  elsif value.to_s =~ /^[+-]/
    @width = parent.content_width + parse_measurement_pts(value, units || self.units)
    @width_pct = nil
  else
    @width = parse_measurement_pts(value, units || self.units)
    @width_pct = nil
  end
  @right = nil unless @left.nil?
  width_set
end

#z_index(value = nil) ⇒ Object



538
539
540
541
# File 'lib/erml_widgets.rb', line 538

def z_index(value=nil)
  return @z_index || 0 if value.nil?
  @z_index = value.to_i
end