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
# 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
  @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



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

def args
  @args
end

#hidedObject

Returns the value of attribute hided



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

def hided
  @hided
end

#initialsObject (readonly)

Returns the value of attribute initials



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

def initials
  @initials
end

#parentObject

Returns the value of attribute parent



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

def parent
  @parent
end

#showsObject (readonly)

Returns the value of attribute shows



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

def shows
  @shows
end

Instance Method Details

#clearObject Also known as: clear_all



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

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

#fix_sizeObject



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

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



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

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

#move(x, y) ⇒ Object



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

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



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

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

#move3(x, y) ⇒ Object



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

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

#positioning(x, y, max) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/shoes/basic.rb', line 102

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



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

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

#showObject



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

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

#style(args = nil) ⇒ Object



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

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



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

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