Class: Cura::Component::Scrollbar

Inherits:
Group
  • Object
show all
Includes:
Attributes::HasOrientation
Defined in:
lib/cura/component/scrollbar.rb

Overview

A component for scrolling. TODO: Option to have buttons or not

Instance Attribute Summary collapse

Attributes included from Attributes::HasOrientation

#orientation

Attributes included from Attributes::HasAncestry

#parent

Attributes included from Attributes::HasOffsets

#offsets

Attributes included from Attributes::HasEvents

#event_handler

Instance Method Summary collapse

Methods included from Attributes::HasOrientation

#horizontal?, #vertical?

Methods included from Attributes::HasAttributes

included, #update_attributes

Methods inherited from Group

#add_child, #delete_child_at, #draw, #height, #update, #width

Methods included from Attributes::HasChildren

#add_child, #add_children, #children, #children?, #delete_child, #delete_child_at, #delete_children, #each

Methods inherited from Base

#application, #background, #contains_coordinates?, #cursor, #draw, #focus, #focused?, #foreground, #inspect, #pencil, #update

Methods included from Attributes::HasRelativeCoordinates

#absolute_x, #absolute_y

Methods included from Attributes::HasCoordinates

#x, #x=, #y, #y=

Methods included from Attributes::HasAncestry

#ancestors, #parent?

Methods included from Attributes::HasOffsets

#border, #border=, #margin, #margin=, #padding, #padding=

Methods included from Attributes::HasColors

#background, #background=, #foreground, #foreground=

Methods included from Attributes::HasFocusability

#focusable=, #focusable?

Methods included from Attributes::HasEvents

included, #on_event

Methods included from Attributes::HasDimensions

#height, #resize, #width

Constructor Details

#initialize(attributes = {}) ⇒ Scrollbar

Returns a new instance of Scrollbar.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cura/component/scrollbar.rb', line 16

def initialize(attributes={})
  @value = 0
  @min = 0
  @max = 100
  @orientation = :vertical
  @buttons = {}
  
  @buttons[:decrement] = Button.new(width: 1, height: 1) { parent.decrement }
  @buttons[:increment] = Button.new(width: 1, height: 1) { parent.increment }
  @handle = Component.new(width: 1, height: 1)
  
  super
  
  setup_value
  setup_buttons
  setup_handle
  
  set_button_labels_based_on_orientation
  set_button_coordinates_based_on_orientation
  set_percentage
  set_handle_position
end

Instance Attribute Details

#buttonsObject (readonly)

Get the buttons for this scrollbar.



40
41
42
# File 'lib/cura/component/scrollbar.rb', line 40

def buttons
  @buttons
end

#maxObject

Get the maximum value of this scrollbar.



90
91
92
# File 'lib/cura/component/scrollbar.rb', line 90

def max
  @max
end

#minObject

Get the minimum value of this scrollbar.



80
81
82
# File 'lib/cura/component/scrollbar.rb', line 80

def min
  @min
end

#percentObject (readonly)

Get the percentage of this scrollbar.



59
60
61
# File 'lib/cura/component/scrollbar.rb', line 59

def percent
  @percent
end

#valueObject

Get the value of this scrollbar.



43
44
45
# File 'lib/cura/component/scrollbar.rb', line 43

def value
  @value
end

Instance Method Details

#decrement(value = 1) ⇒ Object

Decrement the value of this scrollbar by the given number.

Raises:

  • (ArgumentError)


114
115
116
117
118
# File 'lib/cura/component/scrollbar.rb', line 114

def decrement(value=1)
  raise ArgumentError, "value must respond to :to_i" unless value.respond_to?(:to_i)
  
  self.value -= value.to_i
end

#height=(value) ⇒ Object

Set the height of this scrollbar.



71
72
73
74
75
76
77
# File 'lib/cura/component/scrollbar.rb', line 71

def height=(value)
  super
  
  # @height = 2 if @height == 0 # TODO: Depends on if buttons are shown or not AND orientation
  
  set_button_coordinates_based_on_orientation
end

#increment(value = 1) ⇒ Object

Increment the value of this scrollbar by the given number.

Raises:

  • (ArgumentError)


107
108
109
110
111
# File 'lib/cura/component/scrollbar.rb', line 107

def increment(value=1)
  raise ArgumentError, "value must respond to :to_i" unless value.respond_to?(:to_i)
  
  self.value += value.to_i
end

#orientation=(value) ⇒ Object

Set the orientation of this scrollbar.



100
101
102
103
104
# File 'lib/cura/component/scrollbar.rb', line 100

def orientation=(value)
  super
  
  set_button_labels_based_on_orientation
end

#width=(value) ⇒ Object

Set the width of this scrollbar.



62
63
64
65
66
67
68
# File 'lib/cura/component/scrollbar.rb', line 62

def width=(value)
  super
  
  # @width = 2 if @width == 0 # TODO: Depends on if buttons are shown or not AND orientation
  
  set_button_coordinates_based_on_orientation
end