Class: Shoes::App

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
BuiltinMethods, Common::Inspect, DSL
Defined in:
shoes-core/lib/shoes/app.rb

Overview

This is the user-facing App object. It is ‘self` inside of a Shoes.app block, and is the context in which a Shoes app is evaled. It delegates most of its functionality to an InternalApp object, which interacts with other Shoes objects. There should be no unnecessary instance variables or methods in this class, so users are free to use whatever names they choose for their own code.

Constant Summary collapse

DELEGATE_METHODS =

class definitions are evaluated top to bottom, want to have all of them so define at bottom

((Shoes::App.public_instance_methods(false) +
Shoes::BuiltinMethods.public_instance_methods +
Shoes::DSL.public_instance_methods)).freeze

Constants included from DSL::Style

DSL::Style::OTHER_APP_STYLES, DSL::Style::PATTERN_APP_STYLES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::Inspect

#inspect, #to_s

Methods included from BuiltinMethods

#alert, #ask, #ask_color, #ask_open_file, #ask_open_folder, #ask_save_file, #ask_save_folder, #confirm, #font

Methods included from Color::DSLHelpers

#color, #gradient, #gray, #pattern, #rgb

Methods included from Common::ImageHandling

#absolute_file_path, #default_search_paths, #search_for

Methods included from DSL

define_shoes_color

Methods included from DSL::Text

#banner, #bg, #caption, #code, #del, #em, #fg, #ins, #inscription, #link, #para, #span, #strong, #sub, #subtitle, #sup, #tagline, #title

Methods included from DSL::Media

#image, #sound, #video

Methods included from DSL::Interaction

#append, #clipboard, #clipboard=, #download, #gutter, #hover, #keypress, #keyrelease, #leave, #motion, #mouse, #resize, #scroll_top, #scroll_top=, #visit

Methods included from DSL::Style

#nofill, #nostroke, #style, #translate

Methods included from DSL::Element

#background, #border, #button, #check, #edit_box, #edit_line, #flow, #list_box, #progress, #radio, #stack

Methods included from DSL::Art

#arc, #arrow, #line, #mask, #oval, #rect, #shape, #star

Methods included from DSL::Animate

#animate, #every, #timer

Constructor Details

#initialize(opts = {}, &blk) ⇒ App

Instantiates a new Shoes app.

Parameters:

  • opts (Hash) (defaults to: {})

    The options to initialize the app with.

  • blk (Proc)

    The block containing the DSL instructions to be executed within the app.

Options Hash (opts):

  • :title (String) — default: "Shoes 4"

    The title of the window

  • :resizable (Boolean) — default: true

    Whether the window is resizable

  • :fullscreen (Boolean) — default: false

    Whether the app should start in fullscreen

  • :width (Fixnum) — default: 600

    The width of the app window

  • :height (Fixnum) — default: 500

    The height of the app window

See Also:



48
49
50
51
52
53
54
# File 'shoes-core/lib/shoes/app.rb', line 48

def initialize(opts = {}, &blk)
  ensure_app_dir_set
  @__app__ = Shoes::InternalApp.new(self, opts, &blk)
  @__app__.setup_gui
  Shoes.register self
  @__app__.open_gui
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blk) ⇒ Object



104
105
106
107
108
109
110
# File 'shoes-core/lib/shoes/app.rb', line 104

def method_missing(name, *args, &blk)
  if defined?(@__additional_context__) && @__additional_context__
    @__additional_context__.public_send(name, *args, &blk)
  else
    super
  end
end

Class Method Details

.new_dsl_method(name, &blk) ⇒ Object



130
131
132
133
# File 'shoes-core/lib/shoes/app.rb', line 130

def self.new_dsl_method(name, &blk)
  define_method name, blk
  @method_subscribers.each { |klazz| klazz.def_delegator :app, name }
end

.subscribe_to_dsl_methods(klazz) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
# File 'shoes-core/lib/shoes/app.rb', line 118

def self.subscribe_to_dsl_methods(klazz)
  # Delegate anything in the app/dsl public list that DOESN'T have a method
  # already defined on the class in question
  methods_to_delegate = DELEGATE_METHODS - klazz.public_instance_methods

  klazz.extend Forwardable unless klazz.is_a? Forwardable
  klazz.def_delegators :app, *methods_to_delegate

  @method_subscribers ||= []
  @method_subscribers << klazz
end

Instance Method Details

#appObject

Shoes 3 exposes the app object like this, so we keep it for compatibility



58
59
60
# File 'shoes-core/lib/shoes/app.rb', line 58

def app
  self
end

#closeObject



78
79
80
81
# File 'shoes-core/lib/shoes/app.rb', line 78

def close
  Shoes.unregister self
  @__app__.quit
end

#eval_with_additional_context(context, &blk) ⇒ Object



97
98
99
100
101
102
# File 'shoes-core/lib/shoes/app.rb', line 97

def eval_with_additional_context(context, &blk)
  @__additional_context__ = context
  instance_eval(&blk) if blk
ensure
  @__additional_context__ = nil
end

#parentObject



83
84
85
# File 'shoes-core/lib/shoes/app.rb', line 83

def parent
  @__app__.current_slot.parent
end

#quitObject Also known as: exit



72
73
74
# File 'shoes-core/lib/shoes/app.rb', line 72

def quit
  Shoes.apps.each(&:close)
end

#start(&blk) ⇒ Object

Remember startup block for execution later



68
69
70
# File 'shoes-core/lib/shoes/app.rb', line 68

def start(&blk)
  @__app__.start_block = blk
end

#window(options = {}, &block) ⇒ Object



62
63
64
65
# File 'shoes-core/lib/shoes/app.rb', line 62

def window(options = {}, &block)
  options[:owner] = self
  self.class.new(options, &block)
end