Class: MittensUi::Slider
Overview
A horizontal slider widget for selecting values from a range.
The ‘Slider` class allows users to select a value within a specified range by dragging a handle along a horizontal track. It emits a signal when the value changes, enabling callbacks to be executed.
Instance Attribute Summary
Attributes inherited from Core
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Slider
constructor
Initializes a new Slider widget.
-
#move {|value| ... } ⇒ void
(also: #slide)
Registers a callback to be executed when the slider value changes.
Methods inherited from Core
#hidden?, #hide, #keyboard_shortcut, #remove, #remove_keyboard_shortcut, #render, #shortcuts, #show
Methods included from Helpers
#icon_map, #list_system_icons, #set_margin_from_opts_for
Constructor Details
#initialize(options = {}) ⇒ Slider
Initializes a new Slider widget.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mittens_ui/slider.rb', line 26 def initialize( = {}) start_value = .fetch(:start_value, 1.0) stop_value = .fetch(:stop_value, 10.0) step_value = .fetch(:step_value, 1.0) init_value = .fetch(:initial_value, 1.0) adjustment = Gtk::Adjustment.new( init_value, start_value, stop_value, step_value, step_value, 0 ) @scale = Gtk::Scale.new(:horizontal, adjustment) @scale.set_digits(0) @scale.set_draw_value(true) super(@scale, ) end |
Instance Method Details
#move {|value| ... } ⇒ void Also known as: slide
This method returns an undefined value.
Registers a callback to be executed when the slider value changes.
The block will be called with the new slider value as its argument.
60 61 62 63 64 |
# File 'lib/mittens_ui/slider.rb', line 60 def move @scale.signal_connect('value_changed') do || yield(.value) end end |