Class: Shoes::InternalApp

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Common::Clickable, Common::SafelyEvaluate, Common::Style
Defined in:
shoes-core/lib/shoes/internal_app.rb

Overview

This is the representation of the app that is used internally by Shoes objects. It is NOT the app object that a user interacts with in a Shoes.app block. The user facing App object is…the App object.

The InternalApp object is responsible for maintaining the state of the App and providing the bulk of the functionality, leaving the App a relatively blank slate for users to bend to their will.

Constant Summary collapse

DEFAULT_OPTIONS =
{
  width:     600,
  height:    500,
  title:     "Shoes 4",
  resizable: true,
  border:    true
}.freeze

Constants included from Common::Style

Common::Style::DEFAULT_STYLES, Common::Style::STYLE_GROUPS

Instance Attribute Summary collapse

Attributes included from Common::Clickable

#pass_coordinates

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::SafelyEvaluate

#safely_evaluate

Methods included from Common::Style

#applicable_app_styles, #create_style_hash, included, #style, #style_init

Methods included from Common::Clickable

#pass_coordinates?, #register_click

Constructor Details

#initialize(app, opts, &blk) ⇒ InternalApp

Returns a new instance of InternalApp.



27
28
29
30
31
32
# File 'shoes-core/lib/shoes/internal_app.rb', line 27

def initialize(app, opts, &blk)
  @app = app
  @blk = blk
  set_attributes_from_options(opts)
  set_initial_attributes
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



55
56
57
# File 'shoes-core/lib/shoes/internal_app.rb', line 55

def app
  @app
end

#app_titleObject

Returns the value of attribute app_title.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def app_title
  @app_title
end

#blkObject

Returns the value of attribute blk.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def blk
  @blk
end

#current_slotObject

Returns the value of attribute current_slot.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def current_slot
  @current_slot
end

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



55
56
57
# File 'shoes-core/lib/shoes/internal_app.rb', line 55

def dimensions
  @dimensions
end

#element_stylesObject (readonly)

Returns the value of attribute element_styles.



55
56
57
# File 'shoes-core/lib/shoes/internal_app.rb', line 55

def element_styles
  @element_styles
end

#elementsObject

Returns the value of attribute elements.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def elements
  @elements
end

#guiObject (readonly)

Returns the value of attribute gui.



55
56
57
# File 'shoes-core/lib/shoes/internal_app.rb', line 55

def gui
  @gui
end

#heightObject



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

def height
  started? ? gui.height : @dimensions.height
end

#locationObject

Returns the value of attribute location.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def location
  @location
end

#mouse_buttonObject

Returns the value of attribute mouse_button.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def mouse_button
  @mouse_button
end

#mouse_hover_controlsObject

Returns the value of attribute mouse_hover_controls.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def mouse_hover_controls
  @mouse_hover_controls
end

#mouse_motionObject (readonly)

Returns the value of attribute mouse_motion.



55
56
57
# File 'shoes-core/lib/shoes/internal_app.rb', line 55

def mouse_motion
  @mouse_motion
end

#mouse_posObject

Returns the value of attribute mouse_pos.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def mouse_pos
  @mouse_pos
end

#optsObject

Returns the value of attribute opts.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def opts
  @opts
end

#ownerObject (readonly)

Returns the value of attribute owner.



55
56
57
# File 'shoes-core/lib/shoes/internal_app.rb', line 55

def owner
  @owner
end

#remove_stylesObject (readonly)

Returns the value of attribute remove_styles.



55
56
57
# File 'shoes-core/lib/shoes/internal_app.rb', line 55

def remove_styles
  @remove_styles
end

#resizableObject

Returns the value of attribute resizable.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def resizable
  @resizable
end

#resize_callbacksObject (readonly)

Returns the value of attribute resize_callbacks.



55
56
57
# File 'shoes-core/lib/shoes/internal_app.rb', line 55

def resize_callbacks
  @resize_callbacks
end

#start_as_fullscreenObject Also known as: start_as_fullscreen?

Returns the value of attribute start_as_fullscreen.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def start_as_fullscreen
  @start_as_fullscreen
end

#start_blockObject

Returns the value of attribute start_block.



60
61
62
# File 'shoes-core/lib/shoes/internal_app.rb', line 60

def start_block
  @start_block
end

#top_slotObject (readonly)

Returns the value of attribute top_slot.



55
56
57
# File 'shoes-core/lib/shoes/internal_app.rb', line 55

def top_slot
  @top_slot
end

#widthObject



74
75
76
# File 'shoes-core/lib/shoes/internal_app.rb', line 74

def width
  started? ? gui.width : @dimensions.width
end

Class Method Details

.add_global_keypress(key, &blk) ⇒ Object



173
174
175
# File 'shoes-core/lib/shoes/internal_app.rb', line 173

def self.add_global_keypress(key, &blk)
  global_keypresses[key] = blk
end

.global_keypressesObject



169
170
171
# File 'shoes-core/lib/shoes/internal_app.rb', line 169

def self.global_keypresses
  @global_keypresses ||= {}
end

Instance Method Details

#add_child(_child) ⇒ Object



90
91
92
93
94
# File 'shoes-core/lib/shoes/internal_app.rb', line 90

def add_child(_child)
  # No-op. The top_slot needs this method, but we already hold an explicit
  # reference to the top_slot, so we don't need to add it as a child. Other
  # elements should be added as children of the top_slot.
end

#add_mouse_hover_control(element) ⇒ Object



128
129
130
131
# File 'shoes-core/lib/shoes/internal_app.rb', line 128

def add_mouse_hover_control(element)
  return if mouse_hover_controls.include?(element)
  mouse_hover_controls << element
end

#add_resize_callback(blk) ⇒ Object



153
154
155
# File 'shoes-core/lib/shoes/internal_app.rb', line 153

def add_resize_callback(blk)
  @resize_callbacks << blk
end

#clear(&blk) ⇒ Object



66
67
68
# File 'shoes-core/lib/shoes/internal_app.rb', line 66

def clear(&blk)
  current_slot.clear(&blk)
end

#clickObject



118
119
120
121
# File 'shoes-core/lib/shoes/internal_app.rb', line 118

def click
  super
  @app
end

#contentsObject



70
71
72
# File 'shoes-core/lib/shoes/internal_app.rb', line 70

def contents
  top_slot.contents
end

#default_stylesObject



96
97
98
# File 'shoes-core/lib/shoes/internal_app.rb', line 96

def default_styles
  Common::Style::DEFAULT_STYLES.clone
end

#download(url, opts, &block) ⇒ Object



141
142
143
# File 'shoes-core/lib/shoes/internal_app.rb', line 141

def download(url, opts, &block)
  app.download url, opts, &block
end

#ensure_backend_loadedObject



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

def ensure_backend_loaded
  return if defined?(Shoes.configuration.backend::App)

  backend_const = Shoes.load_backend(Shoes.configuration.backend_name)
  backend_const.initialize_backend
end

#execute_block(blk) ⇒ Object



149
150
151
# File 'shoes-core/lib/shoes/internal_app.rb', line 149

def execute_block(blk)
  app.instance_eval(&blk)
end

#font(path = Shoes::DEFAULT_TEXTBLOCK_FONT) ⇒ Object



82
83
84
# File 'shoes-core/lib/shoes/internal_app.rb', line 82

def font(path = Shoes::DEFAULT_TEXTBLOCK_FONT)
  app.font path
end

#hidden?Boolean

Necessary for click/mouse positioning checks

Returns:

  • (Boolean)


114
115
116
# File 'shoes-core/lib/shoes/internal_app.rb', line 114

def hidden?
  false
end

#in_bounds?(_x, _y) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'shoes-core/lib/shoes/internal_app.rb', line 100

def in_bounds?(_x, _y)
  true
end

#inspect_detailsObject



165
166
167
# File 'shoes-core/lib/shoes/internal_app.rb', line 165

def inspect_details
  "\"#{@app_title}\" #{@dimensions.inspect}"
end

#open_guiObject



137
138
139
# File 'shoes-core/lib/shoes/internal_app.rb', line 137

def open_gui
  gui.open
end

#releaseObject



123
124
125
126
# File 'shoes-core/lib/shoes/internal_app.rb', line 123

def release
  super
  @app
end

#remove_mouse_hover_control(element) ⇒ Object



133
134
135
# File 'shoes-core/lib/shoes/internal_app.rb', line 133

def remove_mouse_hover_control(element)
  mouse_hover_controls.delete(element)
end

#setup_guiObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'shoes-core/lib/shoes/internal_app.rb', line 34

def setup_gui
  ensure_backend_loaded
  @gui = Shoes.configuration.backend::App.new self

  self.current_slot = create_top_slot
  execution_blk = create_execution_block(blk)

  eval_block execution_blk
  eval_block start_block if start_block

  setup_global_keypresses
  register_console_keypress
end

#started?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'shoes-core/lib/shoes/internal_app.rb', line 86

def started?
  gui&.started?
end

#textcursor(line_height) ⇒ Object



145
146
147
# File 'shoes-core/lib/shoes/internal_app.rb', line 145

def textcursor(line_height)
  app.line(0, 0, 0, line_height, hidden: true)
end

#trigger_resize_callbacksObject



157
158
159
160
161
162
163
# File 'shoes-core/lib/shoes/internal_app.rb', line 157

def trigger_resize_callbacks
  @resize_callbacks.each do |callback|
    safely_evaluate do
      callback.call
    end
  end
end

#wait_until_closedObject



177
178
179
180
# File 'shoes-core/lib/shoes/internal_app.rb', line 177

def wait_until_closed
  return unless gui
  gui.wait_until_closed
end