Class: Shoes::Slot

Inherits:
Object show all
Includes:
Mod
Defined in:
lib/shoes/slot.rb,
lib/shoes/style.rb

Direct Known Subclasses

Flow, Stack

Instance Attribute Summary collapse

Attributes included from Mod

#margin_bottom, #margin_left, #margin_right, #margin_top

Instance Method Summary collapse

Methods included from Mod

#click, #release, #set_margin

Constructor Details

#initialize(args = {}) ⇒ Slot

Returns a new instance of Slot.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/shoes/slot.rb', line 4

def initialize args={}
  @initials = args
  args.each do |k, v|
    instance_variable_set "@#{k}", v
  end
  
  Slot.class_eval do
    attr_accessor *(args.keys - [:app])
  end

  set_margin

  @parent = @app.cslot
  @app.cslot = self
  @contents = []
  (@parent.contents << self) unless @nocontrol

  if block_given?
    yield
    @app.cslot = @parent
  else
    @left = @top = 0
  end
end

Instance Attribute Details

#app(&blk) ⇒ Object



33
34
35
# File 'lib/shoes/slot.rb', line 33

def app &blk
  blk ? @app.instance_eval(&blk) : @app
end

#contentsObject

Returns the value of attribute contents.



29
30
31
# File 'lib/shoes/slot.rb', line 29

def contents
  @contents
end

#initialsObject (readonly)

Returns the value of attribute initials.



30
31
32
# File 'lib/shoes/slot.rb', line 30

def initials
  @initials
end

#parentObject (readonly)

Returns the value of attribute parent.



30
31
32
# File 'lib/shoes/slot.rb', line 30

def parent
  @parent
end

Instance Method Details

#append(&blk) ⇒ Object



81
82
83
# File 'lib/shoes/slot.rb', line 81

def append &blk
  prepend contents.length, &blk
end

#clear(&blk) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/shoes/slot.rb', line 67

def clear &blk
  @contents.each &:clear
  @contents.clear
  if blk
    args = {}
    initials.keys.each{|k| args[k] = instance_variable_get "@#{k}"}
    args[:nocontrol] = true
    tmp = self.is_a?(Stack) ? Stack.new(@app.slot_attributes(args), &blk) : Flow.new(@app.slot_attributes(args), &blk)
    self.contents = tmp.contents
    contents.each{|e| e.parent = self if e.is_a? Basic}
  end
  @app.flush
end

#fix_sizeObject



65
# File 'lib/shoes/slot.rb', line 65

def fix_size; end

#hideObject



99
100
101
102
# File 'lib/shoes/slot.rb', line 99

def hide
  @hided = false
  toggle
end

#move3(x, y) ⇒ Object



37
38
39
# File 'lib/shoes/slot.rb', line 37

def move3 x, y
  @left, @top = x, y
end

#positioning(x, y, max) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/shoes/slot.rb', line 41

def positioning x, y, max
  w = (parent.width * @initials[:width]).to_i if @initials[:width].is_a? Float
  w = (parent.width + @initials[:width]) if @initials[:width] < 0
  @width = w - (margin_left + margin_right) if w
  if parent.is_a?(Flow) and x + @width <= parent.left + parent.width
    move3 x + parent.margin_left, max.top + parent.margin_top
    @height = Shoes.contents_alignment self
    max = self if max.height < @height
  else
    move3 parent.left + parent.margin_left, max.top + max.height + parent.margin_top
    @height = Shoes.contents_alignment self
    max = self
  end
  case @initials[:height]
  when 0
  when Float
    max.height = @height = (parent.height * @initials[:height]).to_i
  else
    max.height = @height = @initials[:height]
  end
  contents.each &:fix_size
  max
end

#prepend(n = 0) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/shoes/slot.rb', line 85

def prepend n = 0
  self.contents, tmp = contents[0...n], contents[n..-1]
  cslot, @app.cslot = @app.cslot, self
  yield
  self.contents += tmp
  @app.cslot = cslot
  Shoes.call_back_procs @app
end

#showObject



94
95
96
97
# File 'lib/shoes/slot.rb', line 94

def show
  @hided = true
  toggle
end

#style(args = nil) ⇒ Object



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

def style args = nil
  args ? [:width, :height].each{|s| @initials[s] = args[s] if args[s]} :
    {width: @width, height: @height}
end

#toggleObject



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

def toggle
  @hided = !@hided
  if @hided
    @contents.each &:hide
  else
    @contents.each &:show
  end
  self
end