Module: Shoes

Defined in:
lacci/lib/shoes.rb,
lacci/lib/shoes.rb,
lacci/lib/shoes/app.rb,
lacci/lib/shoes/log.rb,
lacci/lib/shoes/border.rb,
lacci/lib/shoes/colors.rb,
lacci/lib/shoes/widget.rb,
lacci/lib/shoes/spacing.rb,
lacci/lib/shoes/download.rb,
lacci/lib/shoes/constants.rb,
lacci/lib/shoes/background.rb,
lacci/lib/shoes/widgets/arc.rb,
lacci/lib/shoes/widgets/flow.rb,
lacci/lib/shoes/widgets/font.rb,
lacci/lib/shoes/widgets/line.rb,
lacci/lib/shoes/widgets/link.rb,
lacci/lib/shoes/widgets/para.rb,
lacci/lib/shoes/widgets/para.rb,
lacci/lib/shoes/widgets/span.rb,
lacci/lib/shoes/widgets/star.rb,
lacci/lib/shoes/widgets/alert.rb,
lacci/lib/shoes/widgets/check.rb,
lacci/lib/shoes/widgets/image.rb,
lacci/lib/shoes/widgets/radio.rb,
lacci/lib/shoes/widgets/shape.rb,
lacci/lib/shoes/widgets/stack.rb,
lacci/lib/shoes/widgets/video.rb,
lacci/lib/shoes/widgets/button.rb,
lacci/lib/shoes/display_service.rb,
lacci/lib/shoes/widgets/edit_box.rb,
lacci/lib/shoes/widgets/list_box.rb,
lacci/lib/shoes/widgets/edit_line.rb,
lacci/lib/shoes/widgets/text_widget.rb,
lacci/lib/shoes/widgets/document_root.rb

Overview

Shoes::TextWidget

Defined Under Namespace

Modules: Background, Border, Colors, Constants, Log, Spacing Classes: Alert, App, Arc, Button, Check, DisplayService, DocumentRoot, EditBox, EditLine, Error, Flow, Font, Image, InvalidAttributeValueError, Line, Link, Linkable, ListBox, LoggedWrapper, Para, Radio, Shape, Slot, Span, Stack, Star, SubscriptionItem, TextWidget, Video, Widget

Constant Summary collapse

LOG_LEVELS =
[:debug, :info, :warn, :error, :fatal].freeze

Class Method Summary collapse

Class Method Details

.add_file_loader(loader) ⇒ Object



115
116
117
# File 'lacci/lib/shoes.rb', line 115

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

.app(title: "Shoes!", width: 480, height: 420, resizable: true, &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 widgets 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

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.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lacci/lib/shoes.rb', line 66

def app(
  title: "Shoes!",
  width: 480,
  height: 420,
  resizable: true,
  &app_code_body
)
  app = Shoes::App.new(title:, width:, height:, resizable:, &app_code_body)
  app.init
  app.run
  nil
end

.default_file_loadersObject



101
102
103
104
105
106
107
108
109
# File 'lacci/lib/shoes.rb', line 101

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_widget_with(element) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lacci/lib/shoes/widgets/text_widget.rb', line 18

def default_text_widget_with(element)
  class_name = element.capitalize

  widget_class = Class.new(Shoes::TextWidget) do
    # Can we just change content to text to match the Shoes API?
    display_property :content

    def initialize(content)
      @content = content

      super

      create_display_widget
    end

    def text
      self.content
    end

    def text=(new_text)
      self.content = new_text
    end
  end
  Shoes.const_set class_name, widget_class
  widget_class.class_eval do
    display_property :content
  end
end

.file_loadersObject



111
112
113
# File 'lacci/lib/shoes.rb', line 111

def file_loaders
  @file_loaders ||= default_file_loaders
end

.reset_file_loadersObject



119
120
121
# File 'lacci/lib/shoes.rb', line 119

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:

  • path (String)

    The current-dir-relative path to the file

See Also:



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lacci/lib/shoes.rb', line 87

def run_app(relative_path)
  path = File.expand_path relative_path
  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



123
124
125
# File 'lacci/lib/shoes.rb', line 123

def set_file_loaders(loaders)
  @file_loaders = loaders
end