Class: Fidgit::Slider
- Defined in:
- lib/fidgit/elements/slider.rb
Defined Under Namespace
Classes: Handle
Constant Summary
Constants inherited from Composite
Constants inherited from Element
Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Packer
Attributes inherited from Element
#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #z
Instance Method Summary collapse
- #handle_dragged_to(x, y) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Slider
constructor
A new instance of Slider.
- #left_mouse_button(sender, x, y) ⇒ Object
- #tip ⇒ Object
Methods inherited from Container
#add, #button, #clear, #color_picker, #color_well, #combo_box, #file_browser, #grid, #group, #hit_element, #horizontal, #image_frame, #insert, #label, #list, #radio_button, #remove, #scroll_area, #scroll_window, #slider, #text_area, #to_s, #toggle_button, #update, #vertical, #write_tree, #x=, #y=
Methods inherited from Element
#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #to_s, #update, #width, #width=, #with, #x, #x=, #y, #y=
Methods included from Event
#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe
Constructor Details
#initialize(options = {}, &block) ⇒ Slider
Returns a new instance of Slider.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fidgit/elements/slider.rb', line 54 def initialize( = {}, &block) = { range: 0.0..1.0, height: 25, background_color: default(:background_color), border_color: default(:border_color), groove_color: default(:groove_color), handle_color: default(:handle_color), groove_thickness: 5, }.merge! @range = [:range].dup @groove_color = [:groove_color].dup @groove_thickness = [:groove_thickness] @continuous = @range.min.is_a?(Float) || @range.max.is_a?(Float) super() @handle = Handle.new(parent: self, width: (height / 2 - padding_left), height: height - padding_top + padding_bottom, background_color: [:handle_color]) self.value = .has_key?(:value) ? [:value] : @range.min end |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
47 48 49 |
# File 'lib/fidgit/elements/slider.rb', line 47 def handle @handle end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
47 48 49 |
# File 'lib/fidgit/elements/slider.rb', line 47 def range @range end |
#value ⇒ Object
Returns the value of attribute value.
47 48 49 |
# File 'lib/fidgit/elements/slider.rb', line 47 def value @value end |
Instance Method Details
#handle_dragged_to(x, y) ⇒ Object
100 101 102 103 |
# File 'lib/fidgit/elements/slider.rb', line 100 def handle_dragged_to(x, y) # In this case, x is the left-hand side fo the handle. self.value = ((x - self.x) / (width - @handle.width)) * (@range.max - @range.min) + @range.min end |
#left_mouse_button(sender, x, y) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/fidgit/elements/slider.rb', line 92 def (sender, x, y) # In this case, x should be the centre of the handle after it has moved. self.value = ((x - (@handle.width / 2) - self.x) / (width - @handle.width)) * (@range.max - @range.min) + @range.min @mouse_down = true nil end |
#tip ⇒ Object
87 88 89 90 |
# File 'lib/fidgit/elements/slider.rb', line 87 def tip tip = super tip.empty? ? @value.to_s : "#{tip}: #{@value}" end |