Class: Fidgit::Container Abstract

Inherits:
Element show all
Extended by:
Forwardable
Defined in:
lib/fidgit/elements/container.rb

Overview

This class is abstract.

A container that contains Elements.

Direct Known Subclasses

Packer, ScrollArea

Constant Summary

Constant Summary

Constants inherited from Element

Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V

Instance Attribute Summary

Attributes inherited from Element

#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z

Instance Method Summary (collapse)

Methods inherited from Element

#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #width, #width=, #with, #x, #y

Methods included from Event

#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe

Constructor Details

- (Container) initialize(options = {})

Returns a new instance of Container



25
26
27
28
29
30
31
# File 'lib/fidgit/elements/container.rb', line 25

def initialize(options = {})
  options[:border_color] = default(:debug, :border_color) if Fidgit.debug_mode?

  @children = []

  super(options)
end

Instance Method Details

- (Object) add(element)



33
34
35
36
37
38
39
# File 'lib/fidgit/elements/container.rb', line 33

def add(element)
  element.send :parent=, self
  @children.push element

  recalc
  nil
end

- (Object) button(text, options = {}, &block)

Create a button within the container.



58
59
60
# File 'lib/fidgit/elements/container.rb', line 58

def button(text, options = {}, &block)
  Button.new(text, {parent: self}.merge!(options), &block)
end

- (Object) clear



140
141
142
143
144
145
146
147
# File 'lib/fidgit/elements/container.rb', line 140

def clear
  @children.each {|child| child.send :parent=, nil }
  @children.clear

  recalc

  nil
end

- (Object) color_picker(options = {}, &block)

Create a color picker within the container.



63
64
65
# File 'lib/fidgit/elements/container.rb', line 63

def color_picker(options = {}, &block)
  ColorPicker.new({parent: self}.merge!(options), &block)
end

- (Object) color_well(options = {}, &block)

Create a color well within the container.



68
69
70
# File 'lib/fidgit/elements/container.rb', line 68

def color_well(options = {}, &block)
  ColorWell.new({parent: self}.merge!(options), &block)
end

- (Object) combo_box(options = {}, &block)



72
73
74
# File 'lib/fidgit/elements/container.rb', line 72

def combo_box(options = {}, &block)
  ComboBox.new({parent: self}.merge!(options), &block)
end

- (Object) file_browser(type, options = {}, &block)



76
77
78
# File 'lib/fidgit/elements/container.rb', line 76

def file_browser(type, options = {}, &block)
  FileBrowser.new(type, {parent: self}.merge!(options), &block)
end

- (Object) grid(options = {}, &block)

Pack elements within the block in a grid (matrix) formation.



112
113
114
# File 'lib/fidgit/elements/container.rb', line 112

def grid(options = {}, &block)
  Grid.new({ parent: self }.merge!(options), &block)
end

- (Object) group(options = {}, &block)



80
81
82
# File 'lib/fidgit/elements/container.rb', line 80

def group(options = {}, &block)
  Group.new({parent: self}.merge!(options), &block)
end

- (Element?) hit_element(x, y)

Returns the element within this container that was hit,

Returns:

  • (Element, nil)

    The element hit, otherwise nil.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/fidgit/elements/container.rb', line 157

def hit_element(x, y)
  @children.reverse_each do |child|
    case child
    when Container, Composite
      if element = child.hit_element(x, y)
        return element
      end
    else
      return child if child.hit?(x, y)
    end
  end

  self if hit?(x, y)
end

- (Object) horizontal(options = {}, &block)

Pack elements within the block horizontally.



100
101
102
# File 'lib/fidgit/elements/container.rb', line 100

def horizontal(options = {}, &block)
  Horizontal.new({ parent: self }.merge!(options), &block)
end

- (Object) image_frame(image, options = {}, &block)

Create an icon.



85
86
87
# File 'lib/fidgit/elements/container.rb', line 85

def image_frame(image, options = {}, &block)
  ImageFrame.new(image, {parent: self}.merge!(options), &block)
end

- (Object) insert(position, element)



49
50
51
52
53
54
55
# File 'lib/fidgit/elements/container.rb', line 49

def insert(position, element)
  @children.insert position, element
  element.send :parent=, self

  recalc
  nil
end

- (Object) label(text, options = {})

Create a label within the container.



90
91
92
# File 'lib/fidgit/elements/container.rb', line 90

def label(text, options = {})
  Label.new(text, {parent: self}.merge!(options))
end

- (Object) list(options = {}, &block)



94
95
96
# File 'lib/fidgit/elements/container.rb', line 94

def list(options = {}, &block)
  List.new({parent: self}.merge!(options), &block)
end

- (Object) radio_button(text, value, options = {}, &block)



116
117
118
# File 'lib/fidgit/elements/container.rb', line 116

def radio_button(text, value, options = {}, &block)
  RadioButton.new(text, value, {parent: self}.merge!(options), &block)
end

- (Object) remove(element)



41
42
43
44
45
46
47
# File 'lib/fidgit/elements/container.rb', line 41

def remove(element)
  @children.delete element
  element.send :parent=, nil

  recalc
  nil
end

- (Object) scroll_area(options = {}, &block)



120
121
122
# File 'lib/fidgit/elements/container.rb', line 120

def scroll_area(options = {}, &block)
  ScrollArea.new({parent: self}.merge!(options), &block)
end

- (Object) scroll_window(options = {}, &block)



124
125
126
# File 'lib/fidgit/elements/container.rb', line 124

def scroll_window(options = {}, &block)
  ScrollWindow.new({parent: self}.merge!(options), &block)
end

- (Object) slider(options = {}, &block)



128
129
130
# File 'lib/fidgit/elements/container.rb', line 128

def slider(options = {}, &block)
  Slider.new({parent: self}.merge!(options), &block)
end

- (Object) text_area(options = {}, &block)



132
133
134
# File 'lib/fidgit/elements/container.rb', line 132

def text_area(options = {}, &block)
  TextArea.new({parent: self}.merge!(options), &block)
end

- (Object) to_s



188
189
190
# File 'lib/fidgit/elements/container.rb', line 188

def to_s
  "#{super} [#{@children.size} #{@children.size == 1 ? 'child' : 'children'}]"
end

- (Object) toggle_button(text, options = {}, &block)



136
137
138
# File 'lib/fidgit/elements/container.rb', line 136

def toggle_button(text, options = {}, &block)
  ToggleButton.new(text, {parent: self}.merge!(options), &block)
end

- (Object) update



149
150
151
152
153
# File 'lib/fidgit/elements/container.rb', line 149

def update
  @children.each { |c| c.update }

  nil
end

- (Object) vertical(options = {}, &block)

Pack elements within the blockvertically.



106
107
108
# File 'lib/fidgit/elements/container.rb', line 106

def vertical(options = {}, &block)
  Vertical.new({ parent: self }.merge!(options), &block)
end

- (Object) write_tree(indent = "", index = 0)



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/fidgit/elements/container.rb', line 193

def write_tree(indent = "", index = 0)
  puts self

  indent = indent + "  "

  @children.each.with_index do |element, i|
      print "#{indent}#{i}: "

      case element
        when Container
          element.write_tree(indent)
        else
          puts element
      end
  end
end

- (Object) x=(value)



12
13
14
15
# File 'lib/fidgit/elements/container.rb', line 12

def x=(value)
  @children.each {|c| c.x += value - x }
  super(value)
end

- (Object) y=(value)



17
18
19
20
# File 'lib/fidgit/elements/container.rb', line 17

def y=(value)
  @children.each {|c| c.y += value - y }
  super(value)
end