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

#hover_proc, #hovered, #leave_proc, #margin_bottom, #margin_left, #margin_right, #margin_top

Instance Method Summary collapse

Methods included from Mod

#click, #hided, #hover, #leave, #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
28
29
30
31
32
33
34
35
36
37
# 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?
    if args[:hidden]
      @hided = true
      BASIC_ATTRIBUTES_DEFAULT.merge! hidden: true
      SLOT_ATTRIBUTES_DEFAULT.merge! hidden: true
      @hidden_flag = true unless @parent.instance_variable_get '@hidden'
    end
    yield
    if @hidden_flag
      BASIC_ATTRIBUTES_DEFAULT.delete :hidden
      SLOT_ATTRIBUTES_DEFAULT.delete :hidden
    end
    @app.cslot = @parent
  else
    @left = @top = 0
  end
end

Instance Attribute Details

#app(&blk) ⇒ Object



43
44
45
# File 'lib/shoes/slot.rb', line 43

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

#contentsObject

Returns the value of attribute contents.



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

def contents
  @contents
end

#initialsObject (readonly)

Returns the value of attribute initials.



40
41
42
# File 'lib/shoes/slot.rb', line 40

def initials
  @initials
end

#lnObject

Returns the value of attribute ln.



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

def ln
  @ln
end

#parentObject (readonly)

Returns the value of attribute parent.



40
41
42
# File 'lib/shoes/slot.rb', line 40

def parent
  @parent
end

Instance Method Details

#after(e, &blk) ⇒ Object



113
114
115
116
117
# File 'lib/shoes/slot.rb', line 113

def after e, &blk
  n = contents.index e
  n = n ? n+1 : contents.length
  prepend n, &blk
end

#append(&blk) ⇒ Object



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

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

#before(e, &blk) ⇒ Object



109
110
111
# File 'lib/shoes/slot.rb', line 109

def before e, &blk
  prepend contents.index(e).to_i, &blk
end

#clear(&blk) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/shoes/slot.rb', line 77

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}
  elsif !@app.cs.isDisposed
    @app.cs.removeListener Swt::SWT::MouseDown, ln if ln
    @app.cs.removeListener Swt::SWT::MouseUp, ln if ln
    @app.mscs -= [self]
    @app.mhcs -= [self]
  end
  @app.flush
end

#fix_sizeObject



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

def fix_size; end

#hideObject



124
125
126
127
# File 'lib/shoes/slot.rb', line 124

def hide
  @hided = false
  toggle
end

#move3(x, y) ⇒ Object



47
48
49
# File 'lib/shoes/slot.rb', line 47

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

#positioning(x, y, max) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/shoes/slot.rb', line 51

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



100
101
102
103
104
105
106
107
# File 'lib/shoes/slot.rb', line 100

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
  @app.aflush
end

#showObject



119
120
121
122
# File 'lib/shoes/slot.rb', line 119

def show
  @hided = true
  toggle
end

#style(args = nil) ⇒ Object



55
56
57
58
# File 'lib/shoes/style.rb', line 55

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

#toggleObject



129
130
131
132
133
134
135
136
137
# File 'lib/shoes/slot.rb', line 129

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