Class: Hokusai::Blocks::Scrollbar
- Inherits:
-
Hokusai::Block
- Object
- Hokusai::Block
- Hokusai::Blocks::Scrollbar
- Defined in:
- ui/src/hokusai/blocks/scrollbar.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#scroll_y ⇒ Object
Returns the value of attribute scroll_y.
-
#scrolling ⇒ Object
Returns the value of attribute scrolling.
Attributes inherited from Hokusai::Block
Instance Method Summary collapse
- #after_updated ⇒ Object
- #do_goto(value) ⇒ Object
-
#initialize(**args) ⇒ Scrollbar
constructor
A new instance of Scrollbar.
- #percent_scrolled ⇒ Object
- #render(canvas) {|canvas| ... } ⇒ Object
- #scroll_handle(event) ⇒ Object
- #scroll_start(event) ⇒ Object
- #scroll_top_height ⇒ Object
Methods inherited from Hokusai::Block
#children, #children?, compile, computed, computed!, #draw, #draw_with, #dump, #emit, inject, inject!, #method_missing, mount, #on_resize, provide, provides, style, styles_get, template, template_from_file, template_get, #update, use, uses
Constructor Details
#initialize(**args) ⇒ Scrollbar
Returns a new instance of Scrollbar.
88 89 90 91 92 93 94 95 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 88 def initialize(**args) @scroll_y = 0.0 @scrolling = false @height = 0.0 @offset = 0.0 super(**args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hokusai::Block
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
38 39 40 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 38 def height @height end |
#offset ⇒ Object
Returns the value of attribute offset.
38 39 40 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 38 def offset @offset end |
#scroll_y ⇒ Object
Returns the value of attribute scroll_y.
38 39 40 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 38 def scroll_y @scroll_y end |
#scrolling ⇒ Object
Returns the value of attribute scrolling.
38 39 40 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 38 def scrolling @scrolling end |
Instance Method Details
#after_updated ⇒ Object
72 73 74 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 72 def after_updated do_goto(goto) unless goto.nil? end |
#do_goto(value) ⇒ Object
82 83 84 85 86 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 82 def do_goto(value) self.scroll_y = value.to_f emit("scroll", scroll_y, percent: percent_scrolled) end |
#percent_scrolled ⇒ Object
76 77 78 79 80 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 76 def percent_scrolled return 0 if scroll_top_height === 0 scroll_top_height / (height - control_height) end |
#render(canvas) {|canvas| ... } ⇒ Object
97 98 99 100 101 102 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 97 def render(canvas) self.offset = canvas.y self.height = canvas.height yield(canvas) end |
#scroll_handle(event) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 47 def scroll_handle(event) if event.left.down && scrolling do_goto(event.pos.y) else self.scrolling = false end # event.stop end |
#scroll_start(event) ⇒ Object
40 41 42 43 44 45 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 40 def scroll_start(event) self.scrolling = true do_goto(event.pos.y) event.stop end |
#scroll_top_height ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'ui/src/hokusai/blocks/scrollbar.rb', line 57 def scroll_top_height start = scroll_y control_middle = (control_height / 2) if start <= offset + control_middle return 0.0 elsif start >= offset + height - control_middle return height - control_height else return scroll_y - offset - control_middle end 0.0 end |