Class: RISlider
- Inherits:
-
Object
- Object
- RISlider
- Defined in:
- lib/RIUI/RISlider.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
writeonly
Sets the attribute actions.
-
#active ⇒ Object
Returns the value of attribute active.
-
#color ⇒ Object
Returns the value of attribute color.
-
#font ⇒ Object
Returns the value of attribute font.
-
#id ⇒ Object
Returns the value of attribute id.
-
#length ⇒ Object
Returns the value of attribute length.
-
#line_color ⇒ Object
Returns the value of attribute line_color.
-
#onchange ⇒ Object
Returns the value of attribute onchange.
-
#size ⇒ Object
Returns the value of attribute size.
-
#square ⇒ Object
Returns the value of attribute square.
-
#square_color ⇒ Object
Returns the value of attribute square_color.
-
#square_size ⇒ Object
Returns the value of attribute square_size.
-
#ticks ⇒ Object
Returns the value of attribute ticks.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(opts = [:length, :x, :y, :square_size, :ticks, :actions]) ⇒ RISlider
constructor
Initialize all variables and start functionality.
- #mouse_down_actions(x, y) ⇒ Object
- #mouse_move_actions(x, y) ⇒ Object
- #mouse_up_actions ⇒ Object
- #onChange(opts = [:onchange]) ⇒ Object
- #reset ⇒ Object
-
#setColors(opts = [:square_color, :line_color]) ⇒ Object
Sets the colors of the line and square.
-
#setLabel(opts = [:size, :font, :color]) ⇒ Object
Creates a label for the slider.
- #update_actions ⇒ Object
-
#value ⇒ Object
Returns slider’s value.
Constructor Details
#initialize(opts = [:length, :x, :y, :square_size, :ticks, :actions]) ⇒ RISlider
Initialize all variables and start functionality
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/RIUI/RISlider.rb', line 5 def initialize(opts = [:length, :x, :y, :square_size, :ticks, :actions]) ### Initialize all variables and start functionality extend Ruby2D::DSL @x = opts[:x] || 0 @y = opts[:y] || 0 @length = opts[:length] || 100 @square_size = opts[:square_size] || 10 @ticks = opts[:ticks] || 10 @label_font = opts[:label_font] || '' @label_size = opts[:label_size] || 20 @label_color = opts[:label_color] || 'black' @line_color = opts[:line_color] || 'black' @square_color = opts[:square_color] || 'red' @actions = opts[:actions] @value = 0 @line = Line.new(x1: @x, y1: @y, x2: @x + @length, y2: y, color: @line_color) self.square = Square.new(size: @square_size, x: x - (@square_size/2), y: y - (@square_size/2), color: @square_color) setState(active: false) #@actions.add(self) # start_update end |
Instance Attribute Details
#actions=(value) ⇒ Object
Sets the attribute actions
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def actions=(value) @actions = value end |
#active ⇒ Object
Returns the value of attribute active.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def active @active end |
#color ⇒ Object
Returns the value of attribute color.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def color @color end |
#font ⇒ Object
Returns the value of attribute font.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def font @font end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def id @id end |
#length ⇒ Object
Returns the value of attribute length.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def length @length end |
#line_color ⇒ Object
Returns the value of attribute line_color.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def line_color @line_color end |
#onchange ⇒ Object
Returns the value of attribute onchange.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def onchange @onchange end |
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def size @size end |
#square ⇒ Object
Returns the value of attribute square.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def square @square end |
#square_color ⇒ Object
Returns the value of attribute square_color.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def square_color @square_color end |
#square_size ⇒ Object
Returns the value of attribute square_size.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def square_size @square_size end |
#ticks ⇒ Object
Returns the value of attribute ticks.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def ticks @ticks end |
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/RIUI/RISlider.rb', line 3 def y @y end |
Instance Method Details
#mouse_down_actions(x, y) ⇒ Object
50 51 52 53 54 |
# File 'lib/RIUI/RISlider.rb', line 50 def mouse_down_actions(x, y) if self.square.contains?(x, y) setState(active: true) end end |
#mouse_move_actions(x, y) ⇒ Object
58 |
# File 'lib/RIUI/RISlider.rb', line 58 def mouse_move_actions(x, y); end |
#mouse_up_actions ⇒ Object
55 56 57 |
# File 'lib/RIUI/RISlider.rb', line 55 def mouse_up_actions setState(active: false) end |
#onChange(opts = [:onchange]) ⇒ Object
45 46 47 |
# File 'lib/RIUI/RISlider.rb', line 45 def onChange(opts = [:onchange]) @onChange = opts[:onchange] end |
#reset ⇒ Object
41 42 43 44 |
# File 'lib/RIUI/RISlider.rb', line 41 def reset self.square.x = @x - (@square_size/2) @value = 0 end |
#setColors(opts = [:square_color, :line_color]) ⇒ Object
Sets the colors of the line and square
26 27 28 29 30 31 32 |
# File 'lib/RIUI/RISlider.rb', line 26 def setColors(opts = [:square_color, :line_color]) ### Sets the colors of the line and square @line_color = opts[:line_color] @square_color = opts[:square_color] @line.color = @line_color self.square.color = @square_color puts 'colors set' end |
#setLabel(opts = [:size, :font, :color]) ⇒ Object
Creates a label for the slider
34 35 36 37 38 39 40 |
# File 'lib/RIUI/RISlider.rb', line 34 def setLabel(opts = [:size, :font, :color]) ### Creates a label for the slider @label_size = opts[:size] @label_font = opts[:font] @label_color = opts[:color] @label = Text.new(x: @x + @length + 15, y: @y, color: @label_color, font: @label_font, size: @label_size, text: '0') puts 'label set' end |
#update_actions ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/RIUI/RISlider.rb', line 59 def update_actions check update_label changed = check_for_change(@old_value, @value) if changed @onChange.call end end |
#value ⇒ Object
Returns slider’s value
48 |
# File 'lib/RIUI/RISlider.rb', line 48 def value; @value; end |