Class: Shoes

Inherits:
Object
  • Object
show all
Defined in:
lacci/lib/shoes.rb,
lacci/lib/shoes.rb,
lacci/lib/shoes/app.rb,
lacci/lib/shoes/log.rb,
lacci/lib/shoes-spec.rb,
lacci/lib/shoes/border.rb,
lacci/lib/shoes/colors.rb,
lacci/lib/shoes/errors.rb,
lacci/lib/shoes/download.rb,
lacci/lib/shoes/drawable.rb,
lacci/lib/shoes/changelog.rb,
lacci/lib/shoes/constants.rb,
lacci/lib/shoes/background.rb,
lacci/lib/shoes/drawables/arc.rb,
lacci/lib/shoes/drawables/flow.rb,
lacci/lib/shoes/drawables/line.rb,
lacci/lib/shoes/drawables/link.rb,
lacci/lib/shoes/drawables/oval.rb,
lacci/lib/shoes/drawables/para.rb,
lacci/lib/shoes/drawables/para.rb,
lacci/lib/shoes/drawables/rect.rb,
lacci/lib/shoes/drawables/star.rb,
lacci/lib/shoes/display_service.rb,
lacci/lib/shoes/drawables/arrow.rb,
lacci/lib/shoes/drawables/check.rb,
lacci/lib/shoes/drawables/image.rb,
lacci/lib/shoes/drawables/radio.rb,
lacci/lib/shoes/drawables/shape.rb,
lacci/lib/shoes/drawables/stack.rb,
lacci/lib/shoes/drawables/video.rb,
lacci/lib/shoes/drawables/border.rb,
lacci/lib/shoes/drawables/button.rb,
lacci/lib/shoes/drawables/edit_box.rb,
lacci/lib/shoes/drawables/list_box.rb,
lacci/lib/shoes/drawables/progress.rb,
lacci/lib/shoes/drawables/edit_line.rb,
lacci/lib/shoes/drawables/document_root.rb,
lacci/lib/shoes/drawables/text_drawable.rb

Overview

Lacci Shoes apps operate in multiple layers. A Shoes drawable tree exists as fairly plain, simple Ruby objects. And then a display-service drawable tree integrates with the display technology. This lets us use Ruby as our API while not tying it too closely to the limitations of Webview, WASM, LibUI, etc.

Choosing Display Services

Before running a Lacci app, you can set SCARPE_DISPLAY_SERVICE. If you set it to "whatever_service", Scarpe will require "scarpe/whatever_service", which can be supplied by the Scarpe gem or another Scarpe-based gem. Currently leaving the environment variable empty is equivalent to requesting local Webview.

Events

Events are a lot of what tie the Shoes drawables and the display service together.

Shoes drawables expect to operate in a fairly "hands off" mode where they record to an event queue to send to the display service, and the display service records events to send back.

When a Shoes handler takes an action (e.g. some_para.replace(),) the relevant call will be dispatched as a :display event, to be sent to the display service. And when a display-side event occurs (e.g. user pushes a button,) it will be dispatched as a :shoes event, to be sent to the Shoes tree of drawables.

Defined Under Namespace

Modules: Background, Builtins, Colors, Constants, Errors, Log, Spec Classes: App, Arc, Arrow, Border, Button, Changelog, Check, DisplayService, DocumentRoot, Drawable, EditBox, EditLine, Error, Flow, Image, Line, Link, LinkHover, Linkable, ListBox, LoggedWrapper, Oval, Para, Progress, Radio, Rect, Shape, Slot, SpecInstance, SpecProxy, Stack, Star, SubscriptionItem, TextDrawable, Video, Widget

Constant Summary collapse

LOG_LEVELS =
[:debug, :info, :warn, :error, :fatal].freeze
RELEASE_INFO =
changelog_instance.get_latest_release_info
RELEASE_NAME =
RELEASE_ID =
RELEASE_BUILD_DATE =
RELEASE_TYPE =

This isn't really a thing any more

"LOOSE_SHOES"
REVISION =

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.APPSObject

Returns the value of attribute APPS.



58
59
60
# File 'lacci/lib/shoes.rb', line 58

def APPS
  @APPS
end

Class Method Details

.add_file_loader(loader) ⇒ Object



138
139
140
# File 'lacci/lib/shoes.rb', line 138

def add_file_loader(loader)
  file_loaders.prepend(loader)
end

.app(title: "Shoes!", width: 480, height: 420, resizable: true, features: [], &app_code_body) ⇒ void

This method returns an undefined value.

Creates a Shoes app with a new window. The block parameter is used to create drawables and set up handlers. Arguments are passed to Shoes::App.new internally.

Examples:

Simple one-button app

Shoes.app(title: "Button!", width: 200, height: 200) do
  @p = para "Press it NOW!"
  button("clicky") { @p.replace("You pressed it! CELEBRATION!") }
end

Parameters:

  • title (String) (defaults to: "Shoes!")

    The new app window title

  • width (Integer) (defaults to: 480)

    The new app window width

  • height (Integer) (defaults to: 420)

    The new app window height

  • resizable (Boolean) (defaults to: true)

    Whether the app window should be resizeable

  • features (Symbol, Array<Symbol>) (defaults to: [])

    Additional Shoes extensions requested by the app

See Also:

  • Shoes::App#new

Incompatibilities with Shoes:

  • In Shoes3, this method will return normally. In Scarpe, after the block is executed, the method will not return and Scarpe will retain control of execution until the window is closed and the app quits.

  • In Shoes3 the parameters were a hash of options, not keyword arguments.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lacci/lib/shoes.rb', line 82

def app(
  title: "Shoes!",
  width: 480,
  height: 420,
  resizable: true,
  features: [],
  &app_code_body
)
  f = [features].flatten # Make sure this is a list, not a single symbol
  app = Shoes::App.new(title:, width:, height:, resizable:, features: f, &app_code_body)
  app.init
  app.run
  nil
end

.default_file_loadersObject



124
125
126
127
128
129
130
131
132
# File 'lacci/lib/shoes.rb', line 124

def default_file_loaders
  [
    # By default we will always try to load any file, regardless of extension, as a Shoes Ruby file.
    proc do |path|
      load path
      true
    end,
  ]
end

.default_text_drawable_with(element) ⇒ Object



98
99
100
101
102
103
104
105
106
107
# File 'lacci/lib/shoes/drawables/text_drawable.rb', line 98

def default_text_drawable_with(element)
  class_name = element.capitalize

  drawable_class = Class.new(Shoes::TextDrawable) do
    shoes_events # No specific events

    init_args # We're going to pass an empty array to super
  end
  Shoes.const_set class_name, drawable_class
end

.file_loadersObject



134
135
136
# File 'lacci/lib/shoes.rb', line 134

def file_loaders
  @file_loaders ||= default_file_loaders
end

.reset_file_loadersObject



142
143
144
# File 'lacci/lib/shoes.rb', line 142

def reset_file_loaders
  @file_loaders = default_file_loaders
end

.run_app(relative_path) ⇒ void

This method returns an undefined value.

Load a Shoes app from a file. By default, this will load old-style Shoes apps from a .rb file with all the appropriate libraries loaded. By setting one or more loaders, a Lacci-based display library can accept new file formats as well, not just raw Shoes .rb files.

Parameters:

  • relative_path (String)

    The current-dir-relative path to the file

See Also:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lacci/lib/shoes.rb', line 105

def run_app(relative_path)
  path = File.expand_path relative_path
  dir = File.dirname(path)

  # Shoes assumes we're starting from the app code's path
  Dir.chdir(dir)

  loaded = false
  file_loaders.each do |loader|
    if loader.call(path)
      loaded = true
      break
    end
  end
  raise "Could not find a file loader for #{path.inspect}!" unless loaded

  nil
end

.set_file_loaders(loaders) ⇒ Object



146
147
148
# File 'lacci/lib/shoes.rb', line 146

def set_file_loaders(loaders)
  @file_loaders = loaders
end