Class: Shoes::App
- Inherits:
-
Object
- Object
- Shoes::App
- 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
-
#app ⇒ Object
Shoes 3 exposes the app object like this, so we keep it for compatibility.
- #close ⇒ Object
- #eval_with_additional_context(context, &blk) ⇒ Object
-
#initialize(opts = {}, &blk) ⇒ App
constructor
Instantiates a new Shoes app.
- #method_missing(name, *args, &blk) ⇒ Object
- #parent ⇒ Object
- #quit ⇒ Object (also: #exit)
-
#start(&blk) ⇒ Object
Remember startup block for execution later.
- #window(options = {}, &block) ⇒ Object
Methods included from Common::Inspect
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
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
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
Constructor Details
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
#app ⇒ Object
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 |
#close ⇒ Object
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 |
#parent ⇒ Object
83 84 85 |
# File 'shoes-core/lib/shoes/app.rb', line 83 def parent @__app__.current_slot.parent end |
#quit ⇒ Object 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( = {}, &block) [:owner] = self self.class.new(, &block) end |