Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for recent Scarpe changes #6

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Install the gem and add to the application's Gemfile by executing:

$ bundle add scarpe-wasm

If bundler is not being used to manage dependencies, install the gem by executing:
If bundler is not being used to manage dependencies (NOT RECOMMENDED), install the gem by executing:

$ gem install scarpe-wasm

Expand Down
20 changes: 5 additions & 15 deletions lib/scarpe/wasm.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Scarpe WASM Display Service
# Scarpe Wasm Display Service

# This file should be required on the Wasm side, not the Ruby side.
# So it's used to link to JS, and to instantiate widgets, but not
# So it's used to link to JS, and to instantiate drawables, but not
# for e.g. packaging.

require_relative "wasm/version"
Expand All @@ -12,20 +12,12 @@
require_relative "wasm/web_wrangler"
require_relative "wasm/control_interface"

require_relative "wasm/widget"
require_relative "wasm/drawable"
require_relative "wasm/wasm_local_display"

require_relative "wasm/dimensions"
require_relative "wasm/html"

require_relative "wasm/spacing"
require_relative "wasm/star"
require_relative "wasm/radio"
require_relative "wasm/background"
require_relative "wasm/border"

require_relative "wasm/arc"
require_relative "wasm/font"
require_relative "wasm/art_drawables"

require_relative "wasm/app"
require_relative "wasm/para"
Expand All @@ -39,12 +31,10 @@
require_relative "wasm/edit_box"
require_relative "wasm/edit_line"
require_relative "wasm/list_box"
require_relative "wasm/alert"
require_relative "wasm/span"
require_relative "wasm/shape"

require_relative "wasm/text_widget"
require_relative "wasm/text_drawable"
require_relative "wasm/link"
require_relative "wasm/line"
require_relative "wasm/video"
require_relative "wasm/check"
66 changes: 0 additions & 66 deletions lib/scarpe/wasm/alert.rb

This file was deleted.

40 changes: 15 additions & 25 deletions lib/scarpe/wasm/app.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
# frozen_string_literal: true

class Scarpe
# Scarpe::WASMApp must only be used from the main thread, due to GTK+ limitations.
class WASMApp < WASMWidget
module Scarpe::Wasm
# App must only be used from the main thread, due to GTK+ limitations.
class App < Drawable
attr_reader :control_interface

attr_writer :shoes_linkable_id

def initialize(properties)
super

# It's possible to provide a Ruby script by setting
# SCARPE_TEST_CONTROL to its file path. This can
# allow pre-setting test options or otherwise
# performing additional actions not written into
# the Shoes app itself.
#
# The control interface is what lets these files see
# events, specify overrides and so on.
@control_interface = ControlInterface.new
if ENV["SCARPE_TEST_CONTROL"]
require "scarpe/components/unit_test_helpers"
@control_interface.instance_eval File.read(ENV["SCARPE_TEST_CONTROL"])
end

# TODO: rename @view
@view = Scarpe::WebWrangler.new title: @title,
@view = Scarpe::Wasm::WebWrangler.new title: @title,
width: @width,
height: @height,
resizable: @resizable
Expand Down Expand Up @@ -62,12 +50,10 @@ def init

def run
@control_interface.dispatch_event(:init)

send_shoes_event("return", event_name: "custom_event_loop")

# This takes control of the main thread and never returns. And it *must* be run from
# the main thread. And it stops any Ruby background threads.
# That's totally cool and normal, right?
@view.empty_page = empty_page_element

@view.run
end

Expand All @@ -82,24 +68,28 @@ def destroy
end
end

# All JS callbacks to Scarpe widgets are dispatched
# All JS callbacks to Scarpe drawables are dispatched
# via this handler
def handle_callback(name, *args)
@callbacks[name].call(*args)
if @callbacks.key?(name)
@callbacks[name].call(*args)
else
raise Scarpe::UnknownEventTypeError, "No such Wasm callback: #{name.inspect}!"
end
end

# Bind a Scarpe callback name; see handle_callback above.
# See Scarpe::Widget for how the naming is set up
# See {Drawable} for how the naming is set up
def bind(name, &block)
@callbacks[name] = block
end

# Request a full redraw if WASM is running. Otherwise
# Request a full redraw if Wasm is running. Otherwise
# this is a no-op.
#
# @return [void]
def request_redraw!
wrangler = WASMDisplayService.instance.wrangler
wrangler = DisplayService.instance.wrangler
if wrangler.is_running
wrangler.replace(@document_root.to_html)
end
Expand Down
56 changes: 0 additions & 56 deletions lib/scarpe/wasm/arc.rb

This file was deleted.

33 changes: 33 additions & 0 deletions lib/scarpe/wasm/art_drawables.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Scarpe::Wasm
class Arc < Drawable
def element(&block)
render("arc")
end
end

class Arrow < Drawable
def element(&block)
render("arrow")
end
end

class Line < Drawable
def element(&block)
render("line")
end
end

class Rect < Drawable
def element(&block)
render("rect")
end
end

class Star < Drawable
def element(&block)
render("star", &block)
end
end
end
27 changes: 0 additions & 27 deletions lib/scarpe/wasm/background.rb

This file was deleted.

24 changes: 0 additions & 24 deletions lib/scarpe/wasm/border.rb

This file was deleted.

Loading