Class: Hokusai::Util::ClampingIterator

Inherits:
Object
  • Object
show all
Defined in:
ui/src/hokusai/util/clamping_iterator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clamping, x, y) ⇒ ClampingIterator

Returns a new instance of ClampingIterator.



135
136
137
138
139
140
141
142
143
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 135

def initialize(clamping, x, y)
  @clamping = clamping
  @x = x
  @y = y
  @height = 0
  @cursor_offset = 0
  @cursor_set = false
  @i = 0
end

Instance Attribute Details

#clampingObject (readonly)

Returns the value of attribute clamping.



127
128
129
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 127

def clamping
  @clamping
end

#cursor_offsetObject

Returns the value of attribute cursor_offset.



132
133
134
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 132

def cursor_offset
  @cursor_offset
end

#cursor_positionObject

Returns the value of attribute cursor_position.



132
133
134
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 132

def cursor_position
  @cursor_position
end

#cursor_setObject

Returns the value of attribute cursor_set.



132
133
134
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 132

def cursor_set
  @cursor_set
end

#heightObject

Returns the value of attribute height.



132
133
134
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 132

def height
  @height
end

#on_char_cbObject (readonly)

Returns the value of attribute on_char_cb.



127
128
129
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 127

def on_char_cb
  @on_char_cb
end

#on_cursor_change_cbObject (readonly)

Returns the value of attribute on_cursor_change_cb.



127
128
129
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 127

def on_cursor_change_cb
  @on_cursor_change_cb
end

#on_draw_cbObject (readonly)

Returns the value of attribute on_draw_cb.



127
128
129
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 127

def on_draw_cb
  @on_draw_cb
end

#on_draw_selection_cbObject (readonly)

Returns the value of attribute on_draw_selection_cb.



127
128
129
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 127

def on_draw_selection_cb
  @on_draw_selection_cb
end

#on_selection_change_cbObject (readonly)

Returns the value of attribute on_selection_change_cb.



127
128
129
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 127

def on_selection_change_cb
  @on_selection_change_cb
end

#producedObject

Returns the value of attribute produced.



132
133
134
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 132

def produced
  @produced
end

#segmentsObject (readonly)

Returns the value of attribute segments.



127
128
129
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 127

def segments
  @segments
end

#start_selectObject

Returns the value of attribute start_select.



132
133
134
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 132

def start_select
  @start_select
end

#stop_selectObject

Returns the value of attribute stop_select.



132
133
134
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 132

def stop_select
  @stop_select
end

#xObject

Returns the value of attribute x.



132
133
134
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 132

def x
  @x
end

#yObject

Returns the value of attribute y.



132
133
134
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 132

def y
  @y
end

Instance Method Details

#cursor_xObject



177
178
179
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 177

def cursor_x
  x
end

#cursor_yObject



173
174
175
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 173

def cursor_y
  y
end

#debugObject



149
150
151
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 149

def debug
  clamping.debug
end

#nextObject



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 157

def next
  if @i < segments.size
    SegmentRenderer.new(segments[@i], self)
  else
    if position = cursor_position
      on_cursor_change_cb&.call(position)
    end

    if start = start_select
      on_selection_change_cb&.call(start, stop_select)
    end
  end
ensure
  @i += 1
end

#on_char(&block) ⇒ Object



197
198
199
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 197

def on_char(&block)
  @on_char_cb = block
end

#on_cursor_change(&block) ⇒ Object



193
194
195
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 193

def on_cursor_change(&block)
  @on_cursor_change_cb = block
end

#on_draw(&block) ⇒ Object



181
182
183
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 181

def on_draw(&block)
  @on_draw_cb = block
end

#on_draw_selection(&block) ⇒ Object



185
186
187
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 185

def on_draw_selection(&block)
  @on_draw_selection_cb = block
end

#on_selection_change(&block) ⇒ Object



189
190
191
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 189

def on_selection_change(&block)
  @on_selection_change_cb = block
end

#resetObject



145
146
147
# File 'ui/src/hokusai/util/clamping_iterator.rb', line 145

def reset
  @i = 0
end