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.



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

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.



38
39
40
# File 'lib/cura/component/scrollbar.rb', line 38

def buttons
  @buttons
end

#maxObject

Get the maximum value of this scrollbar.



88
89
90
# File 'lib/cura/component/scrollbar.rb', line 88

def max
  @max
end

#minObject

Get the minimum value of this scrollbar.



78
79
80
# File 'lib/cura/component/scrollbar.rb', line 78

def min
  @min
end

#percentObject (readonly)

Get the percentage of this scrollbar.



57
58
59
# File 'lib/cura/component/scrollbar.rb', line 57

def percent
  @percent
end

#valueObject

Get the value of this scrollbar.



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

def value
  @value
end

Instance Method Details

#decrement(value = 1) ⇒ Object

Decrement the value of this scrollbar by the given number.

Raises:

  • (ArgumentError)


112
113
114
115
116
# File 'lib/cura/component/scrollbar.rb', line 112

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.



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

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)


105
106
107
108
109
# File 'lib/cura/component/scrollbar.rb', line 105

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.



98
99
100
101
102
# File 'lib/cura/component/scrollbar.rb', line 98

def orientation=(value)
  super

  set_button_labels_based_on_orientation
end

#width=(value) ⇒ Object

Set the width of this scrollbar.



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

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