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

Shoes widget not scarpe #307

Merged
merged 3 commits into from
Jul 14, 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: 2 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
--protected
--no-private
--template-path docs/yard/template
--tag incompatibility:"Incompatibilities with Shoes"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nice..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, yeah :-) We can add other little categories like this if we want to, but I'm not sure which others we would need.

--exclude lib/scarpe/libui
-
lib/**/*.rb
docs/yard/*.md
Expand Down
2 changes: 1 addition & 1 deletion examples/button_go_away.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Shoes.app(debug: true) do
Shoes.app do
@b = button "Go away, button"
@b.click {
@b.destroy
Expand Down
2 changes: 1 addition & 1 deletion examples/ruby_racer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "benchmark"
require "stringio"

Shoes.app(title: "Ruby Racer", debug: true) do
Shoes.app(title: "Ruby Racer") do
racer1 = nil
racer2 = nil

Expand Down
16 changes: 2 additions & 14 deletions lib/scarpe.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "shoes"

require_relative "scarpe/logger"

# This will never be triggered -- we use the (...) feature below, which means this
Expand All @@ -15,7 +17,6 @@
# Is there a Shoes::Error class? Should this be two different error classes?
class Scarpe::Error < StandardError; end

require_relative "scarpe/constants"
require_relative "scarpe/version"
require_relative "scarpe/promises"
require_relative "scarpe/display_service"
Expand All @@ -26,16 +27,3 @@ class Scarpe::Error < StandardError; end
d_s = ENV["SCARPE_DISPLAY_SERVICE"] || "wv_local"
# This is require, not require_relative, to allow gems to supply a new display service
require "scarpe/#{d_s}"

include Constants

module Shoes
class << self
def app(...)
app = Scarpe::App.new(...)
app.init
app.run
app.destroy
end
end
end
2 changes: 1 addition & 1 deletion lib/scarpe/alert.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class Alert < Scarpe::Widget
class Alert < Shoes::Widget
display_property :text

def initialize(text)
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/arc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Scarpe
class InvalidAttributeValueError < Scarpe::Error; end

class Arc < Scarpe::Widget
class Arc < Shoes::Widget
display_properties :left, :top, :width, :height, :angle1, :angle2

def initialize(*args)
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/button.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class Button < Scarpe::Widget
class Button < Shoes::Widget
include Scarpe::Log
display_properties :text, :width, :height, :top, :left, :color, :padding_top, :padding_bottom, :text_color, :size, :font_size

Expand Down
10 changes: 6 additions & 4 deletions lib/scarpe/cats_cradle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ def on_event(event, &block)
}
# What to do about TextWidgets? Link, code, em, strong?
# Also, wait, what's up with span? What *is* that?
WIDGET_FINDERS.each do |finder_name, scarpe_class|
Shoes::Widget.widget_classes.each do |widget_class|
finder_name = widget_class.dsl_name

define_method(finder_name) do |*args|
app = Scarpe::App.instance
app = Shoes::App.instance

widgets = app.find_widgets_by(scarpe_class, *args)
widgets = app.find_widgets_by(widget_class, *args)
raise "Found more than one #{finder_name} matching #{args.inspect}!" if widgets.size > 1
raise "Found no #{finder_name} matching #{args.inspect}!" if widgets.empty?

Expand Down Expand Up @@ -239,7 +241,7 @@ def test_finished
end
end

# This module is mixed into Scarpe::App if we're running CC-based tests
# This module is mixed into Shoes::App if we're running CC-based tests
module CatsCradle
def event_init
@cc_instance = CCInstance.instance
Expand Down
24 changes: 0 additions & 24 deletions lib/scarpe/constants.rb

This file was deleted.

16 changes: 4 additions & 12 deletions lib/scarpe/display_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@
# 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 widgets.
#
# It is normally assumed that there will only be a single 'real' consumer for each
# queue. You wouldn't usually want multiple display services sending back click
# events, for example. But that's not a technical limitation of the system.
# You could have no display service and not get any events back, or a debug
# display service that just records what happened. But in real situations,
# exactly one display service is a reasonable and appropriate assumption.
#
# The event types are "queues" in the sense that they're separate from each
# other. You need to subscribe separately to :shoes and :display events if
# you want both. But internally they're immediately dispatched as events
# rather than keeping a literal array of items.
#
module Shoes
class DisplayService
class << self
Expand Down Expand Up @@ -167,6 +155,10 @@ def destroy
# This is for objects that can be referred to via events, using their
# IDs. There are also convenience functions for binding and sending
# events.
#
# Linkable objects may be event targets. Technically anything, linkable
# or not, can be an event subscriber, but linkables get easy convenience
# functions for subscription.
class Linkable
attr_reader :linkable_id

Expand Down
4 changes: 2 additions & 2 deletions lib/scarpe/download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "openssl"
require "nokogiri"

class Scarpe
module Shoes
class Widget
class ResponseWrapper
attr_reader :response
Expand All @@ -26,7 +26,7 @@ def download(url, method: "GET", save: nil, styles: {}, &block)
@block = block

Thread.new do
logger = Scarpe::Logger.logger("Scarpe::App#download")
logger = Scarpe::Logger.logger("Shoes::App#download")
begin
uri = URI(url)
response = perform_request(uri, method, styles)
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/edit_box.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class EditBox < Scarpe::Widget
class EditBox < Shoes::Widget
display_properties :text, :height, :width

def initialize(text = "", height: nil, width: nil, &block)
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/edit_line.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class EditLine < Scarpe::Widget
class EditLine < Shoes::Widget
display_properties :text, :width

def initialize(text = "", width: nil, &block)
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/fill.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class Fill < Scarpe::Widget
class Fill < Shoes::Widget
display_properties :color

def initialize(color)
Expand Down
4 changes: 2 additions & 2 deletions lib/scarpe/flow.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class Flow < Scarpe::Slot
class Flow < Shoes::Slot
display_properties :width, :height, :margin, :padding

def initialize(width: nil, height: nil, margin: nil, padding: nil, **options, &block)
Expand All @@ -12,7 +12,7 @@ def initialize(width: nil, height: nil, margin: nil, padding: nil, **options, &b
# Create the display-side widget *before* instance_eval, which will add child widgets with their display widgets
create_display_widget

Scarpe::App.instance.with_slot(self, &block) if block_given?
Shoes::App.instance.with_slot(self, &block) if block_given?
end
end
end
2 changes: 1 addition & 1 deletion lib/scarpe/font.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class Font < Scarpe::Widget
class Font < Shoes::Widget
display_properties :font

def initialize(font)
Expand Down
4 changes: 3 additions & 1 deletion lib/scarpe/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "open-uri"

class Scarpe
class Image < Scarpe::Widget
class Image < Shoes::Widget
display_properties :url, :width, :height, :top, :left, :click

def initialize(url, width: nil, height: nil, top: nil, left: nil, click: nil)
Expand All @@ -22,7 +22,9 @@ def replace(url)
self.url = url
end
end
end

module Shoes
class Widget
def size
width, height = FastImage.size(@url)
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative "wv/shape_helper"

class Scarpe
class Line < Scarpe::Widget
class Line < Shoes::Widget
include ShapeHelper

display_properties :left, :top, :x2, :y2, :color
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/link.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class Link < Scarpe::TextWidget
class Link < Shoes::TextWidget
display_properties :text, :click, :has_block

def initialize(text, click: nil, &block)
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/list_box.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class ListBox < Scarpe::Widget
class ListBox < Shoes::Widget
display_properties :selected_item, :items, :height, :width

def initialize(args = {}, &block)
Expand Down
4 changes: 3 additions & 1 deletion lib/scarpe/para.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class Para < Scarpe::Widget
class Para < Shoes::Widget
class << self
def inherited(subclass)
Scarpe::Widget.widget_classes ||= []
Expand Down Expand Up @@ -59,7 +59,9 @@ def show
@hidden_text_items = []
end
end
end

module Shoes
class Widget
def banner(*args, **kwargs)
para(*args, **{ size: :banner }.merge(kwargs))
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/shape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative "wv/shape_helper"

class Scarpe
class Shape < Scarpe::Widget
class Shape < Shoes::Widget
include ShapeHelper
display_properties :left, :top

Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/slot.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Scarpe::Slot < Scarpe::Widget
class Shoes::Slot < Shoes::Widget
include Scarpe::Background
include Scarpe::Border
include Scarpe::Spacing
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/span.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class Span < Scarpe::Widget
class Span < Shoes::Widget
display_properties :text, :stroke, :size, :font, :html_attributes

def initialize(text, stroke: nil, size: :span, font: nil, **html_attributes)
Expand Down
4 changes: 2 additions & 2 deletions lib/scarpe/stack.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class Stack < Scarpe::Slot
class Stack < Shoes::Slot
# TODO: sort out various margin and padding properties, including putting stuff into spacing
display_properties :width, :height, :scroll

Expand All @@ -14,7 +14,7 @@ def initialize(width: nil, height: nil, margin: nil, padding: nil, scroll: false

create_display_widget
# Create the display-side widget *before* running the block, which will add child widgets with their display widgets
Scarpe::App.instance.with_slot(self, &block) if block_given?
Shoes::App.instance.with_slot(self, &block) if block_given?
end
end
end
2 changes: 1 addition & 1 deletion lib/scarpe/star.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Scarpe
class InvalidAttributeValueError < Scarpe::Error; end

class Star < Scarpe::Widget
class Star < Shoes::Widget
include ShapeHelper
display_properties :left, :top, :points, :outer, :inner, :color

Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/subscription_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
# Inheriting from Widget gives these a parent slot and a
# linkable_id automatically.
class SubscriptionItem < Scarpe::Widget
class SubscriptionItem < Shoes::Widget
display_property :shoes_api_name

def initialize(shoes_api_name:, &block)
Expand Down
2 changes: 1 addition & 1 deletion lib/scarpe/video.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Scarpe
class Video < Scarpe::Widget
class Video < Shoes::Widget
display_properties :url

def initialize(url)
Expand Down
6 changes: 3 additions & 3 deletions lib/scarpe/widgets.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require_relative "colors"
require_relative "widget"
require_relative "app"
require "shoes/widget"
require "shoes/app"

require_relative "spacing"
require_relative "background"
Expand All @@ -29,7 +29,7 @@
require_relative "shape"
require_relative "arc"

require_relative "text_widget"
require "shoes/text_widget"
require_relative "link"
require_relative "line"
require_relative "video"
Loading