Class: GlimR::HScrollKnob

Inherits:
EmptyButton show all
Defined in:
lib/glimr/widgets/scrollbar.rb

Constant Summary

Constants included from Layoutable

Layoutable::DIMENSIONS

Instance Attribute Summary

Attributes inherited from EmptyButton

#background, #cover, #down, #down_background, #down_cover, #hover_indicator, #label, #up_background, #up_cover

Attributes inherited from Widget

#focused, #hover

Attributes included from Layoutable

#align, #valign

Attributes inherited from Model

#geometry, #material, #shader, #texture, #transform

Attributes inherited from SceneObject

#children, #drawables, #mtime, #parent, #viewport

Attributes included from EventListener

#event_listeners, #listener_count

Instance Method Summary collapse

Methods inherited from EmptyButton

#button_down, #button_up, #focus_indicator=, #focused=, #key_down, #key_up, #label_model=, #load_image, load_image, #mouse_out, #mouse_over, #mouse_up

Methods inherited from Widget

#activate, #blur, #click, #focus, for, #key_down, #key_up, #lock, #mouse_out, #mouse_over, #mouse_up, #unlock

Methods included from Layoutable

#attach, #children_change, #constant_size?, #detach, #expand!, #expand?, #expand_height, #expand_to_max_height!, #expand_to_max_width!, #expand_width, #fit_height!, #fit_to_children!, #fit_width!, #free_height, #free_width, #full_depth, #full_height, #full_width, #inner_depth, #inner_height, #inner_width, #inspect, #layoutable_children, #margin, #margin=, #max_height=, #max_width=, #min_height=, #min_width=, #padding, #padding=, #parent=, #size_changing, size_changing_accessor, #tell_children_of_size_change, #x=, #y=

Methods inherited from Model

#absolute_transform, #apply, #inspect, #pop_state, #push_state

Methods inherited from SceneObject

#<<, #absolute_geometry, #absolute_material, #absolute_shader, #absolute_texture, #absolute_transform, #absolute_transform_for_drawing, #add_drawables, #apply, #attach, #clone, #detach, #detach_self, #inspect, #pop_state, #push_state, #remove_drawables, #render, #replace_node, #root, #touch!, #visible

Methods included from EventListener

#add_event_listener, #decrement_listener_count, #dispatch_event, #event_root, #increment_listener_count, #method_missing, #multicast_event, #process_event, #remove_event_listener

Constructor Details

#initialize(*a, &b) ⇒ HScrollKnob

Returns a new instance of HScrollKnob.



283
284
285
286
# File 'lib/glimr/widgets/scrollbar.rb', line 283

def initialize(*a,&b)
  super
  on_scroll(:scroll_handler)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GlimR::EventListener

Instance Method Details

#containerObject



288
289
290
291
292
# File 'lib/glimr/widgets/scrollbar.rb', line 288

def container
  parent.parent.container
rescue NoMethodError
  nil
end

#default_configObject



273
274
275
276
277
278
279
280
281
# File 'lib/glimr/widgets/scrollbar.rb', line 273

def default_config
  super.merge(
    :up_background => "scroll_hknob_up.png",
    :down_background => "scroll_hknob_down.png",
    :up_cover => nil, :down_cover => nil, :focus_indicator => nil,
    :label => nil,
    :padding => 0, :rel_x => 0
  )
end

#layoutObject



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/glimr/widgets/scrollbar.rb', line 294

def layout
  return if @layouting
  @layouting = true
  if container
    self.width = [parent.inner_width.to_i,
      [
      (self.min_width || 0.0).to_i,
      (container.content.width > 0 ? ((container.width / container.content.width.to_f)*parent.inner_width) : 0).to_i
      ].max
    ].min.to_i
    @background_model.width = @width if @background_model
    parent.parent.scroll_x = parent.parent.scroll_x
  end
  @layouting = false
end

#mouse_down(o, e) ⇒ Object



310
311
312
313
# File 'lib/glimr/widgets/scrollbar.rb', line 310

def mouse_down(o,e)
  super
  @rel_x = e.rx
end

#mouse_move(o, e) ⇒ Object



315
316
317
318
319
320
# File 'lib/glimr/widgets/scrollbar.rb', line 315

def mouse_move(o,e)
  if @down and e.buttons[:left]
    self.new_x += e.dx
    @rel_x += e.dx
  end
end

#new_xObject



322
323
324
# File 'lib/glimr/widgets/scrollbar.rb', line 322

def new_x
  @new_x || self.x
end

#new_x=(nx) ⇒ Object



326
327
328
329
# File 'lib/glimr/widgets/scrollbar.rb', line 326

def new_x=(nx)
  on_frame(:update_scroll) unless @new_x
  @new_x = [scroll_max, [0, nx].max].min
end

#scroll_handler(*a) ⇒ Object



336
337
338
# File 'lib/glimr/widgets/scrollbar.rb', line 336

def scroll_handler(*a)
  self.x = parent.parent.scroll_x * scroll_max
end

#scroll_maxObject

The highest value the scroll knob can have. (Lowest is 0.)



332
333
334
# File 'lib/glimr/widgets/scrollbar.rb', line 332

def scroll_max
  parent.inner_width - self.full_width
end

#update_scroll(o, e) ⇒ Object



340
341
342
343
344
345
# File 'lib/glimr/widgets/scrollbar.rb', line 340

def update_scroll(o,e)
  new_scroll = (scroll_max > 0 ? (@new_x.to_f / scroll_max) : (@rel_x.to_f / parent.inner_width))
  parent.parent.scroll_x = new_scroll
  @new_x = nil
  remove_event_listener(:frame, :update_scroll)
end