Class: Shoes::Slot

Inherits:
Common::UIElement show all
Includes:
Common::Clickable, Common::Hover
Defined in:
shoes-core/lib/shoes/slot.rb

Direct Known Subclasses

Flow, Stack

Defined Under Namespace

Classes: Position

Constant Summary collapse

NEXT_ELEMENT_OFFSET =

We need that offset because otherwise element overlap e.g. occupy the same pixel - this way they start right next to each other See #update_current_position

1
STYLES =
{ scroll: false, fill: Shoes::COLORS[:black] }.freeze

Constants included from Common::Style

Common::Style::DEFAULT_STYLES, Common::Style::STYLE_GROUPS

Instance Attribute Summary collapse

Attributes included from Common::Hover

#hover_blk, #leave_blk

Attributes included from Common::Clickable

#pass_coordinates

Instance Method Summary collapse

Methods included from Common::Hover

#apply_style_from_hover_class, #apply_style_from_pre_hover, create_hover_class, #eval_hover_block, #hover, #hover_class, #hovered?, #leave, #mouse_hovered, #mouse_left

Methods included from Common::Clickable

#click, #pass_coordinates?, #register_click, #release

Methods inherited from Common::UIElement

#add_to_parent, #after_initialize, #create_backend, #initialize, #needs_rotate?, #painted?, #redraw_height, #redraw_left, #redraw_top, #redraw_width, #update_fill, #update_stroke

Methods included from Common::Style

#applicable_app_styles, #create_style_hash, included, #style, #style_init

Methods included from Common::SafelyEvaluate

#safely_evaluate

Methods included from Common::Positioning

#_position, #displace, #move

Methods included from Common::Visibility

#hidden?, #hidden_from_view?, #hide, #outside_parent_view?, #show, #toggle, #visible?

Methods included from Common::Inspect

#to_s

Methods included from Common::Attachable

#attached_to

Constructor Details

This class inherits a constructor from Shoes::Common::UIElement

Instance Attribute Details

#blkObject (readonly)

Returns the value of attribute blk.



13
14
15
# File 'shoes-core/lib/shoes/slot.rb', line 13

def blk
  @blk
end

#contentsObject (readonly)

Returns the value of attribute contents.



13
14
15
# File 'shoes-core/lib/shoes/slot.rb', line 13

def contents
  @contents
end

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



13
14
15
# File 'shoes-core/lib/shoes/slot.rb', line 13

def dimensions
  @dimensions
end

#guiObject (readonly)

Returns the value of attribute gui.



13
14
15
# File 'shoes-core/lib/shoes/slot.rb', line 13

def gui
  @gui
end

#parentObject (readonly)

Returns the value of attribute parent.



13
14
15
# File 'shoes-core/lib/shoes/slot.rb', line 13

def parent
  @parent
end

#scroll_heightObject

Returns the value of attribute scroll_height.



16
17
18
# File 'shoes-core/lib/shoes/slot.rb', line 16

def scroll_height
  @scroll_height
end

#scroll_topObject

Returns the value of attribute scroll_top.



15
16
17
# File 'shoes-core/lib/shoes/slot.rb', line 15

def scroll_top
  @scroll_top
end

Instance Method Details

#add_child(element) ⇒ Object



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

def add_child(element)
  contents.add_element element

  return if element.hidden? || !element.takes_up_space?

  # Prepending would entail repositioning everyone after us, so just give
  # it up and let contents_alignment save us the work.
  if contents.prepending?
    contents_alignment
  else
    original_height = self.height
    @current_position = positioning(element, @current_position)

    height_delta = slot_grew_by(original_height)
    bump_parent_current_position(height_delta)
  end
end

#add_mouse_hover_controlObject



149
150
151
# File 'shoes-core/lib/shoes/slot.rb', line 149

def add_mouse_hover_control
  @app.add_mouse_hover_control(self)
end

#any_sibling_slots_following?(growing_slot) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
124
125
# File 'shoes-core/lib/shoes/slot.rb', line 121

def any_sibling_slots_following?(growing_slot)
  next_sibling  = contents.index(growing_slot) + 1
  next_siblings = contents[next_sibling..-1]
  next_siblings.any? { |e| e.is_a?(Slot) }
end

#appObject



170
171
172
# File 'shoes-core/lib/shoes/slot.rb', line 170

def app
  @app.app # return the Shoes::App not the internal app
end

#append(&blk) ⇒ Object



131
132
133
# File 'shoes-core/lib/shoes/slot.rb', line 131

def append(&blk)
  eval_block blk
end

#before_initialize(*_) ⇒ Object



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

def before_initialize(*_)
  @contents = SlotContents.new
  @last_hidden_state = nil
end

#bump_current_position(growing_slot, height_delta) ⇒ Object

This method gets called when one of our child slots got larger, so we need to move our current position to accomodate.



111
112
113
114
115
116
117
118
119
# File 'shoes-core/lib/shoes/slot.rb', line 111

def bump_current_position(growing_slot, height_delta)
  # If intermediate child changed, give up and hit it with the big hammer
  if any_sibling_slots_following?(growing_slot)
    contents_alignment
  else
    @current_position.y += height_delta
    @current_position.next_line_start += height_delta
  end
end

#bump_parent_current_position(height_delta) ⇒ Object



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

def bump_parent_current_position(height_delta)
  return unless height_delta.positive?
  return unless parent.respond_to?(:bump_current_position)

  parent.bump_current_position(self, height_delta)
end

#clear(&blk) ⇒ Object



54
55
56
57
58
# File 'shoes-core/lib/shoes/slot.rb', line 54

def clear(&blk)
  contents.clear
  eval_block blk
  self
end

#contents_alignment(_ = nil) ⇒ Object



141
142
143
144
145
146
147
# File 'shoes-core/lib/shoes/slot.rb', line 141

def contents_alignment(_ = nil)
  position_contents
  update_child_visibility

  # Layout code expects height returned!
  determine_slot_height
end

#create_bound_block(blk) ⇒ Object



73
74
75
76
77
# File 'shoes-core/lib/shoes/slot.rb', line 73

def create_bound_block(blk)
  proc do |*args|
    eval_block(blk, *args)
  end
end

#create_dimensions(*args) ⇒ Object



21
22
23
24
25
26
27
28
# File 'shoes-core/lib/shoes/slot.rb', line 21

def create_dimensions(*args)
  super(*args)

  @fixed_height = !height.nil?
  @scroll_top   = 0
  set_default_dimension_values
  @pass_coordinates = true
end

#eval_block(blk, *args) ⇒ Object



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

def eval_block(blk, *args)
  old_current_slot = @app.current_slot
  @app.current_slot = self
  safely_evaluate(*args, &blk)
  @app.current_slot = old_current_slot
end

#fixed_height?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'shoes-core/lib/shoes/slot.rb', line 178

def fixed_height?
  @fixed_height
end

#handle_block(blk) ⇒ Object



35
36
37
38
39
40
# File 'shoes-core/lib/shoes/slot.rb', line 35

def handle_block(blk)
  snapshot_current_position

  @blk = blk
  eval_block blk
end

#inspectObject



174
175
176
# File 'shoes-core/lib/shoes/slot.rb', line 174

def inspect
  "#<#{self.class}:0x#{hash.to_s(16)} @contents=#{@contents.inspect} and so much stuff literally breaks the memory limit. Look at it selectively.>"
end

#prepend(&blk) ⇒ Object



135
136
137
138
139
# File 'shoes-core/lib/shoes/slot.rb', line 135

def prepend(&blk)
  contents.prepend do
    eval_block blk
  end
end

#removeObject



60
61
62
63
64
# File 'shoes-core/lib/shoes/slot.rb', line 60

def remove
  clear
  super
  self
end

#remove_child(element) ⇒ Object



127
128
129
# File 'shoes-core/lib/shoes/slot.rb', line 127

def remove_child(element)
  contents.delete element
end

#scroll_maxObject



163
164
165
166
167
168
# File 'shoes-core/lib/shoes/slot.rb', line 163

def scroll_max
  contents_alignment
  return 0 unless scroll_height && height

  [scroll_height - height, 0].max
end

#set_default_dimension_valuesObject



47
48
49
50
51
52
# File 'shoes-core/lib/shoes/slot.rb', line 47

def set_default_dimension_values
  self.width          ||= 1.0
  self.height         ||= 0
  self.absolute_left  ||= 0
  self.absolute_top   ||= 0
end

#slot_grew_by(original_height) ⇒ Object



97
98
99
100
# File 'shoes-core/lib/shoes/slot.rb', line 97

def slot_grew_by(original_height)
  determine_slot_height
  self.height - original_height
end

#snapshot_current_positionObject



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

def snapshot_current_position
  top = element_top - scroll_offset
  @current_position = Position.new element_left, top, top
end

#variable_height?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'shoes-core/lib/shoes/slot.rb', line 182

def variable_height?
  !@fixed_height
end