lib/cyberarm_engine/ui/elements/slider.rb in cyberarm_engine-0.23.0 vs lib/cyberarm_engine/ui/elements/slider.rb in cyberarm_engine-0.24.0
- old
+ new
@@ -31,11 +31,12 @@
def draggable?(button)
button == :left
end
end
- attr_reader :range, :step_size, :value
+ attr_reader :step_size, :value
+ attr_accessor :range, :step_size
def initialize(options = {}, block = nil)
super(options, block)
@range = @options[:range] || (0.0..1.0)
@@ -74,21 +75,21 @@
end
def update
super
- @tip = value.to_s
+ @tip = format("%.2f", value.to_f)
@handle.tip = @tip
end
def holding_left_mouse_button(_sender, x, y)
handle_dragged_to(x, y)
:handled
end
def handle_dragged_to(x, _y)
- @ratio = ((x - @handle.width / 2) - @x) / (content_width - @handle.outer_width)
+ @ratio = ((x - @handle.width / 2.0) - @x) / (content_width - @handle.outer_width.to_f)
self.value = @ratio.clamp(0.0, 1.0) * (@range.max - @range.min) + @range.min
end
def value=(n)