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

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_size, #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?, #font, #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, #publish, #subscribe

Constructor Details

#initialize(options = {}) ⇒ Container

Returns a new instance of Container.



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

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

  @children = []

  super(options)
end

Instance Method Details

#add(element) ⇒ Object



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

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

  recalc
  nil
end

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

Create a button within the container.



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

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

#clearObject



134
135
136
137
138
139
140
141
# File 'lib/fidgit/elements/container.rb', line 134

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

  recalc

  nil
end

#color_picker(options = {}, &block) ⇒ Object

Create a color picker within the container.



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

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

#color_well(options = {}, &block) ⇒ Object

Create a color well within the container.



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

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

#combo_box(options = {}, &block) ⇒ Object



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

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

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



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

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

#grid(options = {}, &block) ⇒ Object

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



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

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

#group(options = {}, &block) ⇒ Object



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

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

#hit_element(x, y) ⇒ Element?

Returns the element within this container that was hit,

Returns:

  • (Element, nil)

    The element hit, otherwise nil.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/fidgit/elements/container.rb', line 151

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

#horizontal(options = {}, &block) ⇒ Object

Pack elements within the block horizontally.



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

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

#insert(position, element) ⇒ Object



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

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

  recalc
  nil
end

#label(text, options = {}) ⇒ Object

Create a label within the container.



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

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

#list(options = {}, &block) ⇒ Object



88
89
90
# File 'lib/fidgit/elements/container.rb', line 88

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

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



110
111
112
# File 'lib/fidgit/elements/container.rb', line 110

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

#remove(element) ⇒ Object



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

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

  recalc
  nil
end

#scroll_area(options = {}, &block) ⇒ Object



114
115
116
# File 'lib/fidgit/elements/container.rb', line 114

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

#scroll_window(options = {}, &block) ⇒ Object



118
119
120
# File 'lib/fidgit/elements/container.rb', line 118

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

#slider(options = {}, &block) ⇒ Object



122
123
124
# File 'lib/fidgit/elements/container.rb', line 122

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

#text_area(options = {}, &block) ⇒ Object



126
127
128
# File 'lib/fidgit/elements/container.rb', line 126

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

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



130
131
132
# File 'lib/fidgit/elements/container.rb', line 130

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

#updateObject



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

def update
  each { |c| c.update }

  nil
end

#vertical(options = {}, &block) ⇒ Object

Pack elements within the blockvertically.



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

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

#x=(value) ⇒ Object



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

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

#y=(value) ⇒ Object



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

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