Class: CyberarmEngine::Element::Slider
- Inherits:
-
Container
- Object
- CyberarmEngine::Element
- Container
- CyberarmEngine::Element::Slider
- Defined in:
- lib/cyberarm_engine/ui/elements/slider.rb
Defined Under Namespace
Classes: Handle
Constant Summary
Constants included from Theme
Instance Attribute Summary collapse
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#step_size ⇒ Object
readonly
Returns the value of attribute step_size.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Container
#children, #fill_color, #gui_state, #scroll_position, #stroke_color
Attributes inherited from CyberarmEngine::Element
#background_canvas, #border_canvas, #element_visible, #event_handler, #options, #parent, #style, #tip, #x, #y, #z
Instance Method Summary collapse
- #draw ⇒ Object
- #handle_dragged_to(x, _y) ⇒ Object
- #holding_left_mouse_button(_sender, x, y) ⇒ Object
-
#initialize(options = {}, block = nil) ⇒ Slider
constructor
A new instance of Slider.
- #position_handle ⇒ Object
- #recalculate ⇒ Object
- #update ⇒ Object
Methods inherited from Container
#add, #append, #build, #clear, current_container, current_container=, #debug_draw, #fits_on_line?, #hit_element?, #layout, #max_width, #mouse_wheel_down, #mouse_wheel_up, #move_to_next_line, #position_on_current_line, #position_on_next_line, #remove, #render, #scroll_top, #scroll_top=, #tallest_neighbor, #to_s, #write_tree
Methods included from Common
#alt_down?, #control_down?, #current_state, #darken, #draw_rect, #fill, #find_element_by_tag, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #shift_down?, #shift_state, #show_cursor, #show_cursor=, #window
Methods inherited from CyberarmEngine::Element
#background=, #background_image=, #background_nine_slice=, #blur, #button_down, #button_up, #clicked_left_mouse_button, #content_height, #content_width, #debug_draw, #default_events, #dimensional_size, #draggable?, #element_visible?, #enabled=, #enabled?, #enter, #focus, #focused?, #height, #hide, #hit?, #inner_height, #inner_width, #inspect, #is_root?, #leave, #left_mouse_button, #max_scroll_height, #max_scroll_width, #noncontent_height, #noncontent_width, #outer_height, #outer_width, #released_left_mouse_button, #render, #reposition, #root, #safe_style_fetch, #scroll_height, #scroll_width, #set_background, #set_background_image, #set_background_nine_slice, #set_border_color, #set_border_thickness, #set_color, #set_font, #set_margin, #set_padding, #set_static_position, #show, #space_available_height, #space_available_width, #stylize, #to_s, #toggle, #update_background, #update_background_image, #update_background_nine_slice, #update_styles, #visible?, #width
Methods included from CyberarmEngine::Event
#event, #publish, #subscribe, #unsubscribe
Methods included from Theme
#deep_merge, #default, #theme_defaults
Constructor Details
#initialize(options = {}, block = nil) ⇒ Slider
Returns a new instance of Slider.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cyberarm_engine/ui/elements/slider.rb', line 38 def initialize( = {}, block = nil) super(, block) @range = @options[:range] || (0.0..1.0) @step_size = @options[:step] || 0.1 @value = @options[:value] || (@range.first + @range.last) / 2 @handle = Handle.new("", parent: self, theme: [:theme], width: 8, height: 1.0) { close } add(@handle) end |
Instance Attribute Details
#range ⇒ Object (readonly)
Returns the value of attribute range.
36 37 38 |
# File 'lib/cyberarm_engine/ui/elements/slider.rb', line 36 def range @range end |
#step_size ⇒ Object (readonly)
Returns the value of attribute step_size.
36 37 38 |
# File 'lib/cyberarm_engine/ui/elements/slider.rb', line 36 def step_size @step_size end |
#value ⇒ Object
Returns the value of attribute value.
36 37 38 |
# File 'lib/cyberarm_engine/ui/elements/slider.rb', line 36 def value @value end |
Instance Method Details
#draw ⇒ Object
70 71 72 73 74 |
# File 'lib/cyberarm_engine/ui/elements/slider.rb', line 70 def draw super @handle.draw end |
#handle_dragged_to(x, _y) ⇒ Object
89 90 91 92 93 |
# File 'lib/cyberarm_engine/ui/elements/slider.rb', line 89 def handle_dragged_to(x, _y) @ratio = ((x - @handle.width / 2) - @x) / (content_width - @handle.outer_width) self.value = @ratio.clamp(0.0, 1.0) * (@range.max - @range.min) + @range.min end |
#holding_left_mouse_button(_sender, x, y) ⇒ Object
83 84 85 86 87 |
# File 'lib/cyberarm_engine/ui/elements/slider.rb', line 83 def (_sender, x, y) handle_dragged_to(x, y) :handled end |
#position_handle ⇒ Object
63 64 65 66 67 68 |
# File 'lib/cyberarm_engine/ui/elements/slider.rb', line 63 def position_handle @handle.x = @x + @handle.style.margin_left + @style.padding_left + @style.border_thickness_left + ((content_width - @handle.outer_width) * (@value - @range.min) / (@range.max - @range.min).to_f) @handle.y = @y + @handle.style.margin_top + @style.border_thickness_top + @style.padding_top end |
#recalculate ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cyberarm_engine/ui/elements/slider.rb', line 49 def recalculate _width = dimensional_size(@style.width, :width) _height = dimensional_size(@style.height, :height) @width = _width @height = _height position_handle @handle.recalculate @handle.update_background update_background end |
#update ⇒ Object
76 77 78 79 80 81 |
# File 'lib/cyberarm_engine/ui/elements/slider.rb', line 76 def update super @tip = value.to_s @handle.tip = @tip end |