Class: Shoes::Basic

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

Direct Known Subclasses

Image, Native, Pattern, ShapeBase, TextBlock

Instance Attribute Summary collapse

Attributes included from Mod

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

Instance Method Summary collapse

Methods included from Mod

#click, #hover, #leave, #release, #set_margin

Constructor Details

#initialize(args) ⇒ Basic

Returns a new instance of Basic.



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
38
# File 'lib/shoes/basic.rb', line 4

def initialize args
  @initials = args
  args.each do |k, v|
    instance_variable_set "@#{k}", v
  end

  (@app.order << self) unless @noorder or self.is_a?(EditBox) or self.is_a?(EditLine)
  (@app.cslot.contents << self) unless @nocontrol or @app.cmask
  (@app.cmask.contents << self) if @app.cmask
  if self.is_a? Native
    @app.focusables << self
    self.state = args[:state] if args[:state]
    args.delete :state
  end
  @parent = @app.cslot
  
  Basic.class_eval do
    attr_accessor *args.keys
  end

  (@width, @height = @real.size_request) if @real and !self.is_a?(TextBlock)

  set_margin
  @width += (@margin_left + @margin_right)
  @height += (@margin_top + @margin_bottom)

  @proc = nil
  [:app, :real].each{|k| args.delete k}
  @args = args
  @hovered = false
  @cleared = false
  @hidden ? (@hided, @shows = true, false) : (@hided, @shows = false, true)
  @app.fronts.push self if @front
  @app.backs.push self if @back
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#clearedObject (readonly)

Returns the value of attribute cleared.



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

def cleared
  @cleared
end

#hidedObject

Returns the value of attribute hided.



41
42
43
# File 'lib/shoes/basic.rb', line 41

def hided
  @hided
end

#initialsObject (readonly)

Returns the value of attribute initials.



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

def initials
  @initials
end

#parentObject

Returns the value of attribute parent.



41
42
43
# File 'lib/shoes/basic.rb', line 41

def parent
  @parent
end

#showsObject (readonly)

Returns the value of attribute shows.



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

def shows
  @shows
end

Instance Method Details

#clear(flag = true) ⇒ Object Also known as: clear_all



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/shoes/basic.rb', line 89

def clear flag = true
  @app.delete_mouse_events self
  @cleared = true if flag
  case self
    when Button, EditLine, EditBox, ListBox
      @app.cslot.contents.delete self
      @app.focusables.delete self
      remove
      @real = nil
    else
      @real.clear if @real
  end
end

#fix_sizeObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/shoes/basic.rb', line 116

def fix_size
  flag = false
  set_margin
  case self
  when EditBox, Button
    if 0 < @initials[:width] and @initials[:width] <= 1.0
      @width = @parent.width * @initials[:width] - @margin_left - @margin_right
      flag = true
    end
    if 0 < @initials[:height] and @initials[:height] <= 1.0
      @height = @parent.height * @initials[:height] - @margin_top - @margin_bottom
      flag = true
    end
  when EditLine, ListBox
    if 0 < @initials[:width] and @initials[:width] <= 1.0
      @width = @parent.width * @initials[:width] - @margin_left - @margin_right
      @height = 26
      flag = true
    end
  else
  end
  if flag
    @real.set_size_request @width, @height
    move @left, @top
  end
end

#hideObject



67
68
69
70
71
72
# File 'lib/shoes/basic.rb', line 67

def hide
  @app.shcs.delete self
  @app.shcs << self
  @shows = false
  self
end

#move(x, y) ⇒ Object



43
44
45
46
47
48
# File 'lib/shoes/basic.rb', line 43

def move x, y
  @app.cslot.contents -= [self]
  @app.canvas.move @real, x, y unless @hided
  move3 x, y
  self
end

#move2(x, y) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/shoes/basic.rb', line 50

def move2 x, y
  unless @hided
    remove
    @app.canvas.put @real, x, y
  end
  move3 x, y
end

#move3(x, y) ⇒ Object



58
59
60
# File 'lib/shoes/basic.rb', line 58

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

#positioning(x, y, max) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/shoes/basic.rb', line 105

def positioning x, y, max
  if parent.is_a?(Flow) and x + @width <= parent.left + parent.width
    move3 x + parent.margin_left, max.top + parent.margin_top
    max = self if max.height < @height
  else
    move3 parent.left + parent.margin_left, max.top + max.height + parent.margin_top
    max = self
  end
  max
end

#removeObject



62
63
64
65
# File 'lib/shoes/basic.rb', line 62

def remove
  @app.canvas.remove @real unless @hided
  @hided = true if self.is_a?(ShapeBase)
end

#showObject



74
75
76
77
78
79
80
# File 'lib/shoes/basic.rb', line 74

def show
  @app.shcs.delete self
  @app.shcs << self
  @shows = true
  @args.delete :hidden
  self
end

#style(args = nil) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/shoes/style.rb', line 73

def style args = nil
  return {width: @width, height: @height} unless args
  args[:width] ||= @width
  args[:height] ||= @height
  case self
    when Button, EditBox, EditLine, ListBox
      real.set_size_request args[:width], args[:height]
      @height = args[:height]
    when Progress
      real.text = ' ' * (args[:width] / 4 - 2)
    else
  end
  @width = args[:width]
end

#toggleObject



82
83
84
85
86
87
# File 'lib/shoes/basic.rb', line 82

def toggle
  @app.shcs.delete self
  @app.shcs << self
  @shows = !@shows
  self
end