Skip to content

Commit

Permalink
feat: extract mouse/keyboard actions
Browse files Browse the repository at this point in the history
  • Loading branch information
OrthoDex committed Feb 21, 2017
1 parent 67458a7 commit 0fb25ff
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 70 deletions.
72 changes: 2 additions & 70 deletions shoes-core/lib/shoes/dsl.rb
Expand Up @@ -77,6 +77,7 @@ def gem(name)
require 'shoes/color'

require 'shoes/dsl/text'
require 'shoes/dsl/interaction'

require 'shoes/common/attachable'
require 'shoes/common/changeable'
Expand Down Expand Up @@ -154,6 +155,7 @@ class Shoes
module DSL
include Color::DSLHelpers
include DSL::Text
include DSL::Interaction
# Set default style for elements of a particular class, or for all
# elements, or return the current defaults for all elements
#
Expand Down Expand Up @@ -605,76 +607,6 @@ def nofill
@__app__.style[:fill] = nil
end

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

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

def resize(&blk)
@__app__.add_resize_callback blk
end

# hover and leave just delegate to the current slot as hover and leave
# are just defined for slots but self is always the app.
def hover(&blk)
@__app__.current_slot.hover(&blk)
end

def leave(&blk)
@__app__.current_slot.leave(&blk)
end

def keypress(&blk)
Shoes::Keypress.new @__app__, &blk
end

def keyrelease(&blk)
Shoes::Keyrelease.new @__app__, &blk
end

def append
yield if block_given?
end

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

def scroll_top
@__app__.scroll_top
end

def scroll_top=(n)
@__app__.scroll_top = n
end

def clipboard
@__app__.clipboard
end

def clipboard=(str)
@__app__.clipboard = str
end

def download(name, args = {}, &blk)
create(Shoes::Download, name, args, &blk).tap(&:start)
end

def gutter
@__app__.gutter
end

def video(*_args)
raise Shoes::NotImplementedError,
'Sorry video support has been cut from shoes 4!' \
Expand Down
76 changes: 76 additions & 0 deletions shoes-core/lib/shoes/dsl/interaction.rb
@@ -0,0 +1,76 @@
# frozen_string_literal: true
class Shoes
module DSL
module Interaction
def mouse
[@__app__.mouse_button, @__app__.mouse_pos[0], @__app__.mouse_pos[1]]
end

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

def resize(&blk)
@__app__.add_resize_callback blk
end

# hover and leave just delegate to the current slot as hover and leave
# are just defined for slots but self is always the app.
def hover(&blk)
@__app__.current_slot.hover(&blk)
end

def leave(&blk)
@__app__.current_slot.leave(&blk)
end

def keypress(&blk)
Shoes::Keypress.new @__app__, &blk
end

def keyrelease(&blk)
Shoes::Keyrelease.new @__app__, &blk
end

def append
yield if block_given?
end

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

def scroll_top
@__app__.scroll_top
end

def scroll_top=(n)
@__app__.scroll_top = n
end

def clipboard
@__app__.clipboard
end

def clipboard=(str)
@__app__.clipboard = str
end

def download(name, args = {}, &blk)
create(Shoes::Download, name, args, &blk).tap(&:start)
end

def gutter
@__app__.gutter
end
end
end
end

0 comments on commit 0fb25ff

Please sign in to comment.