Class: Cura::Component::Scrollbar
- 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
-
#buttons ⇒ Object
readonly
Get the buttons for this scrollbar.
-
#max ⇒ Object
Get the maximum value of this scrollbar.
-
#min ⇒ Object
Get the minimum value of this scrollbar.
-
#percent ⇒ Object
readonly
Get the percentage of this scrollbar.
-
#value ⇒ Object
Get the value of this scrollbar.
Attributes included from Attributes::HasOrientation
Attributes included from Attributes::HasAncestry
Attributes included from Attributes::HasOffsets
Attributes included from Attributes::HasEvents
Instance Method Summary collapse
-
#decrement(value = 1) ⇒ Object
Decrement the value of this scrollbar by the given number.
-
#height=(value) ⇒ Object
Set the height of this scrollbar.
-
#increment(value = 1) ⇒ Object
Increment the value of this scrollbar by the given number.
-
#initialize(attributes = {}) ⇒ Scrollbar
constructor
A new instance of Scrollbar.
-
#orientation=(value) ⇒ Object
Set the orientation of this scrollbar.
-
#width=(value) ⇒ Object
Set the width of this scrollbar.
Methods included from Attributes::HasOrientation
Methods included from Attributes::HasAttributes
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
Methods included from Attributes::HasCoordinates
Methods included from Attributes::HasAncestry
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
Methods included from Attributes::HasEvents
Methods included from Attributes::HasDimensions
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_handle set_percentage set_handle_position end |
Instance Attribute Details
#buttons ⇒ Object (readonly)
Get the buttons for this scrollbar.
38 39 40 |
# File 'lib/cura/component/scrollbar.rb', line 38 def @buttons end |
#max ⇒ Object
Get the maximum value of this scrollbar.
88 89 90 |
# File 'lib/cura/component/scrollbar.rb', line 88 def max @max end |
#min ⇒ Object
Get the minimum value of this scrollbar.
78 79 80 |
# File 'lib/cura/component/scrollbar.rb', line 78 def min @min end |
#percent ⇒ Object (readonly)
Get the percentage of this scrollbar.
57 58 59 |
# File 'lib/cura/component/scrollbar.rb', line 57 def percent @percent end |
#value ⇒ Object
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.
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 end |
#increment(value = 1) ⇒ Object
Increment the value of this scrollbar by the given number.
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 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 end |