Module: Shoes::DSL::Interaction
- Included in:
- Shoes::DSL
- Defined in:
- shoes-core/lib/shoes/dsl/interaction.rb
Overview
DSL methods for handling user interaction (mouse, keyboard) in Shoes applications.
Instance Method Summary collapse
-
#append ⇒ Object
Run a block in the context of the current slot.
-
#clipboard ⇒ String
Retrieve current clipboard contents.
-
#clipboard=(str) ⇒ Object
Set the current clipboard contents.
-
#download(name, args = {}, &blk) ⇒ Object
Download the contents of a URL.
-
#gutter ⇒ Fixnum
Width of scrollbar area in pixels.
-
#hover(&blk) ⇒ Shoes::App
Register code to run when the mouse hovers over the current slot.
-
#keypress(&blk) ⇒ Shoes::App
Register code to run when a key is pressed.
-
#keyrelease(&blk) ⇒ Shoes::App
Register code to run when a key is released.
-
#leave(&blk) ⇒ Shoes::App
Register code to run when the mouse leaves the current slot.
-
#motion(&blk) ⇒ Shoes::App
Register code to run when the mouse moves in the application.
-
#mouse ⇒ Fixnum
Return the current position of the mouse.
-
#resize(&blk) ⇒ Shoes::App
Register code to run when the window is resized.
-
#scroll_top ⇒ Fixnum
Return the top scrolling location for the main application.
-
#scroll_top=(n) ⇒ Object
Set the top scrolling location for the main application.
-
#visit(url) ⇒ Object
Change the Shoes application to run the method associated with a passed “url”.
Instance Method Details
#append ⇒ Object
Run a block in the context of the current slot. Typically used to add more elements into a slot
85 86 87 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 85 def append yield if block_given? end |
#clipboard ⇒ String
Retrieve current clipboard contents.
132 133 134 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 132 def clipboard @__app__.clipboard end |
#clipboard=(str) ⇒ Object
Set the current clipboard contents.
139 140 141 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 139 def clipboard=(str) @__app__.clipboard = str end |
#download(name, args = {}, &blk) ⇒ Object
Download the contents of a URL.
155 156 157 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 155 def download(name, args = {}, &blk) create(Shoes::Download, name, args, &blk).tap(&:start) end |
#gutter ⇒ Fixnum
Width of scrollbar area in pixels.
162 163 164 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 162 def gutter @__app__.gutter end |
#hover(&blk) ⇒ Shoes::App
Register code to run when the mouse hovers over the current slot.
blk is passed the hovered over element as a parameter.
43 44 45 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 43 def hover(&blk) @__app__.current_slot.hover(&blk) end |
#keypress(&blk) ⇒ Shoes::App
Register code to run when a key is pressed.
Typical text characters are passed to the block as strings. Special keys are identified with symbols. For example :alt_a is the symbol for pressing down the Alt key plus the a key simultaneously.
65 66 67 68 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 65 def keypress(&blk) Shoes::Keypress.new @__app__, &blk @__app__.app end |
#keyrelease(&blk) ⇒ Shoes::App
Register code to run when a key is released.
Typical text characters are passed to the block as strings. Special keys are identified with symbols. For example :alt_a is the symbol for pressing down the Alt key plus the a key simultaneously.
78 79 80 81 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 78 def keyrelease(&blk) Shoes::Keyrelease.new @__app__, &blk @__app__.app end |
#leave(&blk) ⇒ Shoes::App
Register code to run when the mouse leaves the current slot.
blk is passed the left element as a parameter.
53 54 55 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 53 def leave(&blk) @__app__.current_slot.leave(&blk) end |
#motion(&blk) ⇒ Shoes::App
Register code to run when the mouse moves in the application.
blk receives the x, y coordinates of the mouse at the time of moving.
23 24 25 26 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 23 def motion(&blk) @__app__.mouse_motion << blk @__app__.app end |
#mouse ⇒ Fixnum
Return the current position of the mouse.
13 14 15 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 13 def mouse [@__app__., @__app__.mouse_pos[0], @__app__.mouse_pos[1]] end |
#resize(&blk) ⇒ Shoes::App
Register code to run when the window is resized.
32 33 34 35 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 32 def resize(&blk) @__app__.add_resize_callback blk @__app__.app end |
#scroll_top ⇒ Fixnum
Return the top scrolling location for the main application.
Larger values for scroll_top will show positions further down in the application. Smaller values (down to 0) get closer to the top.
115 116 117 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 115 def scroll_top @__app__.scroll_top end |
#scroll_top=(n) ⇒ Object
Set the top scrolling location for the main application.
Larger values for scroll_top will show positions further down in the application. Smaller values (down to 0) get closer to the top.
125 126 127 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 125 def scroll_top=(n) @__app__.scroll_top = n end |
#visit(url) ⇒ Object
Change the Shoes application to run the method associated with a passed “url”. This typically expects your Shoes app to be defined by deriving from Shoes.
The class_book.rb sample is recommended as an example of this approach to Shoes apps.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 97 def visit(url) match_data = nil url_data = Shoes::URL.urls.find { |page, _| match_data = page.match url } return unless url_data action_proc = url_data[1] url_argument = match_data[1] clear do @__app__.location = url action_proc.call self, url_argument end end |