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.

See Also:

Instance Method Summary collapse

Instance Method Details

#appendObject

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

#clipboardString

Retrieve current clipboard contents.

Returns:

  • (String)

    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.

Parameters:

  • str (String)

    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.

Parameters:

  • name (String)

    web URL to download

  • args (Hash) (defaults to: {})
  • blk (Proc)

    code to run when download is complete

Options Hash (args):

  • :error (Proc)

    code to run if the download has an error

  • :finish (Proc)

    code to run when download is complete

  • :progress (Proc)

    code to run as download is happening

  • :save (String)

    filename to write automatically with download contents

  • :body (String)

    body to send with download request

  • :headers (Hash)

    HTTP headers to send with download request

  • :method (String)

    HTTP method for the download request (i.e. GET, POST, etc.)



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

#gutterFixnum

Width of scrollbar area in pixels.

Returns:

  • (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.

Parameters:

  • blk (Proc)

    code to run on hover

Returns:



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.

Parameters:

  • blk (Proc)

    code to when a key is pressed down

Returns:



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.

Parameters:

  • blk (Proc)

    code to when a key is released

Returns:



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.

Parameters:

  • blk (Proc)

    code to run on leaving

Returns:



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.

Parameters:

  • blk (Proc)

    code to run when the mouse moves

Returns:



23
24
25
26
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 23

def motion(&blk)
  @__app__.mouse_motion << blk
  @__app__.app
end

#mouseFixnum

Return the current position of the mouse.

Returns:

  • (Fixnum, Fixnum, Fixnum)

    mouse button, x, y



13
14
15
# File 'shoes-core/lib/shoes/dsl/interaction.rb', line 13

def mouse
  [@__app__.mouse_button, @__app__.mouse_pos[0], @__app__.mouse_pos[1]]
end

#resize(&blk) ⇒ Shoes::App

Register code to run when the window is resized.

Parameters:

  • blk (Proc)

    code to run on resize

Returns:



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_topFixnum

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.

Returns:

  • (Fixnum)

    scroll location



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.

Parameters:

  • n (Fixnum)

    scroll location to set



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.

Parameters:

  • url (String)

    Shoes url to display



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